1 19 package org.enhydra.zeus.util; 20 21 import junit.framework.Test; 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 34 public class NamingUtilsTest extends TestCase { 35 36 43 public NamingUtilsTest(String name) { 44 super(name); 45 } 46 47 56 public static Test suite(){ 57 return new TestSuite(NamingUtilsTest.class); 58 } 59 60 66 public void testGetCharMapping() { 67 Character ch = new Character ('.'); 68 String replaceString = "DOT"; 69 NamingUtils.setCharMapping(ch, replaceString); 70 assertEquals(replaceString, NamingUtils.getCharMapping(ch)); 71 } 72 73 79 public void testSetCharMapping() { 80 Character ch = new Character ('.'); 81 String replaceString = "DOT"; 82 NamingUtils.setCharMapping(ch, replaceString); 83 assertEquals(replaceString, NamingUtils.getCharMapping(ch)); 84 85 replaceString = "OTHER_DOT"; 86 NamingUtils.setCharMapping(ch, replaceString); 87 assertEquals(replaceString, NamingUtils.getCharMapping(ch)); 88 } 89 90 96 public void testIsLegalJavaClassName() { 97 String className = "LegalClassName"; 98 assertTrue(NamingUtils.isLegalJavaClassName(className)); 99 100 className = "#illegalClassName"; 101 assertTrue(!NamingUtils.isLegalJavaClassName(className)); 102 103 className = "9illegalClassName"; 104 assertTrue(!NamingUtils.isLegalJavaClassName(className)); 105 } 106 107 113 public void testIsLegalJavaPackageName() { 114 String packageName = "packageName"; 115 assertTrue(NamingUtils.isLegalJavaPackageName(packageName)); 116 117 packageName = "legal.package.name"; 118 assertTrue(NamingUtils.isLegalJavaPackageName(packageName)); 119 120 packageName = "9illegal.package"; 121 assertTrue(!NamingUtils.isLegalJavaPackageName(packageName)); 122 123 packageName = "#987654"; 124 assertTrue(!NamingUtils.isLegalJavaPackageName(packageName)); 125 } 126 127 132 public void testGetJavaName() { 133 String name = "my-element"; 134 String expected = "myElement"; 135 String actual = NamingUtils.getJavaName(name); 136 137 assertEquals(expected, actual); 138 } 139 140 146 public void testGetJavaVariableName() { 147 String name = "My-class"; 148 String expected = "myClass"; 149 String actual = NamingUtils.getJavaVariableName(name); 150 assertEquals(expected, actual); 151 152 name = "import"; 153 expected = "xmlimport"; 154 actual = NamingUtils.getJavaVariableName(name); 155 assertEquals(expected, actual); 156 } 157 158 165 public void testGetJavaCollectionVariableName() { 166 String name = "My-class"; 167 String expected = "myClass"; 168 String actual = NamingUtils.getJavaCollectionVariableName(name); 169 170 assertEquals(expected, actual); 171 } 172 173 178 public void testGetJavaClassName() { 179 String name = "my-element"; 180 String expected = "MyElement"; 181 String actual = NamingUtils.getJavaClassName(name); 182 183 assertEquals(expected, actual); 184 } 185 186 192 public void testGetJavaType() { 193 String name = "string"; 194 String expected = "String"; 195 String actual = NamingUtils.getJavaType(name); 196 197 assertEquals(expected, actual); 198 } 199 200 207 public void testGetXMLElementNameFromAccessor() { 208 String name = "getMyElement"; 209 String expected = "myElement"; 210 String actual = NamingUtils.getXMLElementNameFromAccessor(name); 211 212 assertEquals(expected, actual); 213 } 214 215 220 public void testRemovePackage() { 221 String name = "java.util.List"; 222 String expected = "List"; 223 assertEquals(expected, NamingUtils.removePackage(name)); 224 225 name = "SomeClass"; 226 expected = name; 227 assertEquals(expected, NamingUtils.removePackage(name)); 228 } 229 } 230 | Popular Tags |