KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > XMLNameToJavaIdentifierUnitTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.xml;
8
9 import junit.framework.TestCase;
10 import org.jboss.xb.binding.Util;
11
12 /**
13  * Tests XML names to various Java identifiers conversion.
14  *
15  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
16  * @version <tt>$Revision: 1.1.2.2 $</tt>
17  */

18 public class XMLNameToJavaIdentifierUnitTestCase
19    extends TestCase
20 {
21    private static final String JavaDoc[] xmlNames = new String JavaDoc[]
22    {
23       "mixedCaseName", "Answer42", "name-with-dashes", "other_punct-chars", "one2three", "__-invalids-at-the-end---"
24    };
25
26    private static final String JavaDoc[] clsNames = new String JavaDoc[]
27    {
28       "MixedCaseName", "Answer42", "NameWithDashes", "OtherPunctChars", "One2Three", "InvalidsAtTheEnd"
29    };
30
31    private static final String JavaDoc[] clsNamesWithLowLines = new String JavaDoc[]
32    {
33       "MixedCaseName", "Answer42", "NameWithDashes", "Other_PunctChars", "One2Three", "__InvalidsAtTheEnd"
34    };
35
36    private static final String JavaDoc[] getNames = new String JavaDoc[]
37    {
38       "getMixedCaseName", "getAnswer42", "getNameWithDashes", "getOtherPunctChars", "getOne2Three", "getInvalidsAtTheEnd"
39    };
40
41    private static final String JavaDoc[] setNames = new String JavaDoc[]
42    {
43       "setMixedCaseName", "setAnswer42", "setNameWithDashes", "setOtherPunctChars", "setOne2Three", "setInvalidsAtTheEnd"
44    };
45
46    private static final String JavaDoc[] constNames = new String JavaDoc[]
47    {
48       "MIXED_CASE_NAME", "ANSWER_42", "NAME_WITH_DASHES", "OTHER_PUNCT_CHARS", "ONE_2_THREE", "INVALIDS_AT_THE_END"
49    };
50
51    public XMLNameToJavaIdentifierUnitTestCase(String JavaDoc localName)
52    {
53       super(localName);
54    }
55
56    public void testXmlNameToClassName() throws Exception JavaDoc
57    {
58       for(int i = 0; i < xmlNames.length; ++i)
59       {
60          String JavaDoc clsName = Util.xmlNameToClassName(xmlNames[i], true);
61          assertEquals(clsNames[i], clsName);
62       }
63    }
64
65    public void testXmlNameToClassNameWithLowLines() throws Exception JavaDoc
66    {
67       for(int i = 0; i < xmlNames.length; ++i)
68       {
69          String JavaDoc clsName = Util.xmlNameToClassName(xmlNames[i], false);
70          assertEquals(clsNamesWithLowLines[i], clsName);
71       }
72    }
73
74    public void testXmlNameToGetMethodName() throws Exception JavaDoc
75    {
76       for(int i = 0; i < xmlNames.length; ++i)
77       {
78          String JavaDoc clsName = Util.xmlNameToGetMethodName(xmlNames[i], true);
79          assertEquals(getNames[i], clsName);
80       }
81    }
82
83    public void testXmlNameToSetMethodName() throws Exception JavaDoc
84    {
85       for(int i = 0; i < xmlNames.length; ++i)
86       {
87          String JavaDoc clsName = Util.xmlNameToSetMethodName(xmlNames[i], true);
88          assertEquals(setNames[i], clsName);
89       }
90    }
91
92    public void testXmlNameToConstantName() throws Exception JavaDoc
93    {
94       for(int i = 0; i < xmlNames.length; ++i)
95       {
96          String JavaDoc clsName = Util.xmlNameToConstantName(xmlNames[i]);
97          assertEquals(constNames[i], clsName);
98       }
99    }
100 }
101
Popular Tags