You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/07/13 21:34:15 UTC

svn commit: r1502856 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/SubsetConfiguration.java test/java/org/apache/commons/configuration/TestSubsetConfiguration.java

Author: oheger
Date: Sat Jul 13 19:34:15 2013
New Revision: 1502856

URL: http://svn.apache.org/r1502856
Log:
SubsetConfiguration now shares its list delimiter handler with its parent.

The overridden properties for the list delimiter and the delimiter parsing
disabled flag have been removed.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubsetConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubsetConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubsetConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubsetConfiguration.java?rev=1502856&r1=1502855&r2=1502856&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubsetConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/SubsetConfiguration.java Sat Jul 13 19:34:15 2013
@@ -239,76 +239,34 @@ public class SubsetConfiguration extends
     }
 
     /**
-     * Returns the list delimiter. This property will be fetched from the parent
-     * configuration if supported.
-     *
-     * @return the list delimiter
-     * @since 1.4
+     * {@inheritDoc} If the parent configuration extends
+     * {@link AbstractConfiguration}, the list delimiter handler is obtained
+     * from there.
      */
     @Override
-    public char getListDelimiter()
+    public ListDelimiterHandler getListDelimiterHandler()
     {
         return (parent instanceof AbstractConfiguration) ? ((AbstractConfiguration) parent)
-                .getListDelimiter()
-                : super.getListDelimiter();
+                .getListDelimiterHandler() : super.getListDelimiterHandler();
     }
 
     /**
-     * Sets the list delimiter. If the parent configuration supports this
-     * feature, the delimiter will be set at the parent.
-     *
-     * @param delim the new list delimiter
-     * @since 1.4
+     * {@inheritDoc} If the parent configuration extends
+     * {@link AbstractConfiguration}, the list delimiter handler is passed to
+     * the parent.
      */
     @Override
-    public void setListDelimiter(char delim)
-    {
-        if (parent instanceof AbstractConfiguration)
-        {
-            ((AbstractConfiguration) parent).setListDelimiter(delim);
-        }
-        else
-        {
-            super.setListDelimiter(delim);
-        }
-    }
-
-    /**
-     * Returns a flag whether string properties should be checked for list
-     * delimiter characters. This implementation ensures that this flag is kept
-     * in sync with the parent configuration if this object supports this
-     * feature.
-     *
-     * @return the delimiter parsing disabled flag
-     * @since 1.4
-     */
-    @Override
-    public boolean isDelimiterParsingDisabled()
-    {
-        return (parent instanceof AbstractConfiguration) ? ((AbstractConfiguration) parent)
-                .isDelimiterParsingDisabled()
-                : super.isDelimiterParsingDisabled();
-    }
-
-    /**
-     * Sets a flag whether list parsing is disabled. This implementation will
-     * also set the flag at the parent configuration if this object supports
-     * this feature.
-     *
-     * @param delimiterParsingDisabled the delimiter parsing disabled flag
-     * @since 1.4
-     */
-    @Override
-    public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
+    public void setListDelimiterHandler(
+            ListDelimiterHandler listDelimiterHandler)
     {
         if (parent instanceof AbstractConfiguration)
         {
             ((AbstractConfiguration) parent)
-                    .setDelimiterParsingDisabled(delimiterParsingDisabled);
+                    .setListDelimiterHandler(listDelimiterHandler);
         }
         else
         {
-            super.setDelimiterParsingDisabled(delimiterParsingDisabled);
+            super.setListDelimiterHandler(listDelimiterHandler);
         }
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubsetConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubsetConfiguration.java?rev=1502856&r1=1502855&r2=1502856&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubsetConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestSubsetConfiguration.java Sat Jul 13 19:34:15 2013
@@ -20,6 +20,7 @@ package org.apache.commons.configuration
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -34,6 +35,7 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.builder.combined.CombinedConfigurationBuilder;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration.interpol.Lookup;
+import org.easymock.EasyMock;
 import org.junit.Test;
 
 /**
@@ -260,8 +262,11 @@ public class TestSubsetConfiguration
         assertFalse("the parent configuration is empty", config.isEmpty());
     }
 
+    /**
+     * Tests whether a list delimiter handler is used correctly.
+     */
     @Test
-    public void testSetListDelimiterHandler()
+    public void testListDelimiterHandling()
     {
         BaseConfiguration config = new BaseConfiguration();
         Configuration subset = config.subset("prefix");
@@ -277,48 +282,52 @@ public class TestSubsetConfiguration
                 .size());
     }
 
+    /**
+     * Tests whether the list delimiter handler is also set for the parent
+     * configuration.
+     */
     @Test
-    public void testGetListDelimiter()
+    public void testSetListDelimiterHandlerInParent()
     {
         BaseConfiguration config = new BaseConfiguration();
-        AbstractConfiguration subset = (AbstractConfiguration) config
-                .subset("prefix");
-        config.setListDelimiter('/');
-        assertEquals("Wrong list delimiter in subset", '/', subset
-                .getListDelimiter());
-        subset.setListDelimiter(';');
-        assertEquals("Wrong list delimiter in parent", ';', config
-                .getListDelimiter());
+        AbstractConfiguration subset =
+                (AbstractConfiguration) config.subset("prefix");
+        ListDelimiterHandler listHandler = new DefaultListDelimiterHandler(',');
+        subset.setListDelimiterHandler(listHandler);
+        assertSame("Handler not passed to parent", listHandler,
+                config.getListDelimiterHandler());
     }
 
+    /**
+     * Tests whether the list delimiter handler from the parent configuration is
+     * used.
+     */
     @Test
-    public void testSetDelimiterParsingDisabled()
+    public void testGetListDelimiterHandlerFromParent()
     {
         BaseConfiguration config = new BaseConfiguration();
-        Configuration subset = config.subset("prefix");
-        subset.addProperty("list", "a,b,c");
-        assertEquals("Wrong value of property", "a,b,c", config
-                .getString("prefix.list"));
-
-        ((AbstractConfiguration) subset)
-                .setListDelimiterHandler(new DefaultListDelimiterHandler(','));
-        subset.addProperty("list2", "a,b,c");
-        assertEquals("Wrong size of list2", 3, config.getList("prefix.list2")
-                .size());
+        AbstractConfiguration subset =
+                (AbstractConfiguration) config.subset("prefix");
+        ListDelimiterHandler listHandler = new DefaultListDelimiterHandler(',');
+        config.setListDelimiterHandler(listHandler);
+        assertSame("Not list handler from parent", listHandler,
+                subset.getListDelimiterHandler());
     }
 
+    /**
+     * Tests the case that the parent configuration is not derived from
+     * AbstractConfiguration and thus does not support a list delimiter handler.
+     */
     @Test
-    public void testIsDelimiterParsingDisabled()
+    public void testSetListDelimiterHandlerParentNotSupported()
     {
-        BaseConfiguration config = new BaseConfiguration();
-        AbstractConfiguration subset = (AbstractConfiguration) config
-                .subset("prefix");
-        config.setDelimiterParsingDisabled(true);
-        assertTrue("Wrong value of list parsing flag in subset", subset
-                .isDelimiterParsingDisabled());
-        subset.setDelimiterParsingDisabled(false);
-        assertFalse("Wrong value of list parsing flag in parent", config
-                .isDelimiterParsingDisabled());
+        Configuration config = EasyMock.createNiceMock(Configuration.class);
+        EasyMock.replay(config);
+        SubsetConfiguration subset = new SubsetConfiguration(config, "prefix");
+        ListDelimiterHandler listHandler = new DefaultListDelimiterHandler(',');
+        subset.setListDelimiterHandler(listHandler);
+        assertSame("List delimiter handler not set", listHandler,
+                subset.getListDelimiterHandler());
     }
 
     /**