1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.model.reference; |
21 |
|
|
22 |
|
import java.util.Locale; |
23 |
|
|
24 |
|
import org.junit.Rule; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.model.EntityType; |
27 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
28 |
|
import org.xwiki.model.internal.reference.RelativeStringEntityReferenceResolver; |
29 |
|
import org.xwiki.test.annotation.ComponentList; |
30 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
31 |
|
|
32 |
|
import static org.junit.Assert.assertFalse; |
33 |
|
import static org.junit.Assert.assertTrue; |
34 |
|
|
35 |
|
|
36 |
|
@link |
37 |
|
|
38 |
|
@version |
39 |
|
|
40 |
|
@ComponentList({ |
41 |
|
DefaultSymbolScheme.class |
42 |
|
}) |
|
|
| 98.9% |
Uncovered Elements: 2 (175) |
Complexity: 35 |
Complexity Density: 0.25 |
|
43 |
|
public class EntityReferenceSetTest |
44 |
|
{ |
45 |
|
@Rule |
46 |
|
public MockitoComponentMockingRule<RelativeStringEntityReferenceResolver> resolverMocker = |
47 |
|
new MockitoComponentMockingRule<>(RelativeStringEntityReferenceResolver.class); |
48 |
|
|
49 |
|
private EntityReferenceSet set = new EntityReferenceSet(); |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
48 |
private void assertMatches(EntityReference reference)... |
52 |
|
{ |
53 |
48 |
assertTrue(this.set.matches(reference)); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
48 |
private void assertNotMatches(EntityReference reference)... |
57 |
|
{ |
58 |
48 |
assertFalse(this.set.matches(reference)); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
31 |
private void assertMatches(String reference, EntityType type) throws Exception... |
62 |
|
{ |
63 |
31 |
assertMatches(this.resolverMocker.getComponentUnderTest().resolve(reference, type)); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
38 |
private void assertNotMatches(String reference, EntityType type) throws Exception... |
67 |
|
{ |
68 |
38 |
assertNotMatches(this.resolverMocker.getComponentUnderTest().resolve(reference, type)); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
8 |
private void assertMatchesWiki(String reference) throws Exception... |
72 |
|
{ |
73 |
8 |
assertMatches(reference, EntityType.WIKI); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
5 |
private void assertNotMatchesWiki(String reference) throws Exception... |
77 |
|
{ |
78 |
5 |
assertNotMatches(reference, EntityType.WIKI); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
15 |
private void assertMatchesSpace(String reference) throws Exception... |
82 |
|
{ |
83 |
15 |
assertMatches(reference, EntityType.SPACE); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
12 |
private void assertNotMatchesSpace(String reference) throws Exception... |
87 |
|
{ |
88 |
12 |
assertNotMatches(reference, EntityType.SPACE); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
8 |
private void assertMatchesDocument(String reference) throws Exception... |
92 |
|
{ |
93 |
8 |
assertMatches(reference, EntityType.DOCUMENT); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
21 |
private void assertNotMatchesDocument(String reference) throws Exception... |
97 |
|
{ |
98 |
21 |
assertNotMatches(reference, EntityType.DOCUMENT); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
17 |
private void includes(EntityReference reference)... |
104 |
|
{ |
105 |
17 |
this.set.includes(reference); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
13 |
private void includes(String reference, EntityType type) throws Exception... |
109 |
|
{ |
110 |
13 |
includes(this.resolverMocker.getComponentUnderTest().resolve(reference, type)); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
2 |
private void includesWiki(String reference) throws Exception... |
114 |
|
{ |
115 |
2 |
includes(reference, EntityType.WIKI); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
5 |
private void includesSpace(String reference) throws Exception... |
119 |
|
{ |
120 |
5 |
includes(reference, EntityType.SPACE); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
6 |
private void includesDocument(String reference) throws Exception... |
124 |
|
{ |
125 |
6 |
includes(reference, EntityType.DOCUMENT); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
6 |
private void excludes(EntityReference reference)... |
131 |
|
{ |
132 |
6 |
this.set.excludes(reference); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
4 |
private void excludes(String reference, EntityType type) throws Exception... |
136 |
|
{ |
137 |
4 |
excludes(this.resolverMocker.getComponentUnderTest().resolve(reference, type)); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
1 |
private void excludesWiki(String reference) throws Exception... |
141 |
|
{ |
142 |
1 |
excludes(reference, EntityType.WIKI); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
3 |
private void excludesSpace(String reference) throws Exception... |
146 |
|
{ |
147 |
3 |
excludes(reference, EntityType.SPACE); |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
private void excludesDocument(String reference) throws Exception... |
151 |
|
{ |
152 |
0 |
excludes(reference, EntityType.DOCUMENT); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void includeWiki() throws Exception |
159 |
|
{ |
160 |
1 |
includesWiki("wiki"); |
161 |
|
|
162 |
1 |
assertMatchesWiki("wiki"); |
163 |
1 |
assertNotMatchesWiki("notwiki"); |
164 |
|
|
165 |
1 |
assertMatchesSpace("wiki:space"); |
166 |
1 |
assertNotMatchesSpace("notwiki:space"); |
167 |
|
|
168 |
1 |
includesWiki("otherwiki"); |
169 |
|
|
170 |
1 |
assertMatchesWiki("wiki"); |
171 |
|
|
172 |
1 |
assertMatchesWiki("otherwiki"); |
173 |
|
|
174 |
1 |
assertNotMatchesWiki("notwiki"); |
175 |
|
} |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
177 |
1 |
@Test... |
178 |
|
public void includeSpace() throws Exception |
179 |
|
{ |
180 |
1 |
includesSpace("wiki:space"); |
181 |
|
|
182 |
1 |
assertMatchesSpace("wiki:space"); |
183 |
|
|
184 |
1 |
assertNotMatchesSpace("notwiki:space"); |
185 |
1 |
assertNotMatchesSpace("wiki:notspace"); |
186 |
|
|
187 |
1 |
includesSpace("wiki:otherspace"); |
188 |
|
|
189 |
1 |
assertMatchesSpace("wiki:space"); |
190 |
|
|
191 |
1 |
assertMatchesSpace("wiki:otherspace"); |
192 |
|
|
193 |
1 |
assertNotMatchesSpace("wiki:notspace"); |
194 |
|
} |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
196 |
1 |
@Test... |
197 |
|
public void includeNestedSpace() throws Exception |
198 |
|
{ |
199 |
1 |
includesSpace("wiki:space.nested"); |
200 |
|
|
201 |
1 |
assertMatchesSpace("wiki:space"); |
202 |
|
|
203 |
1 |
assertMatchesSpace("wiki:space.nested"); |
204 |
1 |
assertMatchesDocument("wiki:space.nested.document"); |
205 |
|
|
206 |
1 |
assertNotMatchesSpace("notwiki:space"); |
207 |
1 |
assertNotMatchesSpace("wiki:notspace"); |
208 |
1 |
assertNotMatchesSpace("wiki:space.notnested"); |
209 |
1 |
assertNotMatchesDocument("wiki:space.document"); |
210 |
|
|
211 |
1 |
includesSpace("wiki:otherspace"); |
212 |
|
|
213 |
1 |
assertMatchesSpace("wiki:space"); |
214 |
|
|
215 |
1 |
assertMatchesSpace("wiki:otherspace"); |
216 |
|
|
217 |
1 |
assertNotMatchesSpace("wiki:notspace"); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
220 |
1 |
@Test... |
221 |
|
public void includePartialOnlySpace() throws Exception |
222 |
|
{ |
223 |
1 |
includesSpace("space"); |
224 |
|
|
225 |
1 |
assertMatchesSpace("wiki:space"); |
226 |
1 |
assertMatchesSpace("space"); |
227 |
|
|
228 |
1 |
assertNotMatchesSpace("wiki:notspace"); |
229 |
1 |
assertNotMatchesSpace("notspace"); |
230 |
|
} |
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
232 |
1 |
@Test... |
233 |
|
public void includeDocument() throws Exception |
234 |
|
{ |
235 |
1 |
includesDocument("wiki:space.document"); |
236 |
|
|
237 |
1 |
assertMatchesDocument("wiki:space.document"); |
238 |
|
|
239 |
1 |
assertNotMatchesDocument("notwiki:space.document"); |
240 |
1 |
assertNotMatchesDocument("wiki:notspace.document"); |
241 |
1 |
assertNotMatchesDocument("wiki:space.notdocument"); |
242 |
|
} |
243 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
244 |
1 |
@Test... |
245 |
|
public void includeLocalDocumentLocale() |
246 |
|
{ |
247 |
1 |
includes(new LocalDocumentReference("space", "document", Locale.ROOT)); |
248 |
|
|
249 |
1 |
assertMatches(new LocalDocumentReference("space", "document")); |
250 |
1 |
assertMatches(new LocalDocumentReference("space", "document", Locale.ROOT)); |
251 |
|
|
252 |
1 |
assertNotMatches(new LocalDocumentReference("space", "document", Locale.FRENCH)); |
253 |
|
|
254 |
1 |
includes(new LocalDocumentReference("space", "document", Locale.ENGLISH)); |
255 |
|
|
256 |
1 |
assertMatches(new LocalDocumentReference("space", "document")); |
257 |
1 |
assertMatches(new LocalDocumentReference("space", "document", Locale.ROOT)); |
258 |
1 |
assertMatches(new LocalDocumentReference("space", "document", Locale.ENGLISH)); |
259 |
|
|
260 |
1 |
assertNotMatches(new LocalDocumentReference("space", "document", Locale.FRENCH)); |
261 |
|
} |
262 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
263 |
1 |
@Test... |
264 |
|
public void includeDocumentInNestedSpace() throws Exception |
265 |
|
{ |
266 |
1 |
includesDocument("wiki:space.nestedspace.document"); |
267 |
|
|
268 |
1 |
assertMatchesDocument("wiki:space.nestedspace.document"); |
269 |
|
|
270 |
1 |
assertNotMatchesDocument("wiki:space.othernestedspace.document"); |
271 |
1 |
assertNotMatchesDocument("wiki:space.document"); |
272 |
1 |
assertNotMatchesDocument("notwiki:space.nestedspace.document"); |
273 |
1 |
assertNotMatchesDocument("wiki:notspace.nestedspace.document"); |
274 |
1 |
assertNotMatchesDocument("wiki:space.nestedspace.notdocument"); |
275 |
1 |
assertNotMatchesDocument("wiki:space.nestedspace.othernestedspace.document"); |
276 |
|
} |
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
278 |
1 |
@Test... |
279 |
|
public void includeDocumentsInNestedSpacesWithShortAfterLong() throws Exception |
280 |
|
{ |
281 |
1 |
includesDocument("wiki:space.nestedspace.document"); |
282 |
1 |
includesDocument("wiki:space.document"); |
283 |
|
|
284 |
1 |
assertMatchesDocument("wiki:space.document"); |
285 |
1 |
assertMatchesDocument("wiki:space.nestedspace.document"); |
286 |
|
|
287 |
1 |
assertNotMatchesDocument("wiki:space.othernestedspace.document"); |
288 |
1 |
assertNotMatchesDocument("notwiki:space.nestedspace.document"); |
289 |
1 |
assertNotMatchesDocument("wiki:notspace.nestedspace.document"); |
290 |
1 |
assertNotMatchesDocument("wiki:space.nestedspace.notdocument"); |
291 |
1 |
assertNotMatchesDocument("wiki:space.nestedspace.othernestedspace.document"); |
292 |
|
} |
293 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
294 |
1 |
@Test... |
295 |
|
public void includeDocumentsInNestedSpacesWithLongAfterShort() throws Exception |
296 |
|
{ |
297 |
1 |
includesDocument("wiki:space.document"); |
298 |
1 |
includesDocument("wiki:space.nestedspace.document"); |
299 |
|
|
300 |
1 |
assertMatchesDocument("wiki:space.document"); |
301 |
1 |
assertMatchesDocument("wiki:space.nestedspace.document"); |
302 |
|
|
303 |
1 |
assertNotMatchesDocument("wiki:space.othernestedspace.document"); |
304 |
1 |
assertNotMatchesDocument("notwiki:space.nestedspace.document"); |
305 |
1 |
assertNotMatchesDocument("wiki:notspace.nestedspace.document"); |
306 |
1 |
assertNotMatchesDocument("wiki:space.nestedspace.notdocument"); |
307 |
1 |
assertNotMatchesDocument("wiki:space.nestedspace.othernestedspace.document"); |
308 |
|
} |
309 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
310 |
1 |
@Test... |
311 |
|
public void excludeWiki() throws Exception |
312 |
|
{ |
313 |
1 |
excludesWiki("wiki"); |
314 |
|
|
315 |
1 |
assertNotMatchesWiki("wiki"); |
316 |
|
|
317 |
1 |
assertMatchesWiki("otherwiki"); |
318 |
|
|
319 |
1 |
assertMatchesWiki("notwiki"); |
320 |
|
|
321 |
1 |
set.excludes(new EntityReference("otherwiki", EntityType.WIKI)); |
322 |
|
|
323 |
1 |
assertNotMatchesWiki("wiki"); |
324 |
|
|
325 |
1 |
assertNotMatchesWiki("otherwiki"); |
326 |
|
|
327 |
1 |
assertMatchesWiki("notwiki"); |
328 |
|
} |
329 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
330 |
1 |
@Test... |
331 |
|
public void excludeSpace() throws Exception |
332 |
|
{ |
333 |
1 |
excludesSpace("wiki:space"); |
334 |
|
|
335 |
1 |
assertNotMatchesSpace("wiki:space"); |
336 |
|
|
337 |
1 |
assertMatchesWiki("wiki"); |
338 |
1 |
assertMatchesSpace("otherwiki:space"); |
339 |
1 |
assertMatchesSpace("wiki:otherspace"); |
340 |
|
} |
341 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
342 |
1 |
@Test... |
343 |
|
public void excludeNestedSpace() throws Exception |
344 |
|
{ |
345 |
1 |
excludesSpace("wiki:space.nested"); |
346 |
|
|
347 |
1 |
assertNotMatchesSpace("wiki:space.nested"); |
348 |
1 |
assertNotMatchesDocument("wiki:space.nested.page"); |
349 |
|
|
350 |
1 |
assertMatchesDocument("wiki:space.page"); |
351 |
1 |
assertMatchesSpace("wiki:space"); |
352 |
1 |
assertMatchesWiki("wiki"); |
353 |
1 |
assertMatchesSpace("otherwiki:space"); |
354 |
1 |
assertMatchesSpace("wiki:otherspace"); |
355 |
|
} |
356 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
357 |
1 |
@Test... |
358 |
|
public void excludePartial() throws Exception |
359 |
|
{ |
360 |
1 |
excludesSpace("space"); |
361 |
|
|
362 |
1 |
assertNotMatches(new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))); |
363 |
1 |
assertNotMatches(new EntityReference("space", EntityType.SPACE)); |
364 |
|
|
365 |
1 |
assertMatches(new EntityReference("notspace", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))); |
366 |
1 |
assertMatches(new EntityReference("notspace", EntityType.SPACE)); |
367 |
|
} |
368 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
369 |
1 |
@Test... |
370 |
|
public void includeLocale() |
371 |
|
{ |
372 |
1 |
includes(new DocumentReference("wiki", "space", "document", Locale.ENGLISH)); |
373 |
|
|
374 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document")); |
375 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document", Locale.ENGLISH)); |
376 |
|
|
377 |
1 |
assertNotMatches(new DocumentReference("wiki", "space", "document", Locale.FRENCH)); |
378 |
1 |
assertNotMatches(new DocumentReference("wiki", "space", "document", Locale.ROOT)); |
379 |
|
|
380 |
1 |
includes(new DocumentReference("wiki", "space", "document", Locale.FRENCH)); |
381 |
|
|
382 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document")); |
383 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document", Locale.ENGLISH)); |
384 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document", Locale.FRENCH)); |
385 |
|
|
386 |
1 |
assertNotMatches(new DocumentReference("wiki", "space", "document", Locale.ROOT)); |
387 |
|
} |
388 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
389 |
1 |
@Test... |
390 |
|
public void excludeLocale() |
391 |
|
{ |
392 |
1 |
excludes(new DocumentReference("wiki", "space", "document", Locale.ENGLISH)); |
393 |
|
|
394 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document")); |
395 |
|
|
396 |
1 |
assertNotMatches(new DocumentReference("wiki", "space", "document", Locale.ENGLISH)); |
397 |
|
|
398 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document", Locale.FRENCH)); |
399 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document", Locale.ROOT)); |
400 |
|
|
401 |
1 |
excludes(new DocumentReference("wiki", "space", "document", Locale.FRENCH)); |
402 |
|
|
403 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document")); |
404 |
|
|
405 |
1 |
assertNotMatches(new DocumentReference("wiki", "space", "document", Locale.ENGLISH)); |
406 |
1 |
assertNotMatches(new DocumentReference("wiki", "space", "document", Locale.FRENCH)); |
407 |
|
|
408 |
1 |
assertMatches(new DocumentReference("wiki", "space", "document", Locale.ROOT)); |
409 |
|
} |
410 |
|
} |