1 package org.jboss.cache; 2 3 import junit.framework.TestCase; 4 5 public class VersionConversionTest extends TestCase 6 { 7 8 public VersionConversionTest(String name) 9 { 10 super(name); 11 } 12 13 public void testStringToShort() 14 { 15 try 16 { 17 Version.getVersionShort("1.2.4SP1"); 18 fail("Correctly did not accept versionString '1.2.4SP1'"); 19 } 20 catch (IllegalArgumentException ok) {} 21 22 try 23 { 24 Version.getVersionShort("1.2.4 SP1"); 25 fail("Correctly did not accept versionString '1.2.4 SP1'"); 26 } 27 catch (IllegalArgumentException ok) {} 28 29 try 30 { 31 Version.getVersionShort("1.3.alpha"); 32 fail("Correctly did not accept versionString '1.3.alpha'"); 33 } 34 catch (IllegalArgumentException ok) {} 35 36 assertEquals("MAX_SHORT correct", Short.MAX_VALUE, Version.getVersionShort("15.31.63")); 37 assertEquals("0.0.1 correct", 1, Version.getVersionShort("0.0.1")); 38 assertEquals("0.1.0 correct", (short) Math.pow(2, 6), Version.getVersionShort("0.1.0")); 39 assertEquals("1.0 correct", (short) Math.pow(2, 11), Version.getVersionShort("1.0")); 40 assertEquals("1.0.1 correct", (short) Math.pow(2, 11) + 1, Version.getVersionShort("1.0.1")); 41 assertEquals("1.1 correct", (short) (Math.pow(2,11) + Math.pow(2,6)), Version.getVersionShort("1.1")); 42 assertEquals("1.1.1 correct", (short) (Math.pow(2,11) + Math.pow(2,6)) + 1, Version.getVersionShort("1.1.1")); 43 assertEquals("2.0 correct", (short) Math.pow(2,12), Version.getVersionShort("2.0")); 44 45 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 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 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 assertEquals("1.2.4.SP2 correct", (short) 124, Version.getVersionShort("1.2.4")); 52 assertEquals("1.2.4.SP2 correct", (short) 1241, Version.getVersionShort("1.2.4.SP1")); 53 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 public void testShortToString() 57 { 58 assertEquals("0.0.1 correct", "0.0.1", Version.getVersionString(Version.getVersionShort("0.0.1"))); 59 assertEquals("1.3.0 correct", "1.3.0", Version.getVersionString(Version.getVersionShort("1.3.0"))); 60 61 assertEquals("1.2.4 correct", "1.2.4", Version.getVersionString((short) 124)); 63 assertEquals("1.2.4.SP1 correct", "1.2.4.SP1", Version.getVersionString((short) 1241)); 64 assertEquals("1.2.4.SP2 correct", "1.2.4.SP2", Version.getVersionString(Version.getVersionShort("1.2.4.SP2"))); 65 } 66 67 public void testDefault() 68 { 69 short defaultShort = Version.getVersionShort(); 70 String versionString = Version.getVersionString(defaultShort); 71 String versionToCompareAgainst = Version.version; 73 String lastElement = versionToCompareAgainst.substring(versionToCompareAgainst.lastIndexOf('.')+1).toUpperCase(); 74 75 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 versionToCompareAgainst = versionToCompareAgainst.substring(0, versionToCompareAgainst.lastIndexOf('.')); 85 } 86 87 assertEquals("Round-trip conversion consistent", versionToCompareAgainst, versionString); 88 } 89 } 90 | Popular Tags |