1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.model.internal.reference.converter

File EntityReferenceConverterTest.java

 

Code metrics

0
21
6
1
109
69
6
0.29
3.5
6
1

Classes

Class Line # Actions
EntityReferenceConverterTest 41 21 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 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.internal.reference.converter;
21   
22    import org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.model.EntityType;
26    import org.xwiki.model.reference.EntityReference;
27    import org.xwiki.properties.ConverterManager;
28    import org.xwiki.properties.converter.Converter;
29    import org.xwiki.test.annotation.AllComponents;
30    import org.xwiki.test.mockito.MockitoComponentMockingRule;
31   
32    import static org.junit.Assert.assertEquals;
33    import static org.junit.Assert.assertNull;
34   
35    /**
36    * Validate {@link EntityReferenceConverter} component.
37    *
38    * @version $Id: 3fcb0605265dab5aa58ae490c5914b1d272ca6a5 $
39    */
40    @AllComponents
 
41    public class EntityReferenceConverterTest
42    {
43    @Rule
44    public MockitoComponentMockingRule<Converter<EntityReference>> mocker =
45    new MockitoComponentMockingRule<>(EntityReferenceConverter.class);
46   
47    private ConverterManager converterManager;
48   
 
49  5 toggle @Before
50    public void setUp() throws Exception
51    {
52  5 this.converterManager = this.mocker.getInstance(ConverterManager.class);
53    }
54   
 
55  1 toggle @Test
56    public void convertDocumentFromString()
57    {
58  1 EntityReference reference;
59   
60  1 reference =
61    new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE,
62    new EntityReference("wiki", EntityType.WIKI)));
63  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "document:wiki:space.page"));
64   
65  1 reference = new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE));
66  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "document:space.page"));
67  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "space.page"));
68   
69  1 reference = new EntityReference("page", EntityType.DOCUMENT);
70  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "document:page"));
71  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "page"));
72    }
73   
 
74  1 toggle @Test
75    public void convertSpaceFromString()
76    {
77  1 EntityReference reference;
78   
79  1 reference = new EntityReference("space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI));
80  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "space:wiki:space"));
81   
82  1 reference = new EntityReference("space", EntityType.SPACE);
83  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "space:space"));
84    }
85   
 
86  1 toggle @Test
87    public void convertWikiFromString()
88    {
89  1 EntityReference reference = new EntityReference("dev", EntityType.WIKI);
90  1 assertEquals(reference, this.converterManager.convert(EntityReference.class, "wiki:dev"));
91    }
92   
 
93  1 toggle @Test
94    public void convertFromNull()
95    {
96  1 assertNull(this.converterManager.convert(EntityReference.class, null));
97    }
98   
 
99  1 toggle @Test
100    public void convertToString()
101    {
102  1 EntityReference reference;
103   
104  1 reference =
105    new EntityReference("page", EntityType.DOCUMENT, new EntityReference("space", EntityType.SPACE,
106    new EntityReference("wiki", EntityType.WIKI)));
107  1 assertEquals("document:wiki:space.page", this.converterManager.convert(String.class, reference));
108    }
109    }