1 16 17 package org.apache.commons.betwixt.strategy; 18 19 import junit.framework.Test; 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 23 28 public class TestBadCharacterReplacingNMapper extends TestCase { 29 30 31 public static Test suite() { 32 return new TestSuite(TestBadCharacterReplacingNMapper.class); 33 } 34 35 public TestBadCharacterReplacingNMapper(String testName) { 36 super(testName); 37 } 38 39 public void testNoReplacementBadFirstNoChainedMapper() { 40 String name="$LoadsOfMoney"; 41 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null); 42 String out = mapper.mapTypeToElementName(name); 43 assertEquals("Expected", "LoadsOfMoney", out); 44 } 45 46 public void testNoReplacementBadFirstWithChainedMapper() { 47 String name="$LOADSŁOF$MONEY"; 48 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper()); 49 String out = mapper.mapTypeToElementName(name); 50 assertEquals("Expected", "LOADSOFMONEY", out); 51 } 52 53 public void testNoReplacementGoodFirstNoChainedMapper() { 54 String name="L$oads%OfMone$y$"; 55 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null); 56 String out = mapper.mapTypeToElementName(name); 57 assertEquals("Expected", "LoadsOfMoney", out); 58 } 59 60 public void testNoReplacementGoodFirstWithChainedMapper() { 61 String name="LOADSOFMONE$$Y"; 62 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper()); 63 String out = mapper.mapTypeToElementName(name); 64 assertEquals("Expected", "LOADSOFMONEY", out); 65 } 66 67 public void testReplacementBadFirstNoChainedMapper() { 68 String name="$LoadsOfMoney$"; 69 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null); 70 mapper.setReplacement(new Character ('_')); 71 String out = mapper.mapTypeToElementName(name); 72 assertEquals("Expected", "_LoadsOfMoney_", out); 73 } 74 75 public void testReplacementBadFirstWithChainedMapper() { 76 String name="$LOADSŁOF$MONEY"; 77 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper()); 78 mapper.setReplacement(new Character ('_')); 79 String out = mapper.mapTypeToElementName(name); 80 assertEquals("Expected", "_LOADS_OF_MONEY", out); 81 } 82 83 public void testReplacementGoodFirstNoChainedMapper() { 84 String name="L$$$$$oads%OfMone$y$"; 85 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null); 86 mapper.setReplacement(new Character ('_')); 87 String out = mapper.mapTypeToElementName(name); 88 assertEquals("Expected", "L_____oads_OfMone_y_", out); 89 } 90 91 public void testReplacementGoodFirstWithChainedMapper() { 92 String name="L$OADSOFMONE$$$$$Y"; 93 BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper()); 94 mapper.setReplacement(new Character ('_')); 95 String out = mapper.mapTypeToElementName(name); 96 assertEquals("Expected", "L_OADSOFMONE_____Y", out); 97 } 98 99 private class PlainMapper implements NameMapper { 100 public String mapTypeToElementName(String typeName) { 101 return typeName; 102 } 103 } 104 } 105 | Popular Tags |