1 |
| package org.jboss.cache; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| |
5 |
| public class VersionConversionTest extends TestCase |
6 |
| { |
7 |
| |
8 |
3
| public VersionConversionTest(String name)
|
9 |
| { |
10 |
3
| super(name);
|
11 |
| } |
12 |
| |
13 |
1
| public void testStringToShort()
|
14 |
| { |
15 |
1
| try
|
16 |
| { |
17 |
1
| Version.getVersionShort("1.2.4SP1");
|
18 |
0
| fail("Correctly did not accept versionString '1.2.4SP1'");
|
19 |
| } |
20 |
| catch (IllegalArgumentException ok) {} |
21 |
| |
22 |
1
| try
|
23 |
| { |
24 |
1
| Version.getVersionShort("1.2.4 SP1");
|
25 |
0
| fail("Correctly did not accept versionString '1.2.4 SP1'");
|
26 |
| } |
27 |
| catch (IllegalArgumentException ok) {} |
28 |
| |
29 |
1
| try
|
30 |
| { |
31 |
1
| Version.getVersionShort("1.3.alpha");
|
32 |
0
| fail("Correctly did not accept versionString '1.3.alpha'");
|
33 |
| } |
34 |
| catch (IllegalArgumentException ok) {} |
35 |
| |
36 |
1
| assertEquals("MAX_SHORT correct", Short.MAX_VALUE, Version.getVersionShort("15.31.63"));
|
37 |
1
| assertEquals("0.0.1 correct", 1, Version.getVersionShort("0.0.1"));
|
38 |
1
| assertEquals("0.1.0 correct", (short) Math.pow(2, 6), Version.getVersionShort("0.1.0"));
|
39 |
1
| assertEquals("1.0 correct", (short) Math.pow(2, 11), Version.getVersionShort("1.0"));
|
40 |
1
| assertEquals("1.0.1 correct", (short) Math.pow(2, 11) + 1, Version.getVersionShort("1.0.1"));
|
41 |
1
| assertEquals("1.1 correct", (short) (Math.pow(2,11) + Math.pow(2,6)), Version.getVersionShort("1.1"));
|
42 |
1
| assertEquals("1.1.1 correct", (short) (Math.pow(2,11) + Math.pow(2,6)) + 1, Version.getVersionShort("1.1.1"));
|
43 |
1
| assertEquals("2.0 correct", (short) Math.pow(2,12), Version.getVersionShort("2.0"));
|
44 |
| |
45 |
| |
46 |
1
| assertEquals("1.3.0.alpha correct", (short) (Math.pow(2,11) + Math.pow(2,7) + Math.pow(2,6)), Version.getVersionShort("1.3.0.alpha"));
|
47 |
1
| assertEquals("1.3.0.RC1 correct", (short) (Math.pow(2,11) + Math.pow(2,7) + Math.pow(2,6)), Version.getVersionShort("1.3.0.RC1"));
|
48 |
1
| assertEquals("1.3.0.SP1 correct", (short) (Math.pow(2,11) + Math.pow(2,7) + Math.pow(2,6)), Version.getVersionShort("1.3.0.SP1"));
|
49 |
| |
50 |
| |
51 |
1
| assertEquals("1.2.4.SP2 correct", (short) 124, Version.getVersionShort("1.2.4"));
|
52 |
1
| assertEquals("1.2.4.SP2 correct", (short) 1241, Version.getVersionShort("1.2.4.SP1"));
|
53 |
1
| assertEquals("1.2.4.SP2 correct", (short) (Math.pow(2,11) + Math.pow(2,7)) + 4, Version.getVersionShort("1.2.4.SP2"));
|
54 |
| } |
55 |
| |
56 |
1
| public void testShortToString()
|
57 |
| { |
58 |
1
| assertEquals("0.0.1 correct", "0.0.1", Version.getVersionString(Version.getVersionShort("0.0.1")));
|
59 |
1
| assertEquals("1.3.0 correct", "1.3.0", Version.getVersionString(Version.getVersionShort("1.3.0")));
|
60 |
| |
61 |
| |
62 |
1
| assertEquals("1.2.4 correct", "1.2.4", Version.getVersionString((short) 124));
|
63 |
1
| assertEquals("1.2.4.SP1 correct", "1.2.4.SP1", Version.getVersionString((short) 1241));
|
64 |
1
| assertEquals("1.2.4.SP2 correct", "1.2.4.SP2", Version.getVersionString(Version.getVersionShort("1.2.4.SP2")));
|
65 |
| } |
66 |
| |
67 |
1
| public void testDefault()
|
68 |
| { |
69 |
1
| short defaultShort = Version.getVersionShort();
|
70 |
1
| String versionString = Version.getVersionString(defaultShort);
|
71 |
| |
72 |
1
| String versionToCompareAgainst = Version.version;
|
73 |
1
| String lastElement = versionToCompareAgainst.substring(versionToCompareAgainst.lastIndexOf('.')+1).toUpperCase();
|
74 |
| |
75 |
1
| if (lastElement.startsWith("GA")
|
76 |
| || lastElement.startsWith("CR") |
77 |
| || lastElement.startsWith("RC") |
78 |
| || lastElement.startsWith("DR") |
79 |
| || lastElement.startsWith("ALPHA") |
80 |
| || lastElement.startsWith("BETA") |
81 |
| || lastElement.startsWith("SP")) |
82 |
| { |
83 |
| |
84 |
1
| versionToCompareAgainst = versionToCompareAgainst.substring(0, versionToCompareAgainst.lastIndexOf('.'));
|
85 |
| } |
86 |
| |
87 |
1
| assertEquals("Round-trip conversion consistent", versionToCompareAgainst, versionString);
|
88 |
| } |
89 |
| } |