1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration2.event;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertSame;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.Set;
27
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 public class TestConfigurationEventTypes {
34
35
36
37
38
39 private void checkErrorEvent(final EventType<ConfigurationErrorEvent> type) {
40 assertSame(ConfigurationErrorEvent.ANY, type.getSuperType(), "Wrong super type for " + type);
41 }
42
43
44
45
46
47
48 private void checkHierarchicalEvent(final EventType<ConfigurationEvent> eventType) {
49 assertSame(ConfigurationEvent.ANY_HIERARCHICAL, eventType.getSuperType(), "Wrong super type for " + eventType);
50 }
51
52
53
54
55
56
57 private void checkUpdateEvent(final EventType<ConfigurationEvent> eventType) {
58 assertSame(ConfigurationEvent.ANY, eventType.getSuperType(), "Wrong super type for " + eventType);
59 }
60
61
62
63
64 @Test
65 public void testAddNodesEventType() {
66 checkHierarchicalEvent(ConfigurationEvent.ADD_NODES);
67 }
68
69
70
71
72 @Test
73 public void testAddPropertyEventType() {
74 checkUpdateEvent(ConfigurationEvent.ADD_PROPERTY);
75 }
76
77
78
79
80 @Test
81 public void testBaseErrorEventType() {
82 assertEquals(Event.ANY, ConfigurationErrorEvent.ANY.getSuperType());
83 }
84
85
86
87
88 @Test
89 public void testClearEventType() {
90 checkUpdateEvent(ConfigurationEvent.CLEAR);
91 }
92
93
94
95
96 @Test
97 public void testClearPropertyEventType() {
98 checkUpdateEvent(ConfigurationEvent.CLEAR_PROPERTY);
99 }
100
101
102
103
104 @Test
105 public void testClearTreeEventType() {
106 checkHierarchicalEvent(ConfigurationEvent.CLEAR_TREE);
107 }
108
109
110
111
112 @Test
113 public void testConfigurationEventType() {
114 assertSame(Event.ANY, ConfigurationEvent.ANY.getSuperType());
115 }
116
117
118
119
120 @Test
121 public void testFetchSuperEventTypesForBaseType() {
122 final Set<EventType<?>> superTypes = EventType.fetchSuperEventTypes(Event.ANY);
123 assertEquals(Collections.singleton(Event.ANY), superTypes);
124 }
125
126
127
128
129 @Test
130 public void testFetchSuperEventTypesNull() {
131 final Set<EventType<?>> superTypes = EventType.fetchSuperEventTypes(null);
132 assertTrue(superTypes.isEmpty());
133 }
134
135
136
137
138 @Test
139 public void testFetchSuperEventTypesOfType() {
140 final Set<EventType<?>> superTypes = EventType.fetchSuperEventTypes(ConfigurationEvent.ADD_NODES);
141 final Set<EventType<? extends Event>> expected = new HashSet<>();
142 expected.add(ConfigurationEvent.ADD_NODES);
143 expected.add(ConfigurationEvent.ANY_HIERARCHICAL);
144 expected.add(ConfigurationEvent.ANY);
145 expected.add(Event.ANY);
146 assertEquals(expected, superTypes);
147 }
148
149
150
151
152 @Test
153 public void testHierarchicalEventType() {
154 checkUpdateEvent(ConfigurationEvent.ANY_HIERARCHICAL);
155 }
156
157
158
159
160 @Test
161 public void testIsInstanceOfBaseNull() {
162 assertFalse(EventType.isInstanceOf(ConfigurationEvent.ANY, null));
163 }
164
165
166
167
168 @Test
169 public void testIsInstanceOfDerivedNull() {
170 assertFalse(EventType.isInstanceOf(null, Event.ANY));
171 }
172
173
174
175
176 @Test
177 public void testIsInstanceOfFalse() {
178 assertFalse(EventType.isInstanceOf(ConfigurationErrorEvent.READ, ConfigurationEvent.ANY));
179 }
180
181
182
183
184 @Test
185 public void testIsInstanceOfTrue() {
186 assertTrue(EventType.isInstanceOf(ConfigurationEvent.ADD_NODES, ConfigurationEvent.ANY_HIERARCHICAL));
187 assertTrue(EventType.isInstanceOf(ConfigurationEvent.ADD_NODES, ConfigurationEvent.ANY));
188 assertTrue(EventType.isInstanceOf(ConfigurationEvent.ADD_NODES, Event.ANY));
189 assertTrue(EventType.isInstanceOf(ConfigurationEvent.ADD_NODES, ConfigurationEvent.ADD_NODES));
190 }
191
192
193
194
195 @Test
196 public void testReadErrorEventType() {
197 checkErrorEvent(ConfigurationErrorEvent.READ);
198 }
199
200
201
202
203 @Test
204 public void testSetPropertyEventType() {
205 checkUpdateEvent(ConfigurationEvent.SET_PROPERTY);
206 }
207
208
209
210
211 @Test
212 public void testSubnodeChangedEventType() {
213 checkHierarchicalEvent(ConfigurationEvent.SUBNODE_CHANGED);
214 }
215
216
217
218
219 @Test
220 public void testWriteErrorEventType() {
221 checkErrorEvent(ConfigurationErrorEvent.WRITE);
222 }
223 }