commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1434918 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/combined/
Date Thu, 17 Jan 2013 21:17:39 GMT
Author: oheger
Date: Thu Jan 17 21:17:38 2013
New Revision: 1434918

URL: http://svn.apache.org/viewvc?rev=1434918&view=rev
Log:
Implemented a special clone() implementation for CombinedBuilderParametersImpl.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java?rev=1434918&r1=1434917&r2=1434918&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedBuilderParametersImpl.java
Thu Jan 17 21:17:38 2013
@@ -20,6 +20,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.configuration.ConfigurationUtils;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.builder.BasicBuilderParameters;
 import org.apache.commons.configuration.builder.BuilderParameters;
@@ -318,4 +319,18 @@ public class CombinedBuilderParametersIm
         params.put(PARAM_KEY, this);
         return params;
     }
+
+    /**
+     * {@inheritDoc} This implementation also clones the parameters object for
+     * the definition builder if possible.
+     */
+    @Override
+    public CombinedBuilderParametersImpl clone()
+    {
+        CombinedBuilderParametersImpl copy =
+                (CombinedBuilderParametersImpl) super.clone();
+        copy.setDefinitionBuilderParameters((BuilderParameters) ConfigurationUtils
+                .cloneIfPossible(getDefinitionBuilderParameters()));
+        return copy;
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java?rev=1434918&r1=1434917&r2=1434918&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedBuilderParametersImpl.java
Thu Jan 17 21:17:38 2013
@@ -18,6 +18,7 @@ package org.apache.commons.configuration
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
@@ -31,6 +32,7 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.ConfigurationBuilder;
+import org.apache.commons.configuration.builder.XMLBuilderParametersImpl;
 import org.easymock.EasyMock;
 import org.junit.Test;
 
@@ -319,4 +321,30 @@ public class TestCombinedBuilderParamete
         assertSame("Wrong def parameters", defparams,
                 params.getDefinitionBuilderParameters());
     }
+
+    /**
+     * Tests whether cloning works as expected.
+     */
+    @Test
+    public void testClone()
+    {
+        CombinedBuilderParametersImpl params =
+                new CombinedBuilderParametersImpl();
+        params.setBasePath("some base path");
+        XMLBuilderParametersImpl defParams = new XMLBuilderParametersImpl();
+        defParams.setSystemID("someSysID");
+        params.setDefinitionBuilderParameters(defParams);
+        CombinedBuilderParametersImpl clone = params.clone();
+        assertEquals("Wrong field value", params.getBasePath(),
+                clone.getBasePath());
+        assertNotSame("Parameters object not cloned",
+                params.getDefinitionBuilderParameters(),
+                clone.getDefinitionBuilderParameters());
+        assertEquals(
+                "Wrong field value in parameters object",
+                params.getDefinitionBuilderParameters().getParameters()
+                        .get("systemID"),
+                clone.getDefinitionBuilderParameters().getParameters()
+                        .get("systemID"));
+    }
 }



Mime
View raw message