commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1415862 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/FileBasedBuilderParameters.java test/java/org/apache/commons/configuration/builder/TestFileBasedBuilderParameters.java
Date Fri, 30 Nov 2012 21:50:58 GMT
Author: oheger
Date: Fri Nov 30 21:50:57 2012
New Revision: 1415862

URL: http://svn.apache.org/viewvc?rev=1415862&view=rev
Log:
Added more properties to FileBasedBuilderParameters.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParameters.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/FileBasedBuilderParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParameters.java?rev=1415862&r1=1415861&r2=1415862&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParameters.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedBuilderParameters.java
Fri Nov 30 21:50:57 2012
@@ -21,6 +21,7 @@ import java.net.URL;
 import java.util.Collections;
 import java.util.Map;
 
+import org.apache.commons.configuration.FileSystem;
 import org.apache.commons.configuration.io.FileHandler;
 
 /**
@@ -193,6 +194,54 @@ public class FileBasedBuilderParameters 
     }
 
     /**
+     * Sets the file name of the associated {@code FileHandler}.
+     *
+     * @param name the file name
+     * @return a reference to this object for method chaining
+     */
+    public FileBasedBuilderParameters setFileName(String name)
+    {
+        getFileHandler().setFileName(name);
+        return this;
+    }
+
+    /**
+     * Sets the base path of the associated {@code FileHandler}.
+     *
+     * @param path the base path
+     * @return a reference to this object for method chaining
+     */
+    public FileBasedBuilderParameters setBasePath(String path)
+    {
+        getFileHandler().setBasePath(path);
+        return this;
+    }
+
+    /**
+     * Sets the {@code FileSystem} of the associated {@code FileHandler}.
+     *
+     * @param fs the {@code FileSystem}
+     * @return a reference to this object for method chaining
+     */
+    public FileBasedBuilderParameters setFileSystem(FileSystem fs)
+    {
+        getFileHandler().setFileSystem(fs);
+        return this;
+    }
+
+    /**
+     * Sets the encoding of the associated {@code FileHandler}.
+     *
+     * @param enc the encoding
+     * @return a reference to this object for method chaining
+     */
+    public FileBasedBuilderParameters setEncoding(String enc)
+    {
+        getFileHandler().setEncoding(enc);
+        return this;
+    }
+
+    /**
      * {@inheritDoc} This implementation returns a map which contains this
      * object itself under a specific key. The static {@code fromParameters()}
      * method can be used to extract an instance from a parameters map.

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=1415862&r1=1415861&r2=1415862&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
Fri Nov 30 21:50:57 2012
@@ -28,7 +28,9 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.configuration.ConfigurationAssert;
+import org.apache.commons.configuration.FileSystem;
 import org.apache.commons.configuration.io.FileHandler;
+import org.easymock.EasyMock;
 import org.junit.Test;
 
 /**
@@ -118,6 +120,58 @@ public class TestFileBasedBuilderParamet
     }
 
     /**
+     * Tests whether a file name can be set.
+     */
+    @Test
+    public void testSetFileName()
+    {
+        String name = "testConfig.xml";
+        FileBasedBuilderParameters params = new FileBasedBuilderParameters();
+        assertSame("Wrong result", params, params.setFileName(name));
+        assertEquals("Wrong name", name, params.getFileHandler().getFileName());
+    }
+
+    /**
+     * Tests whether a base path can be set.
+     */
+    @Test
+    public void testSetBasePath()
+    {
+        String path =
+                ConfigurationAssert.getTestFile("test.properties").getParentFile()
+                        .getAbsolutePath();
+        FileBasedBuilderParameters params = new FileBasedBuilderParameters();
+        assertSame("Wrong result", params, params.setBasePath(path));
+        assertEquals("Wrong path", path, params.getFileHandler().getBasePath());
+    }
+
+    /**
+     * Tests whether a file system can be set.
+     */
+    @Test
+    public void testSetFileSystem()
+    {
+        FileSystem fs = EasyMock.createMock(FileSystem.class);
+        EasyMock.replay(fs);
+        FileBasedBuilderParameters params = new FileBasedBuilderParameters();
+        assertSame("Wrong result", params, params.setFileSystem(fs));
+        assertSame("Wrong file system", fs, params.getFileHandler()
+                .getFileSystem());
+    }
+
+    /**
+     * Tests whether an encoding can be set.
+     */
+    @Test
+    public void testSetEncoding()
+    {
+        String enc = "ISO-8859-1";
+        FileBasedBuilderParameters params = new FileBasedBuilderParameters();
+        assertSame("Wrong result", params, params.setEncoding(enc));
+        assertSame("Wrong encoding", enc, params.getFileHandler().getEncoding());
+    }
+
+    /**
      * Tests whether a map with parameters can be queried.
      */
     @Test



Mime
View raw message