svn commit: r912275 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r912275 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java

doogie-3
Author: doogie
Date: Sun Feb 21 01:29:02 2010
New Revision: 912275

URL: http://svn.apache.org/viewvc?rev=912275&view=rev
Log:
Create an fseTest helper method.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java?rev=912275&r1=912274&r2=912275&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Sun Feb 21 01:29:02 2010
@@ -33,33 +33,30 @@
         super(name);
     }
 
+    private static void fseTest(String label, String input, Map<String, ? extends Object> context, Object compare) {
+        FlexibleStringExpander fse = FlexibleStringExpander.getInstance(input);
+        assertEquals(label, compare, fse.expandString(context));
+    }
+
     public void testFlexibleStringExpander() {
         FlexibleStringExpander fse = FlexibleStringExpander.getInstance(null);
         assertTrue("null FlexibleStringExpander", fse.isEmpty());
-        fse = FlexibleStringExpander.getInstance("Hello World!");
-        assertEquals("null context", "Hello World!", fse.expandString(null));
+        fseTest("null FlexibleStringExpander", null, null, "");
+        fseTest("null context", "Hello World!", null, "Hello World!");
         Map<String, Object> testMap = new HashMap<String, Object>();
         testMap.put("var", "World");
-        fse = FlexibleStringExpander.getInstance("Hello ${var}!");
-        assertEquals("simple replacement", "Hello World!", fse.expandString(testMap));
+        fseTest("simple replacement", "Hello ${var}!", testMap, "Hello World!");
         testMap.put("nested", "Hello ${var}");
-        fse = FlexibleStringExpander.getInstance("${nested}!");
-        assertEquals("hidden (runtime) nested replacement", "Hello World!", fse.expandString(testMap));
-        fse = FlexibleStringExpander.getInstance("${'Hello ${var}'}!");
-        assertEquals("visible nested replacement", "Hello World!", fse.expandString(testMap));
-        fse = FlexibleStringExpander.getInstance("${bsh:return \"Hello \" + var + \"!\";}");
-        assertEquals("bsh: script", "Hello World!", fse.expandString(testMap));
-        fse = FlexibleStringExpander.getInstance("${groovy:return \"Hello \" + var + \"!\";}");
-        assertEquals("groovy: script", "Hello World!", fse.expandString(testMap));
+        fseTest("hidden (runtime) nested replacement", "${nested}!", testMap, "Hello World!");
+        fseTest("visible nested replacement", "${'Hello ${var}'}!", testMap, "Hello World!");
+        fseTest("bsh: script", "${bsh:return \"Hello \" + var + \"!\";}", testMap, "Hello World!");
+        fseTest("groovy: script", "${groovy:return \"Hello \" + var + \"!\";}", testMap, "Hello World!");
         testMap.put("testMap", testMap);
-        fse = FlexibleStringExpander.getInstance("Hello ${testMap.var}!");
-        assertEquals("UEL integration: Map", "Hello World!", fse.expandString(testMap));
+        fseTest("UEL integration: Map", "Hello ${testMap.var}!", testMap, "Hello World!");
         List<String> testList = new ArrayList<String>();
         testList.add("World");
         testMap.put("testList", testList);
-        fse = FlexibleStringExpander.getInstance("Hello ${testList[0]}!");
-        assertEquals("UEL integration: List", "Hello World!", fse.expandString(testMap));
-        fse = FlexibleStringExpander.getInstance("This is an \\${escaped} expression");
-        assertEquals("Escaped expression", "This is an ${escaped} expression", fse.expandString(testMap));
+        fseTest("UEL integration: List", "Hello ${testList[0]}!", testMap, "Hello World!");
+        fseTest("Escaped expression", "This is an \\${escaped} expression", testMap, "This is an ${escaped} expression");
     }
 }