You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/08/28 21:58:05 UTC
[text] [TEXT-134] Add a Properties file string lookup. More tests.
Repository: commons-text
Updated Branches:
refs/heads/master 9dd0e051e -> cab116505
[TEXT-134] Add a Properties file string lookup. More tests.
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/cab11650
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/cab11650
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/cab11650
Branch: refs/heads/master
Commit: cab1165056ea673f9a959df183d844883f3c90c9
Parents: 9dd0e05
Author: Gary Gregory <ga...@gmail.com>
Authored: Tue Aug 28 15:58:01 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Tue Aug 28 15:58:01 2018 -0600
----------------------------------------------------------------------
.../text/lookup/PropertiesStringLookupTest.java | 30 ++++++++++++++++++--
1 file changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/cab11650/src/test/java/org/apache/commons/text/lookup/PropertiesStringLookupTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/lookup/PropertiesStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/PropertiesStringLookupTest.java
index c018e50..09c5a28 100644
--- a/src/test/java/org/apache/commons/text/lookup/PropertiesStringLookupTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/PropertiesStringLookupTest.java
@@ -17,16 +17,40 @@
package org.apache.commons.text.lookup;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.text.StringSubstitutor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class PropertiesStringLookupTest {
+ private static final String DOC_PATH = "src/test/resources/document.properties";
+ private static final String KEY = "mykey";
+ private static final String KEY_PATH = DOC_PATH + ":" + KEY;
+
@Test
public void testOne() {
- final String docName = "src/test/resources/document.properties";
- final String xpath = "mykey";
- Assertions.assertEquals("Hello World!", PropertiesStringLookup.INSTANCE.lookup(docName + ":" + xpath));
+ Assertions.assertEquals("Hello World!", PropertiesStringLookup.INSTANCE.lookup(KEY_PATH));
+ }
+
+ @Test
+ public void testInterpolator() {
+ final StringSubstitutor stringSubstitutor = new StringSubstitutor(
+ StringLookupFactory.INSTANCE.interpolatorStringLookup());
+ Assertions.assertEquals("Hello World!", stringSubstitutor.replace("${properties:" + KEY_PATH + "}"));
+ }
+
+ @Test
+ public void testInterpolatorWithParameterizedKey() {
+ final Map<String, String> map = new HashMap<>();
+ map.put("KeyIsHere", KEY);
+ final StringSubstitutor stringSubstitutor = new StringSubstitutor(
+ StringLookupFactory.INSTANCE.interpolatorStringLookup(map));
+ final String replaced = stringSubstitutor.replace("$${properties:" + DOC_PATH + ":${KeyIsHere}}");
+ Assertions.assertEquals("${properties:" + DOC_PATH + ":mykey}", replaced);
+ Assertions.assertEquals("Hello World!", stringSubstitutor.replace(replaced));
}
}