1 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 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 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 XMLIntrospector introspector = new XMLIntrospector(); 90 introspector.getConfiguration().setElementNameMapper(new HyphenatedNameMapper()); 91 introspector.introspect(new ArrayList ()); 92 } 93 } 94 | Popular Tags |