001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.betwixt.strategy;
019:
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: /** Test harness for the BadCharacterReplacingNMapper
025: *
026: * @author Robert Burrell Donkin
027: * @version $Revision: 438373 $
028: */
029: public class TestBadCharacterReplacingNMapper extends TestCase {
030:
031: public static Test suite() {
032: return new TestSuite(TestBadCharacterReplacingNMapper.class);
033: }
034:
035: public TestBadCharacterReplacingNMapper(String testName) {
036: super (testName);
037: }
038:
039: public void testNoReplacementBadFirstNoChainedMapper() {
040: String name = "$LoadsOfMoney";
041: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
042: null);
043: String out = mapper.mapTypeToElementName(name);
044: assertEquals("Expected", "LoadsOfMoney", out);
045: }
046:
047: public void testNoReplacementBadFirstWithChainedMapper() {
048: String name = "$LOADSŁOF$MONEY";
049: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
050: new PlainMapper());
051: String out = mapper.mapTypeToElementName(name);
052: assertEquals("Expected", "LOADSOFMONEY", out);
053: }
054:
055: public void testNoReplacementGoodFirstNoChainedMapper() {
056: String name = "L$oads%OfMone$y$";
057: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
058: null);
059: String out = mapper.mapTypeToElementName(name);
060: assertEquals("Expected", "LoadsOfMoney", out);
061: }
062:
063: public void testNoReplacementGoodFirstWithChainedMapper() {
064: String name = "LOADSOFMONE$$Y";
065: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
066: new PlainMapper());
067: String out = mapper.mapTypeToElementName(name);
068: assertEquals("Expected", "LOADSOFMONEY", out);
069: }
070:
071: public void testReplacementBadFirstNoChainedMapper() {
072: String name = "$LoadsOfMoney$";
073: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
074: null);
075: mapper.setReplacement(new Character('_'));
076: String out = mapper.mapTypeToElementName(name);
077: assertEquals("Expected", "_LoadsOfMoney_", out);
078: }
079:
080: public void testReplacementBadFirstWithChainedMapper() {
081: String name = "$LOADSŁOF$MONEY";
082: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
083: new PlainMapper());
084: mapper.setReplacement(new Character('_'));
085: String out = mapper.mapTypeToElementName(name);
086: assertEquals("Expected", "_LOADS_OF_MONEY", out);
087: }
088:
089: public void testReplacementGoodFirstNoChainedMapper() {
090: String name = "L$$$$$oads%OfMone$y$";
091: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
092: null);
093: mapper.setReplacement(new Character('_'));
094: String out = mapper.mapTypeToElementName(name);
095: assertEquals("Expected", "L_____oads_OfMone_y_", out);
096: }
097:
098: public void testReplacementGoodFirstWithChainedMapper() {
099: String name = "L$OADSOFMONE$$$$$Y";
100: BadCharacterReplacingNMapper mapper = new BadCharacterReplacingNMapper(
101: new PlainMapper());
102: mapper.setReplacement(new Character('_'));
103: String out = mapper.mapTypeToElementName(name);
104: assertEquals("Expected", "L_OADSOFMONE_____Y", out);
105: }
106:
107: private class PlainMapper implements NameMapper {
108: public String mapTypeToElementName(String typeName) {
109: return typeName;
110: }
111: }
112: }
|