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
32 private static final String NODE_NAME = "TestNodeName";
33
34
35
36
37
38
39
40 private static ImmutableNode createNode(final String name) {
41 return new ImmutableNode.Builder().name(name).create();
42 }
43
44
45 private NodeHandler<ImmutableNode> handler;
46
47
48
49
50
51
52 private void checkMatcherWithNullInput(final NodeMatcher<String> matcher) {
53 assertFalse(matcher.matches(createNode(NODE_NAME), handler, null));
54 assertFalse(matcher.matches(createNode(null), handler, NODE_NAME));
55 }
56
57 @BeforeEach
58 public void setUp() throws Exception {
59 final InMemoryNodeModel model = new InMemoryNodeModel();
60 handler = model.getNodeHandler();
61 }
62
63
64
65
66 @Test
67 void testEqualsIgnoreCaseMatch() {
68 final ImmutableNode node = createNode(NODE_NAME);
69 assertTrue(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, NODE_NAME));
70 assertTrue(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, StringUtils.toRootLowerCase(NODE_NAME)));
71 assertTrue(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, StringUtils.toRootUpperCase(NODE_NAME)));
72 }
73
74
75
76
77 @Test
78 void testEqualsIgnoreCaseNoMatch() {
79 final ImmutableNode node = createNode(NODE_NAME);
80 assertFalse(NodeNameMatchers.EQUALS_IGNORE_CASE.matches(node, handler, NODE_NAME + "_other"));
81 }
82
83
84
85
86 @Test
87 void testEqualsIgnoreCaseNullCriterion() {
88 checkMatcherWithNullInput(NodeNameMatchers.EQUALS_IGNORE_CASE);
89 }
90
91
92
93
94 @Test
95 void testEqualsMatch() {
96 final ImmutableNode node = createNode(NODE_NAME);
97 assertTrue(NodeNameMatchers.EQUALS.matches(node, handler, NODE_NAME));
98 }
99
100
101
102
103 @Test
104 void testEqualsNoMatch() {
105 final ImmutableNode node = createNode(NODE_NAME);
106 assertFalse(NodeNameMatchers.EQUALS.matches(node, handler, NODE_NAME + "_other"));
107 assertFalse(NodeNameMatchers.EQUALS.matches(node, handler, StringUtils.toRootLowerCase(NODE_NAME)));
108 }
109
110
111
112
113 @Test
114 void testEqualsNullCriterion() {
115 checkMatcherWithNullInput(NodeNameMatchers.EQUALS);
116 }
117 }