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 2009/10/26 22:00:06 UTC
svn commit: r829954 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
Author: oheger
Date: Mon Oct 26 21:00:05 2009
New Revision: 829954
URL: http://svn.apache.org/viewvc?rev=829954&view=rev
Log:
Some more tests for FlatNodeHandler.
Made FlatNodeHandler stateless.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java?rev=829954&r1=829953&r2=829954&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java Mon Oct 26 21:00:05 2009
@@ -61,9 +61,6 @@
*/
class FlatNodeHandler extends AbstractNodeHandler<FlatNode>
{
- /** Stores the NodeHandlerRegistry. */
- private NodeHandlerRegistry nodeHandlerRegistry;
-
/**
* Adds an attribute to the specified node. Flat nodes do not support
* attributes, so this implementation just throws an exception.
@@ -275,9 +272,9 @@
* @param registry the {@code NodeHandlerRegistry}
*/
@Override
- public void initNodeHandlerRegistry(NodeHandlerRegistry registry)
+ public void initNodeHandlerRegistry(final NodeHandlerRegistry registry)
{
- nodeHandlerRegistry = registry;
+ assert registry != null : "No parent registry!";
registry.addSubRegistry(new NodeHandlerRegistry()
{
@@ -290,8 +287,7 @@
*/
public NodeHandler<?> resolveHandler(Object node)
{
- assert nodeHandlerRegistry != null : "No parent registry!";
- return nodeHandlerRegistry.resolveHandler(node);
+ return registry.resolveHandler(node);
}
/**
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java?rev=829954&r1=829953&r2=829954&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java Mon Oct 26 21:00:05 2009
@@ -24,6 +24,9 @@
import org.apache.commons.configuration2.ConfigurationRuntimeException;
import org.apache.commons.configuration2.event.ConfigurationEvent;
import org.apache.commons.configuration2.event.ConfigurationListener;
+import org.apache.commons.configuration2.expr.NodeHandler;
+import org.apache.commons.configuration2.expr.NodeHandlerRegistry;
+import org.easymock.EasyMock;
/**
* Test class for FlatNodeHandler.
@@ -325,6 +328,58 @@
}
/**
+ * Tests whether the handler registers itself as a sub node handler
+ * registry.
+ */
+ public void testInitNodeHandlerRegistrySubReg()
+ {
+ NodeHandlerRegistryTestImpl reg = new NodeHandlerRegistryTestImpl();
+ handler.initNodeHandlerRegistry(reg);
+ assertNotNull("No sub registry registered", reg.subRegistry);
+ }
+
+ /**
+ * Tests the resolveHandler() implementation of the node handler registry.
+ */
+ public void testNodeHandlerRegistryResolveHandler()
+ {
+ NodeHandlerRegistryTestImpl reg = new NodeHandlerRegistryTestImpl();
+ handler.initNodeHandlerRegistry(reg);
+ Object node = new Object();
+ NodeHandler<?> h = EasyMock.createMock(NodeHandler.class);
+ EasyMock.replay(h);
+ reg.resolveHandler = h;
+ assertEquals("Wrong resolved handler", h, reg.subRegistry
+ .resolveHandler(node));
+ assertEquals("Wrong node passed to resolveHandler", node,
+ reg.resolveNode);
+ EasyMock.verify(h);
+ }
+
+ /**
+ * Tests the lookupHandler() implementation of the node handler registry if
+ * a flat node is passed in.
+ */
+ public void testNodeHandlerRegistryLookupHandlerFlatNode()
+ {
+ NodeHandlerRegistryTestImpl reg = new NodeHandlerRegistryTestImpl();
+ handler.initNodeHandlerRegistry(reg);
+ assertEquals("Wrong handler", handler, reg.subRegistry.lookupHandler(
+ new FlatRootNode(config), true));
+ }
+
+ /**
+ * Tests the lookupHandler() implementation of the node handler registry if
+ * an unknown node type is passed in.
+ */
+ public void testNodeHandlerRegistryLookupHandlerOtherNode()
+ {
+ NodeHandlerRegistryTestImpl reg = new NodeHandlerRegistryTestImpl();
+ handler.initNodeHandlerRegistry(reg);
+ assertNull("Got a handler", reg.subRegistry.lookupHandler(this, true));
+ }
+
+ /**
* A test flat node handler implementation. It is used mainly for checking
* the internal update flag.
*/
@@ -348,4 +403,37 @@
super.setInternalUpdate(node, f);
}
}
+
+ /**
+ * A specialized node handler registry implementation for testing whether
+ * the node handler correctly acts as a sub registry.
+ */
+ private static class NodeHandlerRegistryTestImpl implements
+ NodeHandlerRegistry
+ {
+ /** The registry passed to addSubRegistry(). */
+ NodeHandlerRegistry subRegistry;
+
+ /** The node passed to resolveHandler(). */
+ Object resolveNode;
+
+ /** The node handler to be returned by resolveHandler(). */
+ NodeHandler<?> resolveHandler;
+
+ public void addSubRegistry(NodeHandlerRegistry subreg)
+ {
+ subRegistry = subreg;
+ }
+
+ public NodeHandler<?> lookupHandler(Object node, boolean subClasses)
+ {
+ throw new UnsupportedOperationException("Not yet implemented!");
+ }
+
+ public NodeHandler<?> resolveHandler(Object node)
+ {
+ resolveNode = node;
+ return resolveHandler;
+ }
+ }
}