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 2008/03/02 21:36:07 UTC
svn commit: r632838 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java
test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java
Author: oheger
Date: Sun Mar 2 12:36:06 2008
New Revision: 632838
URL: http://svn.apache.org/viewvc?rev=632838&view=rev
Log:
Adapter implementation of NodeVisitor plus test class
Added:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java (with props)
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java (with props)
Added: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java?rev=632838&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java Sun Mar 2 12:36:06 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.configuration2.expr;
+
+/**
+ * <p>
+ * A simple adapter class that simplifies writing custom node visitor
+ * implementations.
+ * </p>
+ * <p>
+ * This class provides dummy implementations for the methods defined in the
+ * <code>ConfigurationNodeVisitor</code> interface. Derived classes only need
+ * to override the methods they really need.
+ * </p>
+ *
+ * @author Oliver Heger
+ * @version $Id$
+ * @param <T> the type of the involved nodes
+ */
+public class NodeVisitorAdapter<T> implements NodeVisitor<T>
+{
+ /**
+ * Checks whether the visiting process should be aborted. This base
+ * implementation always returns <b>false</b>
+ *
+ * @return a flag whether the visiting process should be aborted
+ */
+ public boolean terminate()
+ {
+ return false;
+ }
+
+ /**
+ * Visits the specified node after its children have been processed. This is
+ * an empty dummy implementation.
+ *
+ * @param node the node
+ * @param handler the node handler
+ */
+ public void visitAfterChildren(T node, NodeHandler<T> handler)
+ {
+ }
+
+ /**
+ * Visits the specified node before its children are processed. This is an
+ * empty dummy implementation.
+ *
+ * @param node the node
+ * @param handler the node handler
+ */
+ public void visitBeforeChildren(T node, NodeHandler<T> handler)
+ {
+ }
+}
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeVisitorAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java?rev=632838&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java Sun Mar 2 12:36:06 2008
@@ -0,0 +1,116 @@
+/*
+ * 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.configuration2.expr;
+
+import org.apache.commons.configuration2.tree.ConfigurationNode;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for NodeVisitorAdapter.
+ *
+ * @author Oliver Heger
+ * @version $Id$
+ */
+public class TestNodeVisitorAdapter extends TestCase
+{
+ /** The adapter to be tested. */
+ private NodeVisitorAdapter<ConfigurationNode> adapter;
+
+ /** Stores the mock node handler. */
+ private NodeHandler<ConfigurationNode> handler;
+
+ /** Stores the mock for the configuration node. */
+ private ConfigurationNode node;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ adapter = new NodeVisitorAdapter<ConfigurationNode>();
+ handler = EasyMock.createMock(NodeHandler.class);
+ }
+
+ /**
+ * Returns a mock configuration node.
+ *
+ * @return the mock node
+ */
+ private ConfigurationNode mockNode()
+ {
+ node = EasyMock.createMock(ConfigurationNode.class);
+ return node;
+ }
+
+ /**
+ * Replays the involved mock objects.
+ */
+ private void replayMocks()
+ {
+ EasyMock.replay(handler);
+ if (node != null)
+ {
+ EasyMock.replay(node);
+ }
+ }
+
+ /**
+ * Verifies the involved mock objects.
+ */
+ private void verifyMocks()
+ {
+ EasyMock.verify(handler);
+ if (node != null)
+ {
+ EasyMock.verify(node);
+ }
+ }
+
+ /**
+ * Tests the terminate() implementation.
+ */
+ public void testTerminate()
+ {
+ assertFalse("Should terminate", adapter.terminate());
+ }
+
+ /**
+ * Tests the visitBeforeChildren() implementation. We only test whether the
+ * passed in objects are not touched.
+ */
+ public void testVisitBeforeChildren()
+ {
+ ConfigurationNode nd = mockNode();
+ replayMocks();
+ adapter.visitBeforeChildren(nd, handler);
+ verifyMocks();
+ }
+
+ /**
+ * Tests the visitAfterChildren() implementation. We only test whether the
+ * passed in objects are not touched.
+ */
+ public void testVisitAfterChildren()
+ {
+ ConfigurationNode nd = mockNode();
+ replayMocks();
+ adapter.visitAfterChildren(nd, handler);
+ verifyMocks();
+ }
+}
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestNodeVisitorAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain