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

File BlockReferenceTest.java

 

Code metrics

0
14
3
1
87
49
5
0.36
4.67
3
1.67

Classes

Class Line # Actions
BlockReferenceTest 34 14 0% 5 2
0.8823529588.2%
 

Contributing tests

This file is covered by 3 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 org.junit.Test;
23    import org.xwiki.model.EntityType;
24   
25    import static org.junit.Assert.assertEquals;
26    import static org.junit.Assert.fail;
27   
28    /**
29    * Unit test for the Block reference ({@link BlockReference}).
30    *
31    * @version $Id: c57e53841dab8694acff196fcc21c08168181359 $
32    * @since 6.0M1
33    */
 
34    public class BlockReferenceTest
35    {
36    /**
37    * Ensures the equivalence of constructors.
38    */
 
39  1 toggle @Test
40    public void testConstructors()
41    {
42  1 BlockReference reference =
43    new BlockReference(new EntityReference("Block", EntityType.BLOCK));
44  1 assertEquals(reference, new BlockReference("Block"));
45   
46  1 reference =
47    new BlockReference(new EntityReference("Block", EntityType.BLOCK, new EntityReference("Page",
48    EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki",
49    EntityType.WIKI)))));
50  1 assertEquals(reference, new BlockReference("Block", new DocumentReference("wiki", "Space", "Page")));
51   
52  1 reference =
53    new BlockReference(new EntityReference("Block", EntityType.BLOCK,
54    new EntityReference("ObjectProperty", EntityType.OBJECT_PROPERTY,
55    new EntityReference("Object", EntityType.OBJECT,
56    new EntityReference("Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE,
57    new EntityReference("wiki", EntityType.WIKI)))))));
58  1 assertEquals(reference, new BlockReference("Block",
59    new ObjectPropertyReference("wiki", "Space", "Page", "Object", "ObjectProperty")));
60    }
61   
 
62  1 toggle @Test
63    public void testInvalidType()
64    {
65  1 try {
66  1 new BlockReference(new EntityReference("Block", EntityType.DOCUMENT));
67  0 fail("Should have thrown exception");
68    } catch (IllegalArgumentException expected) {
69  1 assertEquals("Invalid type [DOCUMENT] for a block reference", expected.getMessage());
70    }
71    }
72   
73    /**
74    * Tests that an object reference throws exception if it doesn't have a document as a parent.
75    */
 
76  1 toggle @Test
77    public void testInvalidParentType()
78    {
79  1 try {
80  1 new BlockReference(new EntityReference("Block", EntityType.BLOCK, new EntityReference("Object",
81    EntityType.OBJECT)));
82  0 fail("Should have thrown exception");
83    } catch (IllegalArgumentException expected) {
84  1 assertEquals("Invalid parent reference [Object Object] in a block reference", expected.getMessage());
85    }
86    }
87    }