You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by dj...@apache.org on 2013/10/23 01:32:27 UTC

svn commit: r1534849 - /felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java

Author: djencks
Date: Tue Oct 22 23:32:26 2013
New Revision: 1534849

URL: http://svn.apache.org/r1534849
Log:
FELIX-3779 fix InterpolationHelperTest.testBasicSubstitution elaborating a patch from Jonathan Anstey, many thanks

Modified:
    felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java

Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java?rev=1534849&r1=1534848&r2=1534849&view=diff
==============================================================================
--- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java (original)
+++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/InterpolationHelperTest.java Tue Oct 22 23:32:26 2013
@@ -31,21 +31,30 @@ public class InterpolationHelperTest ext
 
     public void testBasicSubstitution()
     {
+        System.clearProperty("value2");
         System.setProperty("value1", "sub_value1");
-        Hashtable props = new Hashtable();
-        props.put("key0", "value0");
-        props.put("key1", "${value1}");
-        props.put("key2", "${value2}");
-
-        for (Enumeration e = props.keys(); e.hasMoreElements();)
+        try
         {
-            String name = (String) e.nextElement();
-            props.put(name, InterpolationHelper.substVars((String) props.get(name), name, null, props, context));
+            Hashtable props = new Hashtable();
+            props.put("key0", "value0");
+            props.put("key1", "${value1}");
+            props.put("key2", "${value2}");
+
+            for (Enumeration e = props.keys(); e.hasMoreElements();)
+            {
+                String name = (String) e.nextElement();
+                props.put(name, InterpolationHelper.substVars((String) props.get(name), name, null, props, context));
+            }
+
+            assertEquals("value0", props.get("key0"));
+            assertEquals("sub_value1", props.get("key1"));
+            assertEquals("", props.get("key2"));
+        }
+        finally
+        {
+            System.clearProperty("value1");
+            System.clearProperty("value2");
         }
-
-        assertEquals("value0", props.get("key0"));
-        assertEquals("sub_value1", props.get("key1"));
-        assertEquals("", props.get("key2"));
 
     }
 
@@ -53,27 +62,35 @@ public class InterpolationHelperTest ext
     {
         System.setProperty("value1", "sub_value1");
         System.setProperty("value2", "sub_value2");
-        context.setProperty("value3", "context_value1");
-        context.setProperty("value2", "context_value2");
-
-        Hashtable props = new Hashtable();
-        props.put("key0", "value0");
-        props.put("key1", "${value1}");
-        props.put("key2", "${value2}");
-        props.put("key3", "${value3}");
+        try
+        {
+            context.setProperty("value3", "context_value1");
+            context.setProperty("value2", "context_value2");
 
-        for (Enumeration e = props.keys(); e.hasMoreElements();)
+            Hashtable props = new Hashtable();
+            props.put("key0", "value0");
+            props.put("key1", "${value1}");
+            props.put("key2", "${value2}");
+            props.put("key3", "${value3}");
+
+            for (Enumeration e = props.keys(); e.hasMoreElements();)
+            {
+                String name = (String) e.nextElement();
+                props.put(name,
+                        InterpolationHelper.substVars((String) props.get(name), name, null, props, context));
+            }
+
+            assertEquals("value0", props.get("key0"));
+            assertEquals("sub_value1", props.get("key1"));
+            assertEquals("context_value2", props.get("key2"));
+            assertEquals("context_value1", props.get("key3"));
+        }
+        finally
         {
-            String name = (String) e.nextElement();
-            props.put(name,
-                    InterpolationHelper.substVars((String) props.get(name), name, null, props, context));
+            System.clearProperty("value1");
+            System.clearProperty("value2");
         }
 
-        assertEquals("value0", props.get("key0"));
-        assertEquals("sub_value1", props.get("key1"));
-        assertEquals("context_value2", props.get("key2"));
-        assertEquals("context_value1", props.get("key3"));
-
     }
 
     public void testSubstitutionFailures()