commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1435337 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/combined/
Date Fri, 18 Jan 2013 20:49:05 GMT
Author: oheger
Date: Fri Jan 18 20:49:05 2013
New Revision: 1435337

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

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

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileBuilderParametersImpl.java?rev=1435337&r1=1435336&r2=1435337&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileBuilderParametersImpl.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileBuilderParametersImpl.java
Fri Jan 18 20:49:05 2013
@@ -18,6 +18,7 @@ package org.apache.commons.configuration
 
 import java.util.Map;
 
+import org.apache.commons.configuration.ConfigurationUtils;
 import org.apache.commons.configuration.builder.BasicBuilderParameters;
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
@@ -152,4 +153,18 @@ public class MultiFileBuilderParametersI
         params.put(PARAM_KEY, this);
         return params;
     }
+
+    /**
+     * {@inheritDoc} This implementation also tries to clone the parameters
+     * object for managed builders if possible.
+     */
+    @Override
+    public MultiFileBuilderParametersImpl clone()
+    {
+        MultiFileBuilderParametersImpl copy =
+                (MultiFileBuilderParametersImpl) super.clone();
+        copy.setManagedBuilderParameters((BuilderParameters) ConfigurationUtils
+                .cloneIfPossible(getManagedBuilderParameters()));
+        return copy;
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileBuilderParametersImpl.java?rev=1435337&r1=1435336&r2=1435337&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileBuilderParametersImpl.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileBuilderParametersImpl.java
Fri Jan 18 20:49:05 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;
 
@@ -26,6 +27,7 @@ import java.util.Map;
 
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
 import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
@@ -128,4 +130,28 @@ public class TestMultiFileBuilderParamet
         assertSame("Wrong managed parameters", bp,
                 params.getManagedBuilderParameters());
     }
+
+    /**
+     * Tests extended cloning functionality.
+     */
+    @Test
+    public void testClone()
+    {
+        FileBasedBuilderParametersImpl managedParams =
+                new FileBasedBuilderParametersImpl();
+        managedParams.setFileName("test.xml");
+        params.setManagedBuilderParameters(managedParams);
+        params.setFilePattern("somePattern");
+        MultiFileBuilderParametersImpl clone = params.clone();
+        assertEquals("Wrong pattern", params.getFilePattern(),
+                clone.getFilePattern());
+        assertNotSame("Managed parameters not cloned",
+                params.getManagedBuilderParameters(),
+                clone.getManagedBuilderParameters());
+        assertEquals("Wrong file name", managedParams.getFileHandler()
+                .getFileName(),
+                ((FileBasedBuilderParametersImpl) clone
+                        .getManagedBuilderParameters()).getFileHandler()
+                        .getFileName());
+    }
 }



Mime
View raw message