KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > util > NamingUtilsTest


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.util;
20
21 // JUnit classes
22
import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 /**
27  * <p>
28  * This is a test case for the <code>{@link DTDUtils}</code> class.
29  * </p>
30  *
31  * @author Robert Sese
32  * @author Brett McLaughlin
33  */

34 public class NamingUtilsTest extends TestCase {
35    
36     /**
37      * <p>
38      * This constructs a new <code>NamingUtilsTest</code>.
39      * </p>
40      *
41      * @param name the name of the test case.
42      */

43     public NamingUtilsTest(String JavaDoc name) {
44         super(name);
45     }
46
47     /**
48      * <p>
49      * This method maeks it easier to call these
50      * tests dynamically.
51      * </p>
52      *
53      * @return <code>TestSuite</code> - corresponds to this
54      * <code>TestCase</code>.
55      */

56     public static Test suite(){
57         return new TestSuite(NamingUtilsTest.class);
58     }
59     
60     /**
61      * <p>
62      * This tests the <code>{@link NamingUtils#getCharMapping}</code>
63      * method.
64      * </p>
65      */

66     public void testGetCharMapping() {
67         Character JavaDoc ch = new Character JavaDoc('.');
68         String JavaDoc replaceString = "DOT";
69         NamingUtils.setCharMapping(ch, replaceString);
70         assertEquals(replaceString, NamingUtils.getCharMapping(ch));
71     }
72     
73     /**
74      * <p>
75      * This tests the <code>{@link NamingUtils#setCharMapping}</code>
76      * method.
77      * </p>
78      */

79     public void testSetCharMapping() {
80         Character JavaDoc ch = new Character JavaDoc('.');
81         String JavaDoc 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     /**
91      * <p>
92      * This tests the <code>{@link NamingUtils#isLegalJavaClassName}</code>
93      * method.
94      * </p>
95      */

96     public void testIsLegalJavaClassName() {
97         String JavaDoc 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     /**
108      * <p>
109      * This tests the <code>{@link NamingUtils#isLegalJavaPackageName}</code>
110      * method.
111      * </p>
112      */

113     public void testIsLegalJavaPackageName() {
114         String JavaDoc 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     /**
128      * <p>
129      * This tests the <code>{@link NamingUtils#getJavaName}</code> method.
130      * </p>
131      */

132     public void testGetJavaName() {
133         String JavaDoc name = "my-element";
134         String JavaDoc expected = "myElement";
135         String JavaDoc actual = NamingUtils.getJavaName(name);
136
137         assertEquals(expected, actual);
138     }
139
140     /**
141      * <p>
142      * This tests the <code>{@link NamingUtils#getJavaVariableName}</code>
143      * method.
144      * </p>
145      */

146     public void testGetJavaVariableName() {
147         String JavaDoc name = "My-class";
148         String JavaDoc expected = "myClass";
149         String JavaDoc 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     /**
159      * <p>
160      * This tests the
161      * <code>{@link NamingUtils#getJavaCollectionVariableName}</code>
162      * method.
163      * </p>
164      */

165     public void testGetJavaCollectionVariableName() {
166         String JavaDoc name = "My-class";
167         String JavaDoc expected = "myClass";
168         String JavaDoc actual = NamingUtils.getJavaCollectionVariableName(name);
169
170         assertEquals(expected, actual);
171     }
172     
173     /**
174      * <p>
175      * This tests the <code>{@link NamingUtils#getJavaClassName}</code> method.
176      * </p>
177      */

178     public void testGetJavaClassName() {
179         String JavaDoc name = "my-element";
180         String JavaDoc expected = "MyElement";
181         String JavaDoc actual = NamingUtils.getJavaClassName(name);
182
183         assertEquals(expected, actual);
184     }
185     
186     /**
187      * <p>
188      * This tests the <code>{@link NamingUtils#getJavaType}</code>
189      * method.
190      * </p>
191      */

192     public void testGetJavaType() {
193         String JavaDoc name = "string";
194         String JavaDoc expected = "String";
195         String JavaDoc actual = NamingUtils.getJavaType(name);
196
197         assertEquals(expected, actual);
198     }
199
200     /**
201      * <p>
202      * This tests the
203      * <code>{@link NamingUtils#getXMLElementNameFromAccessor}</code>
204      * method.
205      * </p>
206      */

207     public void testGetXMLElementNameFromAccessor() {
208         String JavaDoc name = "getMyElement";
209         String JavaDoc expected = "myElement";
210         String JavaDoc actual = NamingUtils.getXMLElementNameFromAccessor(name);
211
212         assertEquals(expected, actual);
213     }
214     
215     /**
216      * <p>
217      * This tests the <code>{@link NamingUtils#removePackage}</code> method.
218      * </p>
219      */

220     public void testRemovePackage() {
221         String JavaDoc name = "java.util.List";
222         String JavaDoc 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