commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1090164 - in /commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event: AbstractTestConfigurationEvents.java ConfigurationListenerTestImpl.java
Date Fri, 08 Apr 2011 09:07:26 GMT
Author: oheger
Date: Fri Apr  8 09:07:25 2011
New Revision: 1090164

URL: http://svn.apache.org/viewvc?rev=1090164&view=rev
Log:
Made test configuration listener implementation a top-level type so that it can be used by
other test classes, too.

Added:
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
  (with props)
Modified:
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/AbstractTestConfigurationEvents.java

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/AbstractTestConfigurationEvents.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/AbstractTestConfigurationEvents.java?rev=1090164&r1=1090163&r2=1090164&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/AbstractTestConfigurationEvents.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/AbstractTestConfigurationEvents.java
Fri Apr  8 09:07:25 2011
@@ -16,14 +16,11 @@
  */
 package org.apache.commons.configuration.event;
 
-import java.util.LinkedList;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
 
 import junit.framework.TestCase;
 
+import org.apache.commons.configuration.AbstractConfiguration;
+
 /**
  * Base class for testing events generated by configuration classes derived from
  * AbstractConfiguration. This class implements a couple of tests related to
@@ -51,14 +48,14 @@ public abstract class AbstractTestConfig
     protected AbstractConfiguration config;
 
     /** A test event listener. */
-    protected TestConfigurationListener l;
+    protected ConfigurationListenerTestImpl l;
 
     protected void setUp() throws Exception
     {
         super.setUp();
         config = createConfiguration();
         config.addProperty(EXIST_PROPERTY, "existing value");
-        l = new TestConfigurationListener();
+        l = new ConfigurationListenerTestImpl(config);
         config.addConfigurationListener(l);
     }
 
@@ -181,89 +178,4 @@ public abstract class AbstractTestConfig
         l.checkEvent(AbstractConfiguration.EVENT_CLEAR, null, null, false);
         l.done();
     }
-
-    /**
-     * A test event listener class used for testing events generated by the
-     * configuration.
-     */
-    protected class TestConfigurationListener implements ConfigurationListener
-    {
-        /** Stores the received events. */
-        private LinkedList events = new LinkedList();
-
-        public void configurationChanged(ConfigurationEvent event)
-        {
-            events.add(event);
-        }
-
-        /**
-         * Checks if at least <code>minEvents</code> 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);
-        }
-
-        /**
-         * 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(int 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()</code> for
-         * comparing complex event values.
-         * @param expectedType the expected type of the event
-         * @return the event object
-         */
-        public ConfigurationEvent nextEvent(int expectedType)
-        {
-            assertFalse("Too few events received", events.isEmpty());
-            ConfigurationEvent e = (ConfigurationEvent) events.removeFirst();
-            assertEquals("Wrong event source", config, e.getSource());
-            assertEquals("Wrong event type", expectedType, e.getType());
-            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(int type)
-        {
-            while (events.size() > 1)
-            {
-                ConfigurationEvent e = (ConfigurationEvent) events
-                        .removeFirst();
-                assertTrue("Found end event in details", type != e.getType());
-            }
-        }
-
-        /**
-         * Checks if all events has been processed.
-         */
-        public void done()
-        {
-            assertTrue("Too many events received", events.isEmpty());
-        }
-    }
 }

Added: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java?rev=1090164&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
(added)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
Fri Apr  8 09:07:25 2011
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.event;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * A test event listener class that can be used for testing whether
+ * configurations generated correct events.
+ *
+ * @author <a
+ *         href="http://commons.apache.org/configuration/team-list.html">Commons
+ *         Configuration team</a>
+ * @version $Id$
+ */
+public class ConfigurationListenerTestImpl implements ConfigurationListener
+{
+    /** The expected event source. */
+    private final Object expectedSource;
+
+    /** Stores the received events. */
+    private final List events;
+
+    /**
+     * Creates a new instance of {@code ConfigurationListenerTestImpl} and sets
+     * the expected event source.
+     *
+     * @param source the event source (<b>null</b> if the source need not to
be
+     *        checked)
+     */
+    public ConfigurationListenerTestImpl(Object source)
+    {
+        expectedSource = source;
+        events = new LinkedList();
+    }
+
+    public void configurationChanged(ConfigurationEvent event)
+    {
+        events.add(event);
+    }
+
+    /**
+     * Checks if at least <code>minEvents</code> events have been received.
+     *
+     * @param minEvents the minimum number of expected events
+     */
+    public void checkEventCount(int minEvents)
+    {
+        AbstractTestConfigurationEvents.assertTrue("Too view events received",
+                events.size() >= minEvents);
+    }
+
+    /**
+     * 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(int type, String propName, Object propValue,
+            boolean before)
+    {
+        ConfigurationEvent e = nextEvent(type);
+        AbstractTestConfigurationEvents.assertEquals("Wrong property name",
+                propName, e.getPropertyName());
+        AbstractTestConfigurationEvents.assertEquals("Wrong property value",
+                propValue, e.getPropertyValue());
+        AbstractTestConfigurationEvents.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()</code> for comparing
+     * complex event values.
+     *
+     * @param expectedType the expected type of the event
+     * @return the event object
+     */
+    public ConfigurationEvent nextEvent(int expectedType)
+    {
+        AbstractTestConfigurationEvents.assertFalse("Too few events received",
+                events.isEmpty());
+        ConfigurationEvent e = (ConfigurationEvent) events.remove(0);
+        if (expectedSource != null)
+        {
+            AbstractTestConfigurationEvents.assertEquals("Wrong event source",
+                    expectedSource, e.getSource());
+        }
+        AbstractTestConfigurationEvents.assertEquals("Wrong event type",
+                expectedType, e.getType());
+        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(int type)
+    {
+        while (events.size() > 1)
+        {
+            ConfigurationEvent e = (ConfigurationEvent) events.remove(0);
+            AbstractTestConfigurationEvents.assertTrue(
+                    "Found end event in details", type != e.getType());
+        }
+    }
+
+    /**
+     * Checks if all events has been processed.
+     */
+    public void done()
+    {
+        AbstractTestConfigurationEvents.assertTrue("Too many events received",
+                events.isEmpty());
+    }
+}

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/event/ConfigurationListenerTestImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message