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

File IndexedObjectReferenceTest.java

 

Code metrics

0
28
8
1
137
96
8
0.29
3.5
8
1

Classes

Class Line # Actions
IndexedObjectReferenceTest 35 28 0% 8 6
0.833333383.3%
 

Contributing tests

This file is covered by 7 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.annotation.reference;
21   
22    import org.junit.Test;
23    import org.xwiki.model.EntityType;
24    import org.xwiki.model.reference.EntityReference;
25   
26    import static org.junit.Assert.assertEquals;
27    import static org.junit.Assert.assertNull;
28   
29    /**
30    * Tests the {@link IndexedObjectReference} implementation of object names.
31    *
32    * @version $Id: 0778949b267f98c1db1716d697901f24f4f8fe78 $
33    * @since 2.3M1
34    */
 
35    public class IndexedObjectReferenceTest
36    {
37    /**
38    * Ensures the equivalence of constructors.
39    */
 
40  1 toggle @Test
41    public void testConstructors()
42    {
43  1 IndexedObjectReference reference1 =
44    new IndexedObjectReference(new EntityReference("XWiki.Class[2]", EntityType.OBJECT, new EntityReference(
45    "Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
46    EntityType.WIKI)))));
47  1 IndexedObjectReference reference2 =
48    new IndexedObjectReference("XWiki.Class", 2, new EntityReference("Page", EntityType.DOCUMENT,
49    new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))));
50  1 assertEquals(reference1, reference2);
51  1 assertEquals(reference1.getClassName(), reference2.getClassName());
52  1 assertEquals(reference1.getObjectNumber(), reference2.getObjectNumber());
53    }
54   
55    /**
56    * Ensures the equivalence of constructors building a reference to the default object.
57    */
 
58  0 toggle public void testConstructorsWhenNonIndexedReference()
59    {
60  0 IndexedObjectReference reference1 =
61    new IndexedObjectReference(new EntityReference("XWiki.Class", EntityType.OBJECT, new EntityReference(
62    "Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
63    EntityType.WIKI)))));
64  0 IndexedObjectReference reference2 =
65    new IndexedObjectReference("XWiki.Class", null, new EntityReference("Page", EntityType.DOCUMENT,
66    new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))));
67  0 assertEquals(reference1, reference2);
68  0 assertEquals(reference1.getClassName(), reference2.getClassName());
69  0 assertEquals(reference1.getObjectNumber(), reference2.getObjectNumber());
70    }
71   
 
72  1 toggle @Test
73    public void testObjectNumber()
74    {
75  1 IndexedObjectReference reference =
76    new IndexedObjectReference(new EntityReference("XWiki.Class[2]", EntityType.OBJECT, new EntityReference(
77    "Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
78    EntityType.WIKI)))));
79  1 assertEquals("XWiki.Class", reference.getClassName());
80  1 assertEquals(new Integer(2), reference.getObjectNumber());
81    }
82   
 
83  1 toggle @Test
84    public void testObjectNumberWhenDefaultObject()
85    {
86  1 IndexedObjectReference reference =
87    new IndexedObjectReference(new EntityReference("XWiki.Class", EntityType.OBJECT, new EntityReference(
88    "Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
89    EntityType.WIKI)))));
90  1 assertEquals("XWiki.Class", reference.getClassName());
91  1 assertNull(reference.getObjectNumber());
92    }
93   
 
94  1 toggle @Test
95    public void testClassNameWhenRelativeClass()
96    {
97  1 IndexedObjectReference reference =
98    new IndexedObjectReference(new EntityReference("Class", EntityType.OBJECT, new EntityReference("Page",
99    EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
100    EntityType.WIKI)))));
101  1 assertEquals("Class", reference.getClassName());
102  1 assertNull(reference.getObjectNumber());
103    }
104   
 
105  1 toggle @Test
106    public void testObjectNumberWhenNonPairedSeparators()
107    {
108  1 IndexedObjectReference reference =
109    new IndexedObjectReference(new EntityReference("XWiki.Class0]", EntityType.OBJECT, new EntityReference(
110    "Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
111    EntityType.WIKI)))));
112  1 assertEquals("XWiki.Class0]", reference.getClassName());
113  1 assertNull(reference.getObjectNumber());
114    }
115   
 
116  1 toggle @Test
117    public void testObjectNumberWhenNameContainsSeparators()
118    {
119  1 IndexedObjectReference reference =
120    new IndexedObjectReference(new EntityReference("XW[iki.C]lass[0]", EntityType.OBJECT, new EntityReference(
121    "Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
122    EntityType.WIKI)))));
123  1 assertEquals("XW[iki.C]lass", reference.getClassName());
124  1 assertEquals(new Integer(0), reference.getObjectNumber());
125    }
126   
 
127  1 toggle @Test
128    public void testObjectNumberWhenIndexNotNumber()
129    {
130  1 IndexedObjectReference reference =
131    new IndexedObjectReference(new EntityReference("XWiki.Class[number]", EntityType.OBJECT,
132    new EntityReference("Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE,
133    new EntityReference("wiki", EntityType.WIKI)))));
134  1 assertEquals("XWiki.Class[number]", reference.getClassName());
135  1 assertNull(reference.getObjectNumber());
136    }
137    }