1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.strategy;
18
19 import java.beans.BeanDescriptor;
20 import java.util.ArrayList;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import org.apache.commons.betwixt.XMLIntrospector;
27
28 /*** Test harness for the HyphenatedNameMapper
29 *
30 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
31 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
32 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
33 * @version $Revision: 1.9 $
34 */
35 public class TestHyphenatedNameMapper extends TestCase {
36
37 public static Test suite() {
38 return new TestSuite(TestHyphenatedNameMapper.class);
39 }
40
41 public TestHyphenatedNameMapper(String testName) {
42 super(testName);
43 }
44
45 public void testLowerCase() {
46 HyphenatedNameMapper mapper = new HyphenatedNameMapper();
47 String result = mapper.mapTypeToElementName("FooBar");
48 assertEquals("foo-bar", result);
49 }
50
51 public void testLowerCaseViaBeanDescriptor() {
52 HyphenatedNameMapper mapper = new HyphenatedNameMapper(false, "_");
53 BeanDescriptor bd = new BeanDescriptor(getClass());
54 String result = mapper.mapTypeToElementName(bd.getName());
55 assertEquals("test_hyphenated_name_mapper", result);
56 }
57
58 public void testUpperCase() {
59 HyphenatedNameMapper mapper = new HyphenatedNameMapper(true, "_");
60 String result = mapper.mapTypeToElementName("FooBar");
61 assertEquals("FOO_BAR", result);
62 }
63
64 public void testUpperCaseViaProperties() {
65 HyphenatedNameMapper mapper = new HyphenatedNameMapper();
66 mapper.setUpperCase(true);
67 mapper.setSeparator("_");
68 String result = mapper.mapTypeToElementName("FooBar");
69 assertEquals("FOO_BAR", result);
70 }
71
72 /***
73 * A more "complicated" exmple
74 */
75 public void testUpperCaseLongViaProperties() {
76 HyphenatedNameMapper mapper = new HyphenatedNameMapper(true, "__");
77 String result = mapper.mapTypeToElementName("FooBarFooBar");
78 assertEquals("FOO__BAR__FOO__BAR", result);
79
80 }
81
82 public void testBeanWithAdd() throws Exception {
83
84
85
86
87
88
89 XMLIntrospector introspector = new XMLIntrospector();
90 introspector.setElementNameMapper(new HyphenatedNameMapper());
91 introspector.introspect(new ArrayList());
92 }
93 }