This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
The following commit(s) were added to refs/heads/master by this push: new 5326ddb More tests. 5326ddb is described below commit 5326ddbfbf1bc2276801ea8369460f8775b56070 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Jul 2 11:19:40 2020 -0400 More tests. --- .../org/apache/commons/text/StringSubstitutorTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java index dc14b11..e9ee28e 100644 --- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java +++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java @@ -48,10 +48,10 @@ import org.junit.jupiter.api.TestMethodOrder; @TestMethodOrder(MethodOrderer.Alphanumeric.class) // temp, for my sanity during dev public class StringSubstitutorTest { + private static final String ACTUAL_ANIMAL = "quick brown fox"; + private static final String ACTUAL_TARGET = "lazy dog"; private static final String CLASSIC_RESULT = "The quick brown fox jumps over the lazy dog."; private static final String CLASSIC_TEMPLATE = "The ${animal} jumps over the ${target}."; - private static final String ACTUAL_TARGET = "lazy dog"; - private static final String ACTUAL_ANIMAL = "quick brown fox"; private static final String EMPTY_EXPR = "${}"; protected Map<String, String> values; @@ -95,7 +95,8 @@ public class StringSubstitutorTest { protected void doTestReplace(final StringSubstitutor sub, final String expectedResult, final String replaceTemplate, final boolean substring) throws IOException { - final String expectedShortResult = expectedResult.substring(1, expectedResult.length() - 1); + final String expectedShortResult = substring ? expectedResult.substring(1, expectedResult.length() - 1) + : expectedResult; // replace using String assertEquals(expectedResult, replace(sub, replaceTemplate)); @@ -631,6 +632,14 @@ public class StringSubstitutorTest { doTestReplace(CLASSIC_RESULT, CLASSIC_TEMPLATE, true); } + /** + * Tests simple key replace. + */ + @Test + public void testReplaceSimpleShortest() throws IOException { + doTestReplace("1", "${a}", false); + } + @Test public void testReplaceTakingCharSequenceReturningNull() { final StringSubstitutor strSubstitutor = new StringSubstitutor((StringLookup) null);