Author: oheger
Date: Wed Jan 16 21:05:57 2013
New Revision: 1434398
URL: http://svn.apache.org/viewvc?rev=1434398&view=rev
Log:
Implemented a special clone() implementation for FileBasedBuilderParametersImpl.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParametersImpl.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedBuilderParameters.java
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParametersImpl.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParametersImpl.java?rev=1434398&r1=1434397&r2=1434398&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParametersImpl.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParametersImpl.java
Wed Jan 16 21:05:57 2013
@@ -55,7 +55,7 @@ public class FileBasedBuilderParametersI
/**
* Stores the associated file handler for the location of the
configuration.
*/
- private final FileHandler fileHandler;
+ private FileHandler fileHandler;
/** The refresh delay for reloading support. */
private long reloadingRefreshDelay;
@@ -204,4 +204,18 @@ public class FileBasedBuilderParametersI
params.put(PARAM_KEY, this);
return params;
}
+
+ /**
+ * {@inheritDoc} This implementation also creates a copy of the
+ * {@code FileHandler}.
+ */
+ @Override
+ public FileBasedBuilderParametersImpl clone()
+ {
+ FileBasedBuilderParametersImpl copy =
+ (FileBasedBuilderParametersImpl) super.clone();
+ copy.fileHandler =
+ new FileHandler(fileHandler.getContent(), fileHandler);
+ return copy;
+ }
}
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedBuilderParameters.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedBuilderParameters.java?rev=1434398&r1=1434397&r2=1434398&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedBuilderParameters.java
(original)
+++
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedBuilderParameters.java
Wed Jan 16 21:05:57 2013
@@ -18,6 +18,7 @@ package org.apache.commons.configuration
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -30,6 +31,7 @@ import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.configuration.ConfigurationAssert;
import org.apache.commons.configuration.FileSystem;
+import org.apache.commons.configuration.io.FileBased;
import org.apache.commons.configuration.io.FileHandler;
import org.easymock.EasyMock;
import org.junit.Test;
@@ -245,4 +247,28 @@ public class TestFileBasedBuilderParamet
assertEquals("Property not stored", Boolean.TRUE,
map.get("throwExceptionOnMissing"));
}
+
+ /**
+ * Tests a clone operation.
+ */
+ @Test
+ public void testClone()
+ {
+ FileBased content = EasyMock.createMock(FileBased.class);
+ EasyMock.replay(content);
+ FileHandler fh = new FileHandler(content);
+ FileBasedBuilderParametersImpl params =
+ new FileBasedBuilderParametersImpl(fh);
+ params.setThrowExceptionOnMissing(true);
+ params.setFileName("test.xml");
+ FileBasedBuilderParametersImpl clone = params.clone();
+ assertEquals("Wrong exception flag", Boolean.TRUE, clone
+ .getParameters().get("throwExceptionOnMissing"));
+ assertEquals("File name not copied", "test.xml", clone.getFileHandler()
+ .getFileName());
+ assertSame("Content not copied", content, clone.getFileHandler()
+ .getContent());
+ assertNotSame("No copy of file handler", params.getFileHandler(),
+ clone.getFileHandler());
+ }
}