Removes Interpolation and MappedMessageFormat from the text package in favor of VariableFormatter. (See message below) No one has complained on commons-dev.
-----Original Message----- From: Gary Gregory [mailto:ggregory@seagullsoftware.com] Sent: Thursday, July 21, 2005 9:34 AM To: Jakarta Commons Developers List Subject: [lang] text.VariableFormatter to replace Interpolation and MappedMessageFormat (WAS a [POLL]) Hello: It's been two weeks since I posted the original message below and I've not heard negative comments on removing Interpolation and MappedMessageFormat from the text package in favor of VariableFormatter. I will therefore do so real soon. Please raise your hand you disagree. Thanks, Gary git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@224558 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7952a55254
commit
cdb9168538
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.lang.text;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang.text.Interpolation}.
|
||||
*
|
||||
* @author Henri Yandell
|
||||
* @author Ken Fitzpatrick
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InterpolationTest extends TestCase {
|
||||
|
||||
private static final String INPUT_TEMPLATE = "The ${animal} jumped over the ${target}.";
|
||||
private static final String EXPECTED_RESULTS_1 = "The quick brown fox jumped over the lazy dog.";
|
||||
private static final String EXPECTED_RESULTS_2 = "The cow jumped over the moon.";
|
||||
|
||||
public InterpolationTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(InterpolationTest.class);
|
||||
suite.setName("Interpolation Tests");
|
||||
return suite;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testSimpleVariableSubstitution() {
|
||||
|
||||
// test case: "The quick brown fox jumped over the lazy dog."
|
||||
Map valuesMap = new HashMap();
|
||||
valuesMap.put( "animal", "quick brown fox" );
|
||||
valuesMap.put( "target", "lazy dog" );
|
||||
assertEquals( "Test case 1: simple variable substitution", EXPECTED_RESULTS_1,
|
||||
Interpolation.interpolate( INPUT_TEMPLATE, valuesMap) );
|
||||
|
||||
// test case: "The cow jumped over the moon."
|
||||
valuesMap = new HashMap();
|
||||
valuesMap.put( "animal", "cow" );
|
||||
valuesMap.put( "target", "moon" );
|
||||
assertEquals( "Test case 2: template reuse, different results" ,EXPECTED_RESULTS_2,
|
||||
Interpolation.interpolate( INPUT_TEMPLATE, valuesMap) );
|
||||
}
|
||||
|
||||
public void testNullMap() {
|
||||
// negative test case: Map == null
|
||||
Map valuesMap = null;
|
||||
assertEquals( "Test case 3: Map == null", INPUT_TEMPLATE,
|
||||
Interpolation.interpolate( INPUT_TEMPLATE, valuesMap) );
|
||||
}
|
||||
|
||||
public void testEmptyMap() {
|
||||
// negative test case: Map.isEmpty()
|
||||
Map valuesMap = new HashMap();
|
||||
assertEquals( "Test case 4: Map.isEmpty()", INPUT_TEMPLATE,
|
||||
Interpolation.interpolate( INPUT_TEMPLATE, valuesMap) );
|
||||
}
|
||||
|
||||
public void testNullTemplate() {
|
||||
// negative test case: INPUT_TEMPLATE == null
|
||||
Map valuesMap = new HashMap();
|
||||
valuesMap.put( "animal", "cow" );
|
||||
valuesMap.put( "target", "moon" );
|
||||
assertNull( "Test case 5: template == null",
|
||||
Interpolation.interpolate( null, valuesMap) );
|
||||
}
|
||||
|
||||
public void testRecursive() {
|
||||
// test case: process repeatedly
|
||||
Map valuesMap = new HashMap();
|
||||
valuesMap.put( "animal", "${critter}" );
|
||||
valuesMap.put( "target", "${pet}" );
|
||||
valuesMap.put( "pet", "${petCharacteristic} dog" );
|
||||
valuesMap.put( "petCharacteristic", "lazy" );
|
||||
valuesMap.put( "critter", "${critterSpeed} ${critterColor} ${critterType}" );
|
||||
valuesMap.put( "critterSpeed", "quick" );
|
||||
valuesMap.put( "critterColor", "brown" );
|
||||
valuesMap.put( "critterType", "fox" );
|
||||
assertEquals( "Test case 6: interpolateRepeatedly", EXPECTED_RESULTS_1,
|
||||
Interpolation.interpolateRepeatedly( INPUT_TEMPLATE, valuesMap ) );
|
||||
|
||||
// test case: process repeatedly
|
||||
valuesMap = new HashMap();
|
||||
valuesMap.put( "animal", "cow" );
|
||||
valuesMap.put( "target", "${celestialObject}" );
|
||||
valuesMap.put( "celestialObject", "moon" );
|
||||
assertEquals( "Test case 8: interpolateRepeatedly", EXPECTED_RESULTS_2,
|
||||
Interpolation.interpolateRepeatedly( INPUT_TEMPLATE, valuesMap ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -48,7 +48,6 @@ public class TextTestSuite extends TestCase {
|
|||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.setName("Commons-Lang-Text Tests");
|
||||
suite.addTest(InterpolationTest.suite());
|
||||
suite.addTest(StrBuilderTest.suite());
|
||||
suite.addTest(StrTokenizerTest.suite());
|
||||
suite.addTestSuite(VariableFormatterTest.class);
|
||||
|
|
Loading…
Reference in New Issue