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:01:05 UTC
svn commit: r1610288 - in
/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event:
AbstractEventListenerTestImpl.java EventListenerTestImpl.java
Author: oheger
Date: Sun Jul 13 20:01:05 2014
New Revision: 1610288
URL: http://svn.apache.org/r1610288
Log:
Added AbstractEventListenerTestImpl as base class for test event listeners.
This class defines basic functionlity for testing whether events of a specific
type have been received.
Added:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/AbstractEventListenerTestImpl.java
- copied, changed from r1610287, commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java
Copied: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/AbstractEventListenerTestImpl.java (from r1610287, commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/AbstractEventListenerTestImpl.java?p2=commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/AbstractEventListenerTestImpl.java&p1=commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java&r1=1610287&r2=1610288&rev=1610288&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/AbstractEventListenerTestImpl.java Sun Jul 13 20:01:05 2014
@@ -24,34 +24,37 @@ import java.util.LinkedList;
import java.util.List;
/**
- * A test event listener class that can be used for testing whether
- * event sources generated correct events.
+ * A base class for different types of event listeners which can be used in unit
+ * tests. This class provides functionality for testing the received events.
*
* @version $Id$
+ * @param <T> the type of events supported by this listener
*/
-public class EventListenerTestImpl implements EventListener<ConfigurationEvent>
+public abstract class AbstractEventListenerTestImpl<T extends Event> implements
+ EventListener<T>
{
/** The expected event source. */
private final Object expectedSource;
/** Stores the received events. */
- private final List<ConfigurationEvent> events;
+ private final List<T> events;
/**
- * Creates a new instance of {@code EventListenerTestImpl} and sets
+ * Creates a new instance of {@code AbstractEventListenerTestImpl} and sets
* the expected event source.
*
* @param source the event source (<b>null</b> if the source need not to be
* checked)
*/
- public EventListenerTestImpl(Object source)
+ protected AbstractEventListenerTestImpl(Object source)
{
expectedSource = source;
- events = new LinkedList<ConfigurationEvent>();
+ events = new LinkedList<T>();
}
@Override
- public void onEvent(ConfigurationEvent event) {
+ public void onEvent(T event)
+ {
events.add(event);
}
@@ -66,34 +69,15 @@ public class EventListenerTestImpl imple
}
/**
- * Checks an expected event.
- *
- * @param type the event type
- * @param propName the expected property name
- * @param propValue the expected property value
- * @param before the expected before flag
- */
- public void checkEvent(EventType<?> type, String propName, Object propValue,
- boolean before)
- {
- ConfigurationEvent e = nextEvent(type);
- assertEquals("Wrong property name", propName, e.getPropertyName());
- assertEquals("Wrong property value", propValue, e.getPropertyValue());
- assertEquals("Wrong before flag", before, e.isBeforeUpdate());
- }
-
- /**
- * Returns the next received event and checks for the expected type. This
- * method can be used instead of {@code checkEvent()} for comparing
- * complex event values.
+ * Returns the next received event and checks for the expected type.
*
* @param expectedType the expected type of the event
* @return the event object
*/
- public ConfigurationEvent nextEvent(EventType<?> expectedType)
+ public T nextEvent(EventType<?> expectedType)
{
assertFalse("Too few events received", events.isEmpty());
- ConfigurationEvent e = events.remove(0);
+ T e = events.remove(0);
if (expectedSource != null)
{
assertEquals("Wrong event source", expectedSource, e.getSource());
@@ -113,7 +97,7 @@ public class EventListenerTestImpl imple
{
while (events.size() > 1)
{
- ConfigurationEvent e = events.remove(0);
+ T e = events.remove(0);
assertTrue("Found end event in details", type != e.getEventType());
}
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java?rev=1610288&r1=1610287&r2=1610288&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/EventListenerTestImpl.java Sun Jul 13 20:01:05 2014
@@ -17,11 +17,6 @@
package org.apache.commons.configuration.event;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.LinkedList;
-import java.util.List;
/**
* A test event listener class that can be used for testing whether
@@ -29,14 +24,8 @@ import java.util.List;
*
* @version $Id$
*/
-public class EventListenerTestImpl implements EventListener<ConfigurationEvent>
+public class EventListenerTestImpl extends AbstractEventListenerTestImpl<ConfigurationEvent>
{
- /** The expected event source. */
- private final Object expectedSource;
-
- /** Stores the received events. */
- private final List<ConfigurationEvent> events;
-
/**
* Creates a new instance of {@code EventListenerTestImpl} and sets
* the expected event source.
@@ -46,23 +35,7 @@ public class EventListenerTestImpl imple
*/
public EventListenerTestImpl(Object source)
{
- expectedSource = source;
- events = new LinkedList<ConfigurationEvent>();
- }
-
- @Override
- public void onEvent(ConfigurationEvent event) {
- events.add(event);
- }
-
- /**
- * Checks if at least {@code minEvents} events have been received.
- *
- * @param minEvents the minimum number of expected events
- */
- public void checkEventCount(int minEvents)
- {
- assertTrue("Too view events received", events.size() >= minEvents);
+ super(source);
}
/**
@@ -81,48 +54,4 @@ public class EventListenerTestImpl imple
assertEquals("Wrong property value", propValue, e.getPropertyValue());
assertEquals("Wrong before flag", before, e.isBeforeUpdate());
}
-
- /**
- * Returns the next received event and checks for the expected type. This
- * method can be used instead of {@code checkEvent()} for comparing
- * complex event values.
- *
- * @param expectedType the expected type of the event
- * @return the event object
- */
- public ConfigurationEvent nextEvent(EventType<?> expectedType)
- {
- assertFalse("Too few events received", events.isEmpty());
- ConfigurationEvent e = events.remove(0);
- if (expectedSource != null)
- {
- assertEquals("Wrong event source", expectedSource, e.getSource());
- }
- assertEquals("Wrong event type", expectedType, e.getEventType());
- return e;
- }
-
- /**
- * Skips to the last received event and checks that no events of the given
- * type have been received. This method is used by checks for detail events
- * to ignore the detail events.
- *
- * @param type the event type
- */
- public void skipToLast(EventType<?> type)
- {
- while (events.size() > 1)
- {
- ConfigurationEvent e = events.remove(0);
- assertTrue("Found end event in details", type != e.getEventType());
- }
- }
-
- /**
- * Checks if all events has been processed.
- */
- public void done()
- {
- assertTrue("Too many events received", events.isEmpty());
- }
}