KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > strategy > TestBadCharacterReplacingNMapper


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /** Test harness for the BadCharacterReplacingNMapper
24   *
25   * @author Robert Burrell Donkin
26   * @version $Revision: 1.5 $
27   */

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 JavaDoc testName) {
36         super(testName);
37     }
38     
39     public void testNoReplacementBadFirstNoChainedMapper() {
40         String JavaDoc name="$LoadsOfMoney";
41         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null);
42         String JavaDoc out = mapper.mapTypeToElementName(name);
43         assertEquals("Expected", "LoadsOfMoney", out);
44     }
45     
46     public void testNoReplacementBadFirstWithChainedMapper() {
47         String JavaDoc name="$LOADSŁOF$MONEY";
48         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper());
49         String JavaDoc out = mapper.mapTypeToElementName(name);
50         assertEquals("Expected", "LOADSOFMONEY", out);
51     }
52     
53     public void testNoReplacementGoodFirstNoChainedMapper() {
54         String JavaDoc name="L$oads%OfMone$y$";
55         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null);
56         String JavaDoc out = mapper.mapTypeToElementName(name);
57         assertEquals("Expected", "LoadsOfMoney", out);
58     }
59     
60     public void testNoReplacementGoodFirstWithChainedMapper() {
61         String JavaDoc name="LOADSOFMONE$$Y";
62         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper());
63         String JavaDoc out = mapper.mapTypeToElementName(name);
64         assertEquals("Expected", "LOADSOFMONEY", out);
65     }
66     
67     public void testReplacementBadFirstNoChainedMapper() {
68         String JavaDoc name="$LoadsOfMoney$";
69         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null);
70         mapper.setReplacement(new Character JavaDoc('_'));
71         String JavaDoc out = mapper.mapTypeToElementName(name);
72         assertEquals("Expected", "_LoadsOfMoney_", out);
73     }
74     
75     public void testReplacementBadFirstWithChainedMapper() {
76         String JavaDoc name="$LOADSŁOF$MONEY";
77         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper());
78         mapper.setReplacement(new Character JavaDoc('_'));
79         String JavaDoc out = mapper.mapTypeToElementName(name);
80         assertEquals("Expected", "_LOADS_OF_MONEY", out);
81     }
82     
83     public void testReplacementGoodFirstNoChainedMapper() {
84         String JavaDoc name="L$$$$$oads%OfMone$y$";
85         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(null);
86         mapper.setReplacement(new Character JavaDoc('_'));
87         String JavaDoc out = mapper.mapTypeToElementName(name);
88         assertEquals("Expected", "L_____oads_OfMone_y_", out);
89     }
90     
91     public void testReplacementGoodFirstWithChainedMapper() {
92         String JavaDoc name="L$OADSOFMONE$$$$$Y";
93         BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(new PlainMapper());
94         mapper.setReplacement(new Character JavaDoc('_'));
95         String JavaDoc out = mapper.mapTypeToElementName(name);
96         assertEquals("Expected", "L_OADSOFMONE_____Y", out);
97     }
98     
99     private class PlainMapper implements NameMapper {
100         public String JavaDoc mapTypeToElementName(String JavaDoc typeName) {
101             return typeName;
102         }
103     }
104 }
105
Popular Tags