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