commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1609804 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/event/EventListenerList.java test/java/org/apache/commons/configuration/event/TestEventListenerList.java
Date Fri, 11 Jul 2014 20:24:10 GMT
Author: oheger
Date: Fri Jul 11 20:24:09 2014
New Revision: 1609804

URL: http://svn.apache.org/r1609804
Log:
Extended EventListenerList to query registration information.

A method was added which returns an unmodifiable list with event listener
registration information.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java?rev=1609804&r1=1609803&r2=1609804&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
Fri Jul 11 20:24:09 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.configuration.event;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -194,6 +195,17 @@ public class EventListenerList
     }
 
     /**
+     * Returns an (unmodifiable) list with registration information about all
+     * event listeners registered at this object.
+     *
+     * @return a list with event listener registration information
+     */
+    public List<EventListenerRegistrationData<?>> getRegistrations()
+    {
+        return Collections.unmodifiableList(listeners);
+    }
+
+    /**
      * Helper method for calling an event listener with an event. We have to
      * operate on raw types to make this code compile. However, this is safe
      * because of the way the listeners have been registered and associated with

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java?rev=1609804&r1=1609803&r2=1609804&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
Fri Jul 11 20:24:09 2014
@@ -428,6 +428,39 @@ public class TestEventListenerList
     }
 
     /**
+     * Tests whether all event listener registrations can be queried.
+     */
+    @Test
+    public void testGetRegistrations()
+    {
+        EventListenerRegistrationData<EventSub1> reg1 =
+                new EventListenerRegistrationData<EventSub1>(typeSub1,
+                        new ListenerTestImpl());
+        EventListenerRegistrationData<EventSub2> reg2 =
+                new EventListenerRegistrationData<EventSub2>(typeSub2,
+                        new ListenerTestImpl());
+        list.addEventListener(reg1);
+        list.addEventListener(reg2);
+
+        List<EventListenerRegistrationData<?>> registrations =
+                list.getRegistrations();
+        assertEquals("Wrong number of registrations", 2, registrations.size());
+        assertTrue("Registration 1 not found", registrations.contains(reg1));
+        assertTrue("Registration 2 not found", registrations.contains(reg2));
+    }
+
+    /**
+     * Tests that the list with registration information cannot be modified.
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGetRegistrationsModify()
+    {
+        list.getRegistrations().add(
+                new EventListenerRegistrationData<EventBase>(typeBase,
+                        new ListenerTestImpl()));
+    }
+
+    /**
      * Test event class. For testing purposes, a small hierarchy of test event
      * class is created. This way it can be checked whether event types are
      * correctly evaluated and take the event hierarchy into account.



Mime
View raw message