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

File RegexEntityReferenceTest.java

 

Code metrics

0
14
6
1
100
60
6
0.43
2.33
6
1

Classes

Class Line # Actions
RegexEntityReferenceTest 36 14 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 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.regex.Pattern;
23   
24    import org.junit.Assert;
25   
26    import org.junit.Test;
27    import org.xwiki.model.EntityType;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30   
31    /**
32    * Validate {@link RegexEntityReference} class.
33    *
34    * @version $Id: e34a4fdb2f5fbbdc180e533da39b3b9e4e6a2139 $
35    */
 
36    public class RegexEntityReferenceTest
37    {
38    private static final DocumentReference REFERENCETOMATCH = new DocumentReference("wiki", "space", "page");
39   
 
40  1 toggle @Test
41    public void testExact()
42    {
43  1 EntityReference wikiReference =
44    new RegexEntityReference(Pattern.compile(REFERENCETOMATCH.getWikiReference().getName(), Pattern.LITERAL),
45    EntityType.WIKI);
46  1 EntityReference spaceReference =
47    new RegexEntityReference(Pattern.compile(REFERENCETOMATCH.getLastSpaceReference().getName(),
48    Pattern.LITERAL), EntityType.SPACE, wikiReference);
49  1 EntityReference reference =
50    new RegexEntityReference(Pattern.compile(REFERENCETOMATCH.getName(), Pattern.LITERAL), EntityType.DOCUMENT,
51    spaceReference);
52   
53  1 Assert.assertTrue(reference.equals(REFERENCETOMATCH));
54    }
55   
 
56  1 toggle @Test
57    public void testWithOnlyPage()
58    {
59  1 EntityReference reference =
60    new RegexEntityReference(Pattern.compile(REFERENCETOMATCH.getName(), Pattern.LITERAL), EntityType.DOCUMENT);
61   
62  1 Assert.assertTrue(reference.equals(REFERENCETOMATCH));
63    }
64   
 
65  1 toggle @Test
66    public void testWithOnlyWiki()
67    {
68  1 EntityReference reference =
69    new RegexEntityReference(Pattern.compile(REFERENCETOMATCH.getWikiReference().getName(), Pattern.LITERAL),
70    EntityType.WIKI);
71   
72  1 Assert.assertTrue(reference.equals(REFERENCETOMATCH));
73    }
74   
 
75  1 toggle @Test
76    public void testPattern()
77    {
78  1 EntityReference reference = new RegexEntityReference(Pattern.compile("p.*"), EntityType.DOCUMENT);
79   
80  1 Assert.assertTrue(reference.equals(REFERENCETOMATCH));
81    }
82   
 
83  1 toggle @Test
84    public void testPatternNotMatching()
85    {
86  1 EntityReference reference = new RegexEntityReference(Pattern.compile("space"), EntityType.DOCUMENT);
87   
88  1 Assert.assertFalse(reference.equals(REFERENCETOMATCH));
89    }
90   
 
91  1 toggle @Test
92    public void testWithNonRegexParent()
93    {
94  1 EntityReference reference =
95    new RegexEntityReference(Pattern.compile("space"), EntityType.SPACE, new EntityReference("wiki",
96    EntityType.WIKI));
97   
98  1 Assert.assertTrue(reference.equals(REFERENCETOMATCH));
99    }
100    }