1 package org.netbeans.modules.classfile; 2 8 9 import junit.framework.TestCase; 10 11 15 public class ClassNameTest extends TestCase { 16 17 public ClassNameTest(String testName) { 18 super(testName); 19 } 20 21 protected void tearDown() { 22 ClassName.clearCache(); 23 } 24 25 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 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 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 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 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 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 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 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 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 |