-
-
Notifications
You must be signed in to change notification settings - Fork 973
/
BasicMarkerTest.java
210 lines (178 loc) · 7.1 KB
/
BasicMarkerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* Copyright (c) 2004-2011 QOS.ch
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.slf4j.basicTests;
import static org.junit.Assert.*;
import java.util.Iterator;
import org.junit.Test;
import org.slf4j.IMarkerFactory;
import org.slf4j.Marker;
import org.slf4j.helpers.BasicMarkerFactory;
/**
* Unit test BasicMarker
*
* @author Ceki Gülcü
* @author Joern Huxhorn
*/
public class BasicMarkerTest {
static final String BLUE_STR = "BLUE";
static final String RED_STR = "RED";
static final String GREEN_STR = "GREEN";
static final String COMP_STR = "COMP";
static final String MULTI_COMP_STR = "MULTI_COMP";
static final String PARENT_MARKER_STR = "PARENT_MARKER";
static final String CHILD_MARKER_STR = "CHILD_MARKER";
static final String NOT_CONTAINED_MARKER_STR = "NOT_CONTAINED";
final IMarkerFactory factory;
final Marker blue;
final Marker red;
final Marker green;
final Marker comp;
final Marker multiComp;
short diff = Differentiator.getDiffentiator();
public BasicMarkerTest() {
factory = new BasicMarkerFactory();
blue = factory.getMarker(BLUE_STR);
red = factory.getMarker(RED_STR);
green = factory.getMarker(GREEN_STR);
comp = factory.getMarker(COMP_STR);
comp.add(blue);
multiComp = factory.getMarker(MULTI_COMP_STR);
multiComp.add(green);
multiComp.add(comp);
}
@Test
public void testPrimitive() {
assertEquals(BLUE_STR, blue.getName());
assertTrue(blue.contains(blue));
Marker blue2 = factory.getMarker(BLUE_STR);
assertEquals(BLUE_STR, blue2.getName());
assertEquals(blue, blue2);
assertTrue(blue.contains(blue2));
assertTrue(blue2.contains(blue));
}
@Test
public void testPrimitiveByName() {
assertTrue(blue.contains(BLUE_STR));
}
@Test
public void testComposite() {
assertTrue(comp.contains(comp));
assertTrue(comp.contains(blue));
}
@Test
public void testCompositeByName() {
assertTrue(comp.contains(COMP_STR));
assertTrue(comp.contains(BLUE_STR));
}
@Test
public void testMultiComposite() {
assertTrue(multiComp.contains(comp));
assertTrue(multiComp.contains(blue));
assertTrue(multiComp.contains(green));
assertFalse(multiComp.contains(red));
}
@Test
public void testMultiCompositeByName() {
assertTrue(multiComp.contains(COMP_STR));
assertTrue(multiComp.contains(BLUE_STR));
assertTrue(multiComp.contains(GREEN_STR));
assertFalse(multiComp.contains(RED_STR));
}
@Test
public void testMultiAdd() {
Marker parent = factory.getMarker(PARENT_MARKER_STR);
Marker child = factory.getMarker(CHILD_MARKER_STR);
for (int i = 0; i < 10; i++) {
parent.add(child);
}
// check that the child was added once and only once
Iterator<Marker> iterator = parent.iterator();
assertTrue(iterator.hasNext());
assertEquals(CHILD_MARKER_STR, iterator.next().toString());
assertFalse(iterator.hasNext());
}
@Test
public void testAddRemove() {
final String NEW_PREFIX = "NEW_";
Marker parent = factory.getMarker(NEW_PREFIX + PARENT_MARKER_STR);
Marker child = factory.getMarker(NEW_PREFIX + CHILD_MARKER_STR);
assertFalse(parent.contains(child));
assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
assertFalse(parent.remove(child));
parent.add(child);
assertTrue(parent.contains(child));
assertTrue(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
assertTrue(parent.remove(child));
assertFalse(parent.contains(child));
assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
assertFalse(parent.remove(child));
}
@Test
public void testSelfRecursion() {
final String diffPrefix = "NEW_" + diff;
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
final String NOT_CONTAINED_NAME = diffPrefix + NOT_CONTAINED_MARKER_STR;
Marker parent = factory.getMarker(PARENT_NAME);
Marker notContained = factory.getMarker(NOT_CONTAINED_NAME);
parent.add(parent);
assertTrue(parent.contains(parent));
assertTrue(parent.contains(PARENT_NAME));
assertFalse(parent.contains(notContained));
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
}
@Test
public void testIndirectRecursion() {
final String diffPrefix = "NEW_" + diff;
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
final String CHILD_NAME = diffPrefix + CHILD_MARKER_STR;
final String NOT_CONTAINED_NAME = diffPrefix + NOT_CONTAINED_MARKER_STR;
Marker parent = factory.getMarker(PARENT_NAME);
Marker child = factory.getMarker(CHILD_NAME);
Marker notContained = factory.getMarker(NOT_CONTAINED_NAME);
parent.add(child);
child.add(parent);
assertTrue(parent.contains(parent));
assertTrue(parent.contains(child));
assertTrue(parent.contains(PARENT_NAME));
assertTrue(parent.contains(CHILD_NAME));
assertFalse(parent.contains(notContained));
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
}
@Test
public void testHomonyms() {
final String diffPrefix = "homonym" + diff;
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
final String CHILD_NAME = diffPrefix + CHILD_MARKER_STR;
Marker parent = factory.getMarker(PARENT_NAME);
Marker child = factory.getMarker(CHILD_NAME);
parent.add(child);
IMarkerFactory otherFactory = new BasicMarkerFactory();
Marker otherParent = otherFactory.getMarker(PARENT_NAME);
Marker otherChild = otherFactory.getMarker(CHILD_NAME);
assertTrue(parent.contains(otherParent));
assertTrue(parent.contains(otherChild));
assertTrue(parent.remove(otherChild));
}
}