You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2005/07/24 00:26:06 UTC
svn commit: r224561 -
/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/VariableFormatterTest.java
Author: ggregory
Date: Sat Jul 23 15:26:02 2005
New Revision: 224561
URL: http://svn.apache.org/viewcvs?rev=224561&view=rev
Log:
Three new boundary tests for VariableFormatterTest.java.
Modified:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/VariableFormatterTest.java
Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/VariableFormatterTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/VariableFormatterTest.java?rev=224561&r1=224560&r2=224561&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/VariableFormatterTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/VariableFormatterTest.java Sat Jul 23 15:26:02 2005
@@ -30,7 +30,13 @@
* @version $Id$
*/
public class VariableFormatterTest extends TestCase {
+
+ private static final String KEY_TARGET = "target";
+ private static final String KEY_ANIMAL = "animal";
static final String REPLACE_TEMPLATE = "The ${animal} jumps over the ${target}.";
+ static final String REPLACE_TEMPLATE_NO_ESCAPE = "The {animal} jumps over the {target}.";
+ static final String REPLACE_TEMPLATE_NO_PREFIX = "The $animal} jumps over the $target}.";
+ static final String REPLACE_TEMPLATE_NO_SUFFIX = "The ${animal jumps over the ${target.";
private VariableFormatter format;
@@ -59,8 +65,8 @@
protected void setUp() throws Exception {
super.setUp();
Map map = new HashMap();
- map.put("animal", "quick brown fox");
- map.put("target", "lazy dog");
+ map.put(KEY_ANIMAL, "quick brown fox");
+ map.put(KEY_TARGET, "lazy dog");
setValues(map);
setFormat(new VariableFormatter(map));
}
@@ -78,8 +84,8 @@
*/
public void testCyclicReplacement() {
Map valuesMap = new HashMap();
- valuesMap.put("animal", "${critter}");
- valuesMap.put("target", "${pet}");
+ valuesMap.put(KEY_ANIMAL, "${critter}");
+ valuesMap.put(KEY_TARGET, "${pet}");
valuesMap.put("pet", "${petCharacteristic} dog");
valuesMap.put("petCharacteristic", "lazy");
valuesMap.put("critter", "${critterSpeed} ${critterColor} ${critterType}");
@@ -160,8 +166,8 @@
public void testNonInstanceMethods() {
assertEquals("The quick brown fox jumps over the lazy dog.", VariableFormatter
.replace(values, REPLACE_TEMPLATE));
- values.put("animal", "cow");
- values.put("target", "moon");
+ values.put(KEY_ANIMAL, "cow");
+ values.put(KEY_TARGET, "moon");
assertEquals("The cow jumps over the moon.", VariableFormatter.replace(values, "&", ";",
"The &animal; jumps over the ⌖."));
}
@@ -186,8 +192,8 @@
*/
public void testRecursiveReplacement() {
Map valuesMap = new HashMap();
- valuesMap.put("animal", "${critter}");
- valuesMap.put("target", "${pet}");
+ valuesMap.put(KEY_ANIMAL, "${critter}");
+ valuesMap.put(KEY_TARGET, "${pet}");
valuesMap.put("pet", "${petCharacteristic} dog");
valuesMap.put("petCharacteristic", "lazy");
valuesMap.put("critter", "${critterSpeed} ${critterColor} ${critterType}");
@@ -204,11 +210,41 @@
public void testReplace() {
assertEquals("The quick brown fox jumps over the lazy dog.", this.getFormat().replaceObject(REPLACE_TEMPLATE));
Map map = this.getValueMap();
- map.put("animal", "cow");
- map.put("target", "moon");
+ map.put(KEY_ANIMAL, "cow");
+ map.put(KEY_TARGET, "moon");
assertEquals("The cow jumps over the moon.", this.getFormat().replace(REPLACE_TEMPLATE));
assertEquals("Variable ${var} is unknown!", this.getFormat().replace("Variable ${var} is unknown!"));
+ }
+
+ /**
+ * Tests a replace template with missing escape strings.
+ */
+ public void testReplaceNoEscape() {
+ testReplaceNoElement(REPLACE_TEMPLATE_NO_ESCAPE);
+ }
+
+ /**
+ * Tests a replace template with missing prefix strings.
+ */
+ public void testReplaceNoPrefix() {
+ testReplaceNoElement(REPLACE_TEMPLATE_NO_PREFIX);
+ }
+
+ /**
+ * Tests a replace template with missing postfix strings.
+ */
+ public void testReplaceNoSuffix() {
+ testReplaceNoElement(REPLACE_TEMPLATE_NO_SUFFIX);
+ }
+
+ void testReplaceNoElement(String badReplaceTemplate) {
+ assertEquals(badReplaceTemplate, this.getFormat().replaceObject(badReplaceTemplate));
+ Map map = this.getValueMap();
+ map.put(KEY_ANIMAL, "cow");
+ map.put(KEY_TARGET, "moon");
+ assertEquals("The cow jumps over the moon.", this.getFormat().replace(REPLACE_TEMPLATE));
+ assertEquals(badReplaceTemplate, this.getFormat().replaceObject(badReplaceTemplate));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org