KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > modules > SpecificationVersionTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /** Test parsing of specification versions.
28  * @author Jesse Glick
29  */

30 public class SpecificationVersionTest extends NbTestCase {
31
32     public SpecificationVersionTest(String JavaDoc name) {
33         super(name);
34     }
35
36     public void testParseAndCompare() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc s) throws Exception JavaDoc {
69         try {
70             new SpecificationVersion(s);
71             assertTrue("Should have misparsed: " + s, false);
72         } catch (NumberFormatException JavaDoc nfe) {
73             // OK, expected.
74
}
75     }
76     
77 }
78
Popular Tags