You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/07/13 22:07:32 UTC
svn commit: r1610300 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
Author: oheger
Date: Sun Jul 13 20:07:32 2014
New Revision: 1610300
URL: http://svn.apache.org/r1610300
Log:
Removed methods for adding error listeners from BasicConfigurationBuilder.
Error events are now propagated via regular event listeners.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java?rev=1610300&r1=1610299&r2=1610300&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java Sun Jul 13 20:07:32 2014
@@ -28,7 +28,6 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.beanutils.BeanDeclaration;
import org.apache.commons.configuration.beanutils.BeanHelper;
import org.apache.commons.configuration.beanutils.ConstructorArg;
-import org.apache.commons.configuration.event.ConfigurationErrorListener;
import org.apache.commons.configuration.event.Event;
import org.apache.commons.configuration.event.EventListener;
import org.apache.commons.configuration.event.EventListenerList;
@@ -303,38 +302,6 @@ public class BasicConfigurationBuilder<T
}
/**
- * Adds the specified listener for {@code ConfigurationErrorEvent}s to this
- * builder. It is also registered at the result objects produced by this
- * builder.
- *
- * @param l the listener to be registered
- * @return a reference to this builder for method chaining
- */
- public synchronized BasicConfigurationBuilder<T> addErrorListener(
- ConfigurationErrorListener l)
- {
- //errorListeners.add(l);
- fetchEventSource().addErrorListener(l);
- return this;
- }
-
- /**
- * Removes the specified listener for {@code ConfigurationErrorEvent}s from
- * this builder. It is also removed from the current result object if it
- * exists.
- *
- * @param l the listener to be removed
- * @return a reference to this builder for method chaining
- */
- public synchronized BasicConfigurationBuilder<T> removeErrorListener(
- ConfigurationErrorListener l)
- {
- //errorListeners.remove(l);
- fetchEventSource().removeErrorListener(l);
- return this;
- }
-
- /**
* {@inheritDoc} This implementation creates the result configuration on
* first access. Later invocations return the same object until this builder
* is reset. The double-check idiom for lazy initialization is used (Bloch,
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java?rev=1610300&r1=1610299&r2=1610300&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java Sun Jul 13 20:07:32 2014
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertNot
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -45,8 +44,9 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.beanutils.XMLBeanDeclaration;
import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
import org.apache.commons.configuration.convert.ListDelimiterHandler;
-import org.apache.commons.configuration.event.ConfigurationErrorListener;
+import org.apache.commons.configuration.event.ConfigurationErrorEvent;
import org.apache.commons.configuration.event.ConfigurationEvent;
+import org.apache.commons.configuration.event.ErrorListenerTestImpl;
import org.apache.commons.configuration.event.EventListener;
import org.apache.commons.configuration.ex.ConfigurationException;
import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
@@ -54,7 +54,6 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.reloading.ReloadingDetector;
import org.easymock.EasyMock;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -397,52 +396,6 @@ public class TestBasicConfigurationBuild
}
/**
- * Tests whether error listeners can be registered.
- */
- @Test @Ignore //TODO error listeners have to be reworked
- public void testAddErrorListener() throws ConfigurationException
- {
- ConfigurationErrorListener l1 =
- EasyMock.createMock(ConfigurationErrorListener.class);
- ConfigurationErrorListener l2 =
- EasyMock.createMock(ConfigurationErrorListener.class);
- EasyMock.replay(l1, l2);
- BasicConfigurationBuilder<PropertiesConfiguration> builder =
- new BasicConfigurationBuilder<PropertiesConfiguration>(
- PropertiesConfiguration.class).addErrorListener(l1);
- PropertiesConfiguration config = builder.getConfiguration();
- builder.addErrorListener(l2);
- assertTrue("Listeners not registered", config.getErrorListeners()
- .containsAll(Arrays.asList(l1, l2)));
- }
-
- /**
- * Tests whether error listeners can be removed.
- */
- @Test @Ignore //TODO error listeners have to be reworked
- public void testRemoveErrorListener() throws ConfigurationException
- {
- ConfigurationErrorListener l1 =
- EasyMock.createMock(ConfigurationErrorListener.class);
- ConfigurationErrorListener l2 =
- EasyMock.createMock(ConfigurationErrorListener.class);
- EasyMock.replay(l1, l2);
- BasicConfigurationBuilder<PropertiesConfiguration> builder =
- new BasicConfigurationBuilder<PropertiesConfiguration>(
- PropertiesConfiguration.class).addErrorListener(l1)
- .addErrorListener(l2);
- builder.removeErrorListener(l2);
- PropertiesConfiguration config = builder.getConfiguration();
- assertFalse("Removed listener was registered", config
- .getErrorListeners().contains(l2));
- assertTrue("Listener not registered", config
- .getErrorListeners().contains(l1));
- builder.removeErrorListener(l1);
- assertFalse("Listener still registered", config
- .getErrorListeners().contains(l1));
- }
-
- /**
* Tests whether event listeners can be copied to another builder.
*/
@Test
@@ -450,12 +403,14 @@ public class TestBasicConfigurationBuild
{
EventListener<ConfigurationEvent> l1 = createEventListener();
EventListener<ConfigurationEvent> l2 = createEventListener();
+ EventListener<ConfigurationErrorEvent> l3 = new ErrorListenerTestImpl(null);
BasicConfigurationBuilder<PropertiesConfiguration> builder =
new BasicConfigurationBuilder<PropertiesConfiguration>(
PropertiesConfiguration.class);
- builder.addConfigurationListener(ConfigurationEvent.ANY, l1)
- .addConfigurationListener(ConfigurationEvent.ANY_HIERARCHICAL,
+ builder.addConfigurationListener(ConfigurationEvent.ANY, l1);
+ builder.addConfigurationListener(ConfigurationEvent.ANY_HIERARCHICAL,
l2);
+ builder.addConfigurationListener(ConfigurationErrorEvent.ANY, l3);
BasicConfigurationBuilder<XMLConfiguration> builder2 =
new BasicConfigurationBuilder<XMLConfiguration>(
XMLConfiguration.class);
@@ -471,6 +426,10 @@ public class TestBasicConfigurationBuild
listeners.size());
assertTrue("Listener 1 not found", listeners.contains(l1));
assertTrue("Listener 2 not found", listeners.contains(l2));
+ Collection<EventListener<? super ConfigurationErrorEvent>> errListeners =
+ config.getEventListeners(ConfigurationErrorEvent.ANY);
+ assertEquals("Wrong number of error listeners", 1, errListeners.size());
+ assertTrue("Wrong error listener", errListeners.contains(l3));
}
/**