1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration2.tree;
18
19 import static org.junit.jupiter.api.Assertions.assertFalse;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import org.apache.commons.lang3.StringUtils;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26
27
28
29 public class TestNodeNameMatchers {
30
31 private static final String NODE_NAME = "TestNodeName";
32
33
34
35
36
37
38
39 private static ImmutableNode createNode(final String name) {
40 return new ImmutableNode.Builder().name(name).create();
41 }
42
43
44 private NodeHandler<ImmutableNode> handler;
45
46
47
48
49
50
51 private void checkMatcherWithNullInput(final NodeMatcher<String> matcher) {
52 assertFalse(matcher.matches(createNode(NODE_NAME), handler, null));
53 assertFalse(matcher.matches(createNode(null), handler, NODE_NAME));
54 }
55
56 @BeforeEach
57 public void setUp() throws Exception {
58 final InMemoryNodeModel model = new InMemoryNodeModel();
59 handler = model.getNodeHandler();
60 }
61
62
63
64
65 @Test
66 void testEqualsIgnoreCaseMatch() {
67 final ImmutableNode node = createNode(NODE_NAME);
68 assertTrue(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, NODE_NAME));
69 assertTrue(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, StringUtils.toRootLowerCase(NODE_NAME)));
70 assertTrue(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, StringUtils.toRootUpperCase(NODE_NAME)));
71 }
72
73
74
75
76 @Test
77 void testEqualsIgnoreCaseNoMatch() {
78 final ImmutableNode node = createNode(NODE_NAME);
79 assertFalse(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, NODE_NAME + "_other"));
80 }
81
82
83
84
85 @Test
86 void testEqualsIgnoreCaseNullCriterion() {
87 checkMatcherWithNullInput(NodeNameMatchers.EQUALS_IGNORE_CASE);
88 }
89
90
91
92
93 @Test
94 void testEqualsMatch() {
95 final ImmutableNode node = createNode(NODE_NAME);
96 assertTrue(NodeNameMatchers.EQUALS.matches(node, handler, NODE_NAME));
97 }
98
99
100
101
102 @Test
103 void testEqualsNoMatch() {
104 final ImmutableNode node = createNode(NODE_NAME);
105 assertFalse(NodeNameMatchers.EQUALS.matches(node, handler, NODE_NAME + "_other"));
106 assertFalse(NodeNameMatchers.EQUALS.matches(node, handler, StringUtils.toRootLowerCase(NODE_NAME)));
107 }
108
109
110
111
112 @Test
113 void testEqualsNullCriterion() {
114 checkMatcherWithNullInput(NodeNameMatchers.EQUALS);
115 }
116 }