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 2014/11/01 21:51:45 UTC
svn commit: r1636041 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration2/tree/NodeNameMatchers.java
test/java/org/apache/commons/configuration2/tree/TestNodeNameMatchers.java
Author: oheger
Date: Sat Nov 1 20:51:45 2014
New Revision: 1636041
URL: http://svn.apache.org/r1636041
Log:
Added a node name matcher which ignores case.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/tree/NodeNameMatchers.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestNodeNameMatchers.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/tree/NodeNameMatchers.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/tree/NodeNameMatchers.java?rev=1636041&r1=1636040&r2=1636041&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/tree/NodeNameMatchers.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/tree/NodeNameMatchers.java Sat Nov 1 20:51:45 2014
@@ -48,5 +48,20 @@ public enum NodeNameMatchers implements
{
return StringUtils.equals(criterion, handler.nodeName(node));
}
+ },
+
+ /**
+ * A matcher for matches on node names which ignores case. For this matcher
+ * the names {@code node}, {@code NODE}, or {@code NodE} are all the same.
+ */
+ EQUALS_IGNORE_CASE
+ {
+ @Override
+ public <T> boolean matches(T node, NodeHandler<T> handler,
+ String criterion)
+ {
+ return StringUtils.equalsIgnoreCase(criterion,
+ handler.nodeName(node));
+ }
}
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestNodeNameMatchers.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestNodeNameMatchers.java?rev=1636041&r1=1636040&r2=1636041&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestNodeNameMatchers.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestNodeNameMatchers.java Sat Nov 1 20:51:45 2014
@@ -84,15 +84,59 @@ public class TestNodeNameMatchers
}
/**
+ * Tests whether a matcher can handle null input safely.
+ *
+ * @param matcher the matcher to be tested
+ */
+ private void checkMatcherWithNullInput(NodeMatcher<String> matcher)
+ {
+ assertFalse("Match (1)",
+ matcher.matches(createNode(NODE_NAME), handler, null));
+ assertFalse("Match (2)",
+ matcher.matches(createNode(null), handler, NODE_NAME));
+ }
+
+ /**
* Tests whether the equals matcher can handle a null criterion.
*/
@Test
public void testEqualsNullCriterion()
{
+ checkMatcherWithNullInput(NodeNameMatchers.EQUALS);
+ }
+
+ /**
+ * Tests the equalsIgnoreCase mather if the expected result is true.
+ */
+ @Test
+ public void testEqualsIgnoreCaseMatch()
+ {
ImmutableNode node = createNode(NODE_NAME);
- assertFalse("Match (1)",
- NodeNameMatchers.EQUALS.matches(node, handler, null));
- assertFalse("Match (2)", NodeNameMatchers.EQUALS.matches(
- createNode(null), handler, NODE_NAME));
+ assertTrue("No match (1)", NodeNameMatchers.EQUALS_IGNORE_CASE.matches(
+ node, handler, NODE_NAME));
+ assertTrue("No match (2)", NodeNameMatchers.EQUALS_IGNORE_CASE.matches(
+ node, handler, NODE_NAME.toLowerCase(Locale.ENGLISH)));
+ assertTrue("No match (3)", NodeNameMatchers.EQUALS_IGNORE_CASE.matches(
+ node, handler, NODE_NAME.toUpperCase(Locale.ENGLISH)));
+ }
+
+ /**
+ * Tests the equalsIgnoreCase matcher if the expected result is false.
+ */
+ @Test
+ public void testEqualsIgnoreCaseNoMatch()
+ {
+ ImmutableNode node = createNode(NODE_NAME);
+ assertFalse("Match", NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node,
+ handler, NODE_NAME + "_other"));
+ }
+
+ /**
+ * Tests whether the equalsIgnoreCase matcher is null-safe.
+ */
+ @Test
+ public void testEqualsIgnoreCaseNullCriterion()
+ {
+ checkMatcherWithNullInput(NodeNameMatchers.EQUALS_IGNORE_CASE);
}
}