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/04 22:11:48 UTC
svn commit: r633645 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/expr/
test/java/org/apache/commons/configuration2/expr/
Author: oheger
Date: Tue Mar 4 13:11:46 2008
New Revision: 633645
URL: http://svn.apache.org/viewvc?rev=633645&view=rev
Log:
Added isDefined() method to NodeHandler interface.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java?rev=633645&r1=633644&r2=633645&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java Tue Mar 4 13:11:46 2008
@@ -220,4 +220,17 @@
{
node.removeChild(child);
}
+
+ /**
+ * Tests whether the passed in node is defined. This implementation checks
+ * whether the node has a value, any attributes or any children.
+ *
+ * @param node the node to test
+ * @return a flag whether this node is defined
+ */
+ public boolean isDefined(ConfigurationNode node)
+ {
+ return node.getValue() != null || !node.getAttributes().isEmpty()
+ || !node.getChildren().isEmpty();
+ }
}
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java?rev=633645&r1=633644&r2=633645&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java Tue Mar 4 13:11:46 2008
@@ -146,4 +146,14 @@
* @param name the name of the attribute to be removed
*/
void removeAttribute(T node, String name);
+
+ /**
+ * Checks whether the specified node is defined. Nodes are
+ * "defined" if they contain any data, e.g. a value, or
+ * attributes, or defined children.
+ *
+ * @param node the node to test
+ * @return a flag whether the passed in node is defined
+ */
+ boolean isDefined(T node);
}
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java?rev=633645&r1=633644&r2=633645&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java Tue Mar 4 13:11:46 2008
@@ -27,8 +27,8 @@
/**
* Test class for ConfigurationNodeHandler.
- *
- * @author hacker
+ *
+ * @author Oliver Heger
* @version $Id$
*/
public class TestConfigurationNodeHandler extends TestCase
@@ -51,7 +51,7 @@
/**
* Creates a mock for a configuration node.
- *
+ *
* @return the mock node
*/
private static ConfigurationNode mockNode()
@@ -272,6 +272,53 @@
EasyMock.expect(node.removeAttribute(NAME)).andReturn(Boolean.TRUE);
EasyMock.replay(node);
handler.removeAttribute(node, NAME);
+ EasyMock.verify(node);
+ }
+
+ /**
+ * Tests the isDefined() method when the node in question has a value.
+ */
+ public void testIsDefinedValue()
+ {
+ ConfigurationNode node = mockNode();
+ EasyMock.expect(node.getValue()).andReturn(VALUE);
+ EasyMock.replay(node);
+ assertTrue("Node not defined", handler.isDefined(node));
+ EasyMock.verify(node);
+ }
+
+ /**
+ * Tests the isDefined() method when the node in questions has an attribute.
+ */
+ public void testIsDefinedAttributes()
+ {
+ ConfigurationNode node = new DefaultConfigurationNode(NAME);
+ node.addAttribute(new DefaultConfigurationNode("attr", VALUE));
+ assertTrue("Node not defined", handler.isDefined(node));
+ }
+
+ /**
+ * Tests the isDefined() method when the node in question has children.
+ */
+ public void testIsDefinedChildren()
+ {
+ ConfigurationNode node = new DefaultConfigurationNode(NAME);
+ node.addChild(new DefaultConfigurationNode("child", VALUE));
+ assertTrue("Node not defined", handler.isDefined(node));
+ }
+
+ /**
+ * Tests the isDefined() method for an undefined node.
+ */
+ public void testIsDefinedEmpty()
+ {
+ ConfigurationNode node = mockNode();
+ EasyMock.expect(node.getValue()).andReturn(null);
+ List<ConfigurationNode> emptyList = new ArrayList<ConfigurationNode>();
+ EasyMock.expect(node.getAttributes()).andReturn(emptyList);
+ EasyMock.expect(node.getChildren()).andReturn(emptyList);
+ EasyMock.replay(node);
+ assertFalse("Node is defined", handler.isDefined(node));
EasyMock.verify(node);
}
}