1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.objects

File BaseObjectReferenceTest.java

 

Code metrics

0
27
5
1
121
72
5
0.19
5.4
5
1

Classes

Class Line # Actions
BaseObjectReferenceTest 39 27 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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 com.xpn.xwiki.objects;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.model.EntityType;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.EntityReference;
29   
30    import com.xpn.xwiki.test.MockitoOldcoreRule;
31    import com.xpn.xwiki.test.reference.ReferenceComponentList;
32   
33    /**
34    * Validate {@link BaseObjectReference}.
35    *
36    * @version $Id: 344e30df4572eb24358b2736f0430a23a3439773 $
37    */
38    @ReferenceComponentList
 
39    public class BaseObjectReferenceTest
40    {
41    @Rule
42    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule();
43   
44    private DocumentReference document;
45   
 
46  4 toggle @Before
47    public void before() throws Exception
48    {
49  4 this.document = new DocumentReference("wiki", "space", "page");
50    }
51   
 
52  1 toggle @Test
53    public void testSerialize() throws Exception
54    {
55  1 BaseObjectReference reference =
56    new BaseObjectReference(new DocumentReference("wiki", "space", "class"), 42, this.document);
57   
58  1 Assert.assertEquals("wiki:space.class[42]", reference.getName());
59   
60  1 reference = new BaseObjectReference(new DocumentReference("wiki", "space", "class"), null, this.document);
61   
62  1 Assert.assertEquals("wiki:space.class", reference.getName());
63    }
64   
 
65  1 toggle @Test
66    public void testSerializeEscape() throws Exception
67    {
68  1 BaseObjectReference reference =
69    new BaseObjectReference(new DocumentReference("wiki", "space", "class[42]"), null, this.document);
70   
71  1 Assert.assertEquals("wiki:space.class\\[42]", reference.getName());
72   
73  1 reference =
74    new BaseObjectReference(new DocumentReference("wiki", "space", "class\\\\[42]"), null, this.document);
75   
76  1 Assert.assertEquals("wiki:space.class\\\\\\\\\\[42]", reference.getName());
77    }
78   
 
79  1 toggle @Test
80    public void testUnserialize() throws Exception
81    {
82  1 BaseObjectReference reference =
83    new BaseObjectReference(new EntityReference("wiki:space.class[42]", EntityType.OBJECT, this.document));
84   
85  1 Assert.assertEquals(new DocumentReference("wiki", "space", "class"), reference.getXClassReference());
86  1 Assert.assertEquals(42, (int) reference.getObjectNumber());
87   
88  1 reference = new BaseObjectReference(new EntityReference("wiki:space.class", EntityType.OBJECT, this.document));
89   
90  1 Assert.assertEquals(new DocumentReference("wiki", "space", "class"), reference.getXClassReference());
91  1 Assert.assertNull(reference.getObjectNumber());
92    }
93   
 
94  1 toggle @Test
95    public void testUnserializeEscape() throws Exception
96    {
97  1 BaseObjectReference reference =
98    new BaseObjectReference(new EntityReference("wiki:space.class\\[42]", EntityType.OBJECT, this.document));
99   
100  1 Assert.assertEquals(new DocumentReference("wiki", "space", "class[42]"), reference.getXClassReference());
101  1 Assert.assertNull(reference.getObjectNumber());
102   
103  1 reference =
104    new BaseObjectReference(new EntityReference("wiki:space.class\\\\[42]", EntityType.OBJECT, this.document));
105   
106  1 Assert.assertEquals(new DocumentReference("wiki", "space", "class\\"), reference.getXClassReference());
107  1 Assert.assertEquals(42, (int) reference.getObjectNumber());
108   
109  1 reference =
110    new BaseObjectReference(new EntityReference("wiki:space.class\\\\\\[42]", EntityType.OBJECT, this.document));
111   
112  1 Assert.assertEquals(new DocumentReference("wiki", "space", "class\\[42]"), reference.getXClassReference());
113  1 Assert.assertNull(reference.getObjectNumber());
114   
115  1 reference =
116    new BaseObjectReference(new EntityReference("wiki:space.class[word]", EntityType.OBJECT, this.document));
117   
118  1 Assert.assertEquals(new DocumentReference("wiki", "space", "class[word]"), reference.getXClassReference());
119  1 Assert.assertNull(reference.getObjectNumber());
120    }
121    }