commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1427221 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
Date Mon, 31 Dec 2012 18:56:22 GMT
Author: oheger
Date: Mon Dec 31 18:56:21 2012
New Revision: 1427221

URL: http://svn.apache.org/viewvc?rev=1427221&view=rev
Log:
Allowed access to a combined reloading controller's sub controllers.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java?rev=1427221&r1=1427220&r2=1427221&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
Mon Dec 31 18:56:21 2012
@@ -18,6 +18,7 @@ package org.apache.commons.configuration
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 
 /**
  * <p>
@@ -62,6 +63,18 @@ public class CombinedReloadingController
     }
 
     /**
+     * Returns a (unmodifiable) collection with the sub controllers managed by
+     * this combined controller.
+     *
+     * @return a collection with sub controllers
+     */
+    public Collection<ReloadingController> getSubControllers()
+    {
+        return ((MultiReloadingControllerDetector) getDetector())
+                .getControllers();
+    }
+
+    /**
      * Creates a specialized detector object which manages the passed in sub
      * controllers. The collection with controllers is also checked for
      * validity.
@@ -91,7 +104,8 @@ public class CombinedReloadingController
             }
         }
 
-        return new MultiReloadingControllerDetector(ctrls);
+        return new MultiReloadingControllerDetector(
+                Collections.unmodifiableCollection(ctrls));
     }
 
     /**
@@ -125,7 +139,7 @@ public class CombinedReloadingController
          */
         public boolean isReloadingRequired()
         {
-            for (ReloadingController rc : controllers)
+            for (ReloadingController rc : getControllers())
             {
                 if (rc.checkForReloading(null) || rc.isInReloadingState())
                 {
@@ -141,10 +155,20 @@ public class CombinedReloadingController
          */
         public void reloadingPerformed()
         {
-            for (ReloadingController rc : controllers)
+            for (ReloadingController rc : getControllers())
             {
                 rc.resetReloadingState();
             }
         }
+
+        /**
+         * Returns the collection with managed sub controllers.
+         *
+         * @return the controllers the sub controllers
+         */
+        Collection<ReloadingController> getControllers()
+        {
+            return controllers;
+        }
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java?rev=1427221&r1=1427220&r2=1427221&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
Mon Dec 31 18:56:21 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.configuration.reloading;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -177,4 +178,30 @@ public class TestCombinedReloadingContro
         ctrl.resetReloadingState();
         verifySubSontrollers();
     }
+
+    /**
+     * Tests whether the sub controllers can be accessed.
+     */
+    @Test
+    public void testGetSubControllers()
+    {
+        CombinedReloadingController ctrl = setUpController();
+        replaySubControllers();
+        Collection<ReloadingController> subs = ctrl.getSubControllers();
+        assertEquals("Wrong number of sub controllers", subControllers.length,
+                subs.size());
+        assertTrue("Wrong sub controllers",
+                subs.containsAll(Arrays.asList(subControllers)));
+    }
+
+    /**
+     * Tests that the list of sub controllers cannot be manipulated.
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGetSubControllersModify()
+    {
+        Collection<ReloadingController> subs =
+                setUpController().getSubControllers();
+        subs.clear();
+    }
 }



Mime
View raw message