1 19 20 package org.openide.modules; 21 22 import junit.textui.TestRunner; 23 import org.netbeans.junit.NbTestCase; 24 import org.netbeans.junit.NbTestSuite; 25 import org.openide.modules.SpecificationVersion; 26 27 30 public class SpecificationVersionTest extends NbTestCase { 31 32 public SpecificationVersionTest(String name) { 33 super(name); 34 } 35 36 public void testParseAndCompare() throws Exception { 37 SpecificationVersion v = new SpecificationVersion("1.2.3"); 38 assertEquals("1.2.3", v.toString()); 39 assertTrue(v.compareTo(new SpecificationVersion("1.2.3")) == 0); 40 assertTrue(v.compareTo(new SpecificationVersion("2.4.6")) < 0); 41 assertTrue(v.compareTo(new SpecificationVersion("1.2.4")) < 0); 42 assertTrue(v.compareTo(new SpecificationVersion("1.2.0")) > 0); 43 assertTrue(v.compareTo(new SpecificationVersion("1.2")) > 0); 44 assertTrue(v.compareTo(new SpecificationVersion("1.3")) < 0); 45 assertTrue(v.compareTo(new SpecificationVersion("1.2.3.0")) == 0); 46 assertTrue(v.compareTo(new SpecificationVersion("1.2.2.99")) > 0); 47 assertTrue(v.compareTo(new SpecificationVersion("1.3.0")) < 0); 48 assertTrue(v.compareTo(new SpecificationVersion("1")) > 0); 49 assertTrue(v.compareTo(new SpecificationVersion("2")) < 0); 50 v = new SpecificationVersion("10.99.3"); 51 assertTrue(v.compareTo(new SpecificationVersion("10.9.4")) > 0); 52 assertTrue(v.compareTo(new SpecificationVersion("10.100")) < 0); 53 } 54 55 public void testMisparse() throws Exception { 56 misparse(""); 57 misparse("1."); 58 misparse(".1"); 59 misparse("-1"); 60 misparse("0x13"); 61 misparse("2..4"); 62 misparse("2...4"); 63 misparse("13.8."); 64 misparse("1.4.0beta"); 65 misparse("hello"); 66 } 67 68 private void misparse(String s) throws Exception { 69 try { 70 new SpecificationVersion(s); 71 assertTrue("Should have misparsed: " + s, false); 72 } catch (NumberFormatException nfe) { 73 } 75 } 76 77 } 78 | Popular Tags |