KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > classfile > ClassNameTest


1 package org.netbeans.modules.classfile;
2 /*
3  * ClassNameTest.java
4  * JUnit based test
5  *
6  * Created on September 3, 2004, 2:09 PM
7  */

8
9 import junit.framework.TestCase;
10
11 /**
12  *
13  * @author tball
14  */

15 public class ClassNameTest extends TestCase {
16     
17     public ClassNameTest(String JavaDoc testName) {
18         super(testName);
19     }
20     
21     protected void tearDown() {
22         ClassName.clearCache();
23     }
24     
25     /**
26      * Test of getClassName method, of class org.netbeans.modules.classfile.ClassName.
27      */

28     public void testGetClassName() {
29         assertNotNull(ClassName.getClassName("Ljava/lang/String;"));
30         assertNotNull(ClassName.getClassName("java/io/File"));
31         assertNull(ClassName.getClassName(null));
32         assertNull(ClassName.getClassName(""));
33     }
34
35     /**
36      * Test of getType method, of class org.netbeans.modules.classfile.ClassName.
37      */

38     public void testGetType() {
39         ClassName cn = ClassName.getClassName("Ljava/lang/String$CaseInsensitiveComparator;");
40         assertEquals(cn.getType(), "java/lang/String$CaseInsensitiveComparator");
41         cn = ClassName.getClassName("[Ljava/io/File;");
42         assertEquals(cn.getType(), "[java/io/File");
43         cn = ClassName.getClassName("[I");
44         assertEquals(cn.getType(), "[I");
45     }
46
47     /**
48      * Test of getInternalName method, of class org.netbeans.modules.classfile.ClassName.
49      */

50     public void testGetInternalName() {
51         ClassName cn = ClassName.getClassName("Ljava/lang/String$CaseInsensitiveComparator;");
52         assertEquals(cn.getInternalName(), "java/lang/String$CaseInsensitiveComparator");
53         cn = ClassName.getClassName("[Ljava/io/File;");
54         assertEquals(cn.getInternalName(), "java/io/File");
55         cn = ClassName.getClassName("[I");
56         assertEquals(cn.getInternalName(), "I");
57     }
58
59     /**
60      * Test of getExternalName method, of class org.netbeans.modules.classfile.ClassName.
61      */

62     public void testGetExternalName() {
63         ClassName cn = ClassName.getClassName("Ljava/lang/String$CaseInsensitiveComparator;");
64         assertEquals(cn.getExternalName(), "java.lang.String.CaseInsensitiveComparator");
65         cn = ClassName.getClassName("[Ljava/io/File;");
66         assertEquals(cn.getExternalName(), "java.io.File[]");
67         cn = ClassName.getClassName("[I");
68         assertEquals(cn.getExternalName(), "I[]");
69     }
70
71     /**
72      * Test of getPackage method, of class org.netbeans.modules.classfile.ClassName.
73      */

74     public void testGetPackage() {
75         ClassName cn = ClassName.getClassName("Ljava/lang/String$CaseInsensitiveComparator;");
76         assertEquals(cn.getPackage(), "java.lang");
77         cn = ClassName.getClassName("[Ljava/io/File;");
78         assertEquals(cn.getPackage(), "java.io");
79         cn = ClassName.getClassName("[I");
80         assertEquals(cn.getPackage(), "");
81     }
82
83     /**
84      * Test of getSimpleName method, of class org.netbeans.modules.classfile.ClassName.
85      */

86     public void testGetSimpleName() {
87         ClassName cn = ClassName.getClassName("Ljava/lang/String$CaseInsensitiveComparator;");
88         assertEquals(cn.getSimpleName(), "String.CaseInsensitiveComparator");
89         cn = ClassName.getClassName("[Ljava/io/File;");
90         assertEquals(cn.getSimpleName(), "File[]");
91         cn = ClassName.getClassName("[I");
92         assertEquals(cn.getSimpleName(), "I[]");
93     }
94
95     /**
96      * Test of equals method, of class org.netbeans.modules.classfile.ClassName.
97      */

98     public void testEquals() {
99         ClassName cn1 = ClassName.getClassName("Ljava/io/File;");
100         ClassName cn2 = ClassName.getClassName("Ljava/io/File;");
101         ClassName cn3 = ClassName.getClassName("Ljava/lang/String;");
102         assertTrue(cn1.equals(cn2));
103         assertFalse(cn1.equals(cn3));
104     }
105
106     /**
107      * Test of compareTo method, of class org.netbeans.modules.classfile.ClassName.
108      */

109     public void testCompareTo() {
110         ClassName cn1 = ClassName.getClassName("Ljava/io/File;");
111         ClassName cn2 = ClassName.getClassName("Ljava/io/File;");
112         ClassName cn3 = ClassName.getClassName("Ljava/lang/String;");
113         assertTrue(cn1.compareTo(cn2) == 0);
114         assertTrue(cn1.compareTo(cn3) < 0);
115         assertTrue(cn3.compareTo(cn2) > 0);
116     }
117
118     /**
119      * Test of compare method, of class org.netbeans.modules.classfile.ClassName.
120      */

121     public void testCompare() {
122         ClassName cn1 = ClassName.getClassName("Ljava/io/File;");
123         ClassName cn2 = ClassName.getClassName("Ljava/io/File;");
124         ClassName cn3 = ClassName.getClassName("Ljava/lang/String;");
125         assertTrue(cn1.compare(cn1, cn2) == 0);
126         assertTrue(cn1.compare(cn1, cn3) < 0);
127         assertTrue(cn3.compare(cn3, cn2) > 0);
128     }
129 }
130
Popular Tags