1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.model.reference

File EntityReferenceSetTest.java

 

Code metrics

0
140
35
1
410
281
35
0.25
4
35
1

Classes

Class Line # Actions
EntityReferenceSetTest 43 140 0% 35 2
0.988571498.9%
 

Contributing tests

This file is covered by 15 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Validate {@link EntityReferenceSet}.
37    *
38    * @version $Id: 6ebdad43794ed6070a9657b9170eb0ea4aa85283 $
39    */
40    @ComponentList({
41    DefaultSymbolScheme.class
42    })
 
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   
 
51  48 toggle private void assertMatches(EntityReference reference)
52    {
53  48 assertTrue(this.set.matches(reference));
54    }
55   
 
56  48 toggle private void assertNotMatches(EntityReference reference)
57    {
58  48 assertFalse(this.set.matches(reference));
59    }
60   
 
61  31 toggle private void assertMatches(String reference, EntityType type) throws Exception
62    {
63  31 assertMatches(this.resolverMocker.getComponentUnderTest().resolve(reference, type));
64    }
65   
 
66  38 toggle private void assertNotMatches(String reference, EntityType type) throws Exception
67    {
68  38 assertNotMatches(this.resolverMocker.getComponentUnderTest().resolve(reference, type));
69    }
70   
 
71  8 toggle private void assertMatchesWiki(String reference) throws Exception
72    {
73  8 assertMatches(reference, EntityType.WIKI);
74    }
75   
 
76  5 toggle private void assertNotMatchesWiki(String reference) throws Exception
77    {
78  5 assertNotMatches(reference, EntityType.WIKI);
79    }
80   
 
81  15 toggle private void assertMatchesSpace(String reference) throws Exception
82    {
83  15 assertMatches(reference, EntityType.SPACE);
84    }
85   
 
86  12 toggle private void assertNotMatchesSpace(String reference) throws Exception
87    {
88  12 assertNotMatches(reference, EntityType.SPACE);
89    }
90   
 
91  8 toggle private void assertMatchesDocument(String reference) throws Exception
92    {
93  8 assertMatches(reference, EntityType.DOCUMENT);
94    }
95   
 
96  21 toggle private void assertNotMatchesDocument(String reference) throws Exception
97    {
98  21 assertNotMatches(reference, EntityType.DOCUMENT);
99    }
100   
101    // Includes
102   
 
103  17 toggle private void includes(EntityReference reference)
104    {
105  17 this.set.includes(reference);
106    }
107   
 
108  13 toggle private void includes(String reference, EntityType type) throws Exception
109    {
110  13 includes(this.resolverMocker.getComponentUnderTest().resolve(reference, type));
111    }
112   
 
113  2 toggle private void includesWiki(String reference) throws Exception
114    {
115  2 includes(reference, EntityType.WIKI);
116    }
117   
 
118  5 toggle private void includesSpace(String reference) throws Exception
119    {
120  5 includes(reference, EntityType.SPACE);
121    }
122   
 
123  6 toggle private void includesDocument(String reference) throws Exception
124    {
125  6 includes(reference, EntityType.DOCUMENT);
126    }
127   
128    // Excludes
129   
 
130  6 toggle private void excludes(EntityReference reference)
131    {
132  6 this.set.excludes(reference);
133    }
134   
 
135  4 toggle private void excludes(String reference, EntityType type) throws Exception
136    {
137  4 excludes(this.resolverMocker.getComponentUnderTest().resolve(reference, type));
138    }
139   
 
140  1 toggle private void excludesWiki(String reference) throws Exception
141    {
142  1 excludes(reference, EntityType.WIKI);
143    }
144   
 
145  3 toggle private void excludesSpace(String reference) throws Exception
146    {
147  3 excludes(reference, EntityType.SPACE);
148    }
149   
 
150  0 toggle private void excludesDocument(String reference) throws Exception
151    {
152  0 excludes(reference, EntityType.DOCUMENT);
153    }
154   
155    // Tests
156   
 
157  1 toggle @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   
 
177  1 toggle @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   
 
196  1 toggle @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   
 
220  1 toggle @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   
 
232  1 toggle @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   
 
244  1 toggle @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   
 
263  1 toggle @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   
 
278  1 toggle @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   
 
294  1 toggle @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   
 
310  1 toggle @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   
 
330  1 toggle @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   
 
342  1 toggle @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   
 
357  1 toggle @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   
 
369  1 toggle @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   
 
389  1 toggle @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    }