commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1625139 - /commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
Date Mon, 15 Sep 2014 19:58:15 GMT
Author: oheger
Date: Mon Sep 15 19:58:15 2014
New Revision: 1625139

URL: http://svn.apache.org/r1625139
Log:
Added some test helper methods related to the processing of configuration keys.

These methods allow the removal of all references to [collections] in test
classes.

Modified:
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java?rev=1625139&r1=1625138&r2=1625139&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
Mon Sep 15 19:58:15 2014
@@ -23,7 +23,12 @@ import static org.junit.Assert.assertTru
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.commons.configuration2.ex.ConfigurationRuntimeException;
 
@@ -140,6 +145,47 @@ public class ConfigurationAssert
     }
 
     /**
+     * Returns a list with all keys defined for the specified configuration.
+     *
+     * @param config the configuration
+     * @return a list with all keys of this configuration
+     */
+    public static List<String> keysToList(Configuration config)
+    {
+        List<String> keyList = new LinkedList<String>();
+        appendKeys(config, keyList);
+        return keyList;
+    }
+
+    /**
+     * Returns a set with all keys defined for the specified configuration.
+     *
+     * @param config the configuration
+     * @return a set with all keys of this configuration
+     */
+    public static Set<String> keysToSet(Configuration config)
+    {
+        Set<String> keySet = new HashSet<String>();
+        appendKeys(config, keySet);
+        return keySet;
+    }
+
+    /**
+     * Appends all keys in the specified configuration to the given collection.
+     *
+     * @param config the configuration
+     * @param collection the target collection
+     */
+    public static void appendKeys(Configuration config,
+            Collection<String> collection)
+    {
+        for (Iterator<String> it = config.getKeys(); it.hasNext();)
+        {
+            collection.add(it.next());
+        }
+    }
+
+    /**
      * Helper method for converting a file to a URL.
      *
      * @param file the file



Mime
View raw message