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 2013/05/05 22:23:19 UTC
svn commit: r1479378 - in
/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration:
SynchronizerTestImpl.java TestAbstractConfigurationSynchronization.java
Author: oheger
Date: Sun May 5 20:23:14 2013
New Revision: 1479378
URL: http://svn.apache.org/r1479378
Log:
Made SynchronizerTestImpl helper class a top-level class.
It can now be used by other test classes, too.
Added:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/SynchronizerTestImpl.java
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationSynchronization.java
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/SynchronizerTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/SynchronizerTestImpl.java?rev=1479378&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/SynchronizerTestImpl.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/SynchronizerTestImpl.java Sun May 5 20:23:14 2013
@@ -0,0 +1,134 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * A test implementation of Synchronizer which allows keeping track about
+ * the methods called by the configuration.
+ *
+ * @version $Id$
+ */
+class SynchronizerTestImpl implements Synchronizer
+{
+ /** A buffer for registering the methods invoked by clients. */
+ private final StringBuilder methods = new StringBuilder();
+
+ /**
+ * {@inheritDoc} Registers this invocation.
+ */
+ public void beginRead()
+ {
+ append(Methods.BEGIN_READ);
+ }
+
+ /**
+ * {@inheritDoc} Registers this invocation.
+ */
+ public void endRead()
+ {
+ append(Methods.END_READ);
+ }
+
+ /**
+ * {@inheritDoc} Registers this invocation.
+ */
+ public void beginWrite()
+ {
+ append(Methods.BEGIN_WRITE);
+ }
+
+ /**
+ * {@inheritDoc} Registers this invocation.
+ */
+ public void endWrite()
+ {
+ append(Methods.END_WRITE);
+ }
+
+ /**
+ * Verifies that the passed in methods were called in this order.
+ *
+ * @param expMethods the expected methods
+ */
+ public void verify(Methods... expMethods)
+ {
+ assertEquals("Wrong methods invoked",
+ constructExpectedMethods(expMethods), methods.toString());
+ }
+
+ /**
+ * Verifies that the specified methods were called at the beginning of
+ * the interaction with the synchronizer.
+ *
+ * @param expMethods the expected methods
+ */
+ public void verifyStart(Methods... expMethods)
+ {
+ assertTrue("Wrong methods at start: " + methods, methods.toString()
+ .startsWith(constructExpectedMethods(expMethods)));
+ }
+
+ /**
+ * Verifies that the specified methods were called at the end of the
+ * interaction with the synchronizer.
+ *
+ * @param expMethods the expected methods
+ */
+ public void verifyEnd(Methods... expMethods)
+ {
+ assertTrue("Wrong methods at start: " + methods, methods.toString()
+ .endsWith(constructExpectedMethods(expMethods)));
+ }
+
+ /**
+ * Generates a string with expected methods from the given array.
+ *
+ * @param expMethods the array with expected methods
+ * @return a corresponding string representation
+ */
+ private String constructExpectedMethods(Methods... expMethods)
+ {
+ StringBuilder buf = new StringBuilder();
+ for (Methods m : expMethods)
+ {
+ buf.append(m);
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Adds a method name to the internal buffer. Called by all interface
+ * methods.
+ *
+ * @param m the method that was invoked
+ */
+ private void append(Methods m)
+ {
+ methods.append(m);
+ }
+
+ /**
+ * An enumeration with the methods of the Synchronizer which can be called.
+ */
+ public static enum Methods
+ {
+ BEGIN_READ, END_READ, BEGIN_WRITE, END_WRITE
+ }
+}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationSynchronization.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationSynchronization.java?rev=1479378&r1=1479377&r2=1479378&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationSynchronization.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationSynchronization.java Sun May 5 20:23:14 2013
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import org.apache.commons.configuration.SynchronizerTestImpl.Methods;
import org.apache.commons.configuration.io.FileHandler;
import org.junit.Before;
import org.junit.Test;
@@ -171,116 +172,4 @@ public class TestAbstractConfigurationSy
assertEquals("Wrong synchronizer for subset",
NoOpSynchronizer.INSTANCE, subset.getSynchronizer());
}
-
- /**
- * An enumeration with the methods of the Synchronizer which can be called.
- */
- private static enum Methods
- {
- BEGIN_READ, END_READ, BEGIN_WRITE, END_WRITE
- }
-
- /**
- * A test implementation of Synchronizer which allows keeping track about
- * the methods called by the configuration.
- */
- private static class SynchronizerTestImpl implements Synchronizer
- {
- /** A buffer for registering the methods invoked by clients. */
- private final StringBuilder methods = new StringBuilder();
-
- /**
- * {@inheritDoc} Registers this invocation.
- */
- public void beginRead()
- {
- append(Methods.BEGIN_READ);
- }
-
- /**
- * {@inheritDoc} Registers this invocation.
- */
- public void endRead()
- {
- append(Methods.END_READ);
- }
-
- /**
- * {@inheritDoc} Registers this invocation.
- */
- public void beginWrite()
- {
- append(Methods.BEGIN_WRITE);
- }
-
- /**
- * {@inheritDoc} Registers this invocation.
- */
- public void endWrite()
- {
- append(Methods.END_WRITE);
- }
-
- /**
- * Verifies that the passed in methods were called in this order.
- *
- * @param expMethods the expected methods
- */
- public void verify(Methods... expMethods)
- {
- assertEquals("Wrong methods invoked",
- constructExpectedMethods(expMethods), methods.toString());
- }
-
- /**
- * Verifies that the specified methods were called at the beginning of
- * the interaction with the synchronizer.
- *
- * @param expMethods the expected methods
- */
- public void verifyStart(Methods... expMethods)
- {
- assertTrue("Wrong methods at start: " + methods, methods.toString()
- .startsWith(constructExpectedMethods(expMethods)));
- }
-
- /**
- * Verifies that the specified methods were called at the end of the
- * interaction with the synchronizer.
- *
- * @param expMethods the expected methods
- */
- public void verifyEnd(Methods... expMethods)
- {
- assertTrue("Wrong methods at start: " + methods, methods.toString()
- .endsWith(constructExpectedMethods(expMethods)));
- }
-
- /**
- * Generates a string with expected methods from the given array.
- *
- * @param expMethods the array with expected methods
- * @return a corresponding string representation
- */
- private String constructExpectedMethods(Methods... expMethods)
- {
- StringBuilder buf = new StringBuilder();
- for (Methods m : expMethods)
- {
- buf.append(m);
- }
- return buf.toString();
- }
-
- /**
- * Adds a method name to the internal buffer. Called by all interface
- * methods.
- *
- * @param m the method that was invoked
- */
- private void append(Methods m)
- {
- methods.append(m);
- }
- }
}