1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package com.smartdevicelink.test.util;
import android.support.test.runner.AndroidJUnit4;
import com.smartdevicelink.util.Version;
import org.junit.Test;
import org.junit.runner.RunWith;
import static junit.framework.TestCase.assertEquals;
@RunWith(AndroidJUnit4.class)
public class VersionTest {
private static final String TEST_VERSION_STRING = "1.2.3";
private static final Version TEST_VERSION = new Version(1,2,3);
@Test
public void testConstructorCorrect(){
Version version = new Version(TEST_VERSION_STRING);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
}
@Test
public void testConstructorIncorrect(){
try{
Version version = new Version("1.2");
}catch (Exception e){
assert true;
}
assert false;
}
@Test
public void testToString(){
Version version = new Version(TEST_VERSION_STRING);
assertEquals(version.toString(), TEST_VERSION_STRING);
}
@Test
public void testisNewerThan(){
Version version1 = new Version(5,0,0);
//Supplied version is newer
assertEquals(-1,version1.isNewerThan(new Version(6,0,0)));
assertEquals(-1,version1.isNewerThan( new Version(5,1,0)));
assertEquals(-1,version1.isNewerThan( new Version(5,0,1)));
//Supplied version is older
assertEquals(1,version1.isNewerThan( new Version(4,0,0)));
assertEquals(1,version1.isNewerThan( new Version(4,1,0)));
assertEquals(1,version1.isNewerThan( new Version(4,0,1)));
//Supplied version is equal
assertEquals(0,version1.isNewerThan( new Version(5,0,0)));
}
@Test
public void testIsBetween(){
assertEquals(TEST_VERSION.isBetween(new Version(1,0,0), new Version (2,0,0)), 1);
assertEquals(TEST_VERSION.isBetween(new Version(2,0,0), new Version (1,0,0)), -1);
assertEquals(TEST_VERSION.isBetween(new Version(2,0,0), new Version (3,0,0)), -1);
assertEquals(TEST_VERSION.isBetween(new Version(1,0,0), new Version (1,2,3)), 0);
assertEquals(TEST_VERSION.isBetween(new Version(1,2,3), new Version (3,2,3)), 0);
assertEquals(TEST_VERSION.isBetween(new Version(1,2,3), new Version (1,2,3)), 0);
}
}
|