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

File XClassRelativeStringEntityReferenceResolverTest.java

 

Code metrics

0
13
4
1
86
55
5
0.38
3.25
4
1.25

Classes

Class Line # Actions
XClassRelativeStringEntityReferenceResolverTest 42 13 0% 5 1
0.941176594.1%
 

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 com.xpn.xwiki.internal.model.reference;
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.internal.reference.DefaultSymbolScheme;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.EntityReferenceResolver;
31    import org.xwiki.test.annotation.ComponentList;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    /**
35    * Unit tests for {@link XClassRelativeStringEntityReferenceResolver}.
36    *
37    * @version $Id: 82b07cd5192227a2500c17e4708c142765ac4c46 $
38    */
39    @ComponentList({
40    DefaultSymbolScheme.class
41    })
 
42    public class XClassRelativeStringEntityReferenceResolverTest
43    {
44    @Rule
45    public MockitoComponentMockingRule<EntityReferenceResolver<String>> mocker =
46    new MockitoComponentMockingRule<>(XClassRelativeStringEntityReferenceResolver.class);
47   
48    private EntityReferenceResolver<String> resolver;
49   
 
50  3 toggle @Before
51    public void before() throws Exception
52    {
53  3 this.resolver = this.mocker.getComponentUnderTest();
54    }
55   
 
56  1 toggle @Test
57    public void testResolve()
58    {
59  1 EntityReference reference = this.resolver.resolve("page", EntityType.DOCUMENT);
60  1 Assert.assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
61  1 Assert.assertEquals("XWiki", reference.extractReference(EntityType.SPACE).getName());
62  1 Assert.assertNull(reference.extractReference(EntityType.WIKI));
63    }
64   
 
65  1 toggle @Test
66    public void testResolveWhenExplicitParameterAndNoPageInStringRepresentation()
67    {
68  1 EntityReference reference =
69    this.resolver.resolve("", EntityType.DOCUMENT, new DocumentReference("dummy", "dummy", "page"));
70  1 Assert.assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName());
71  1 Assert.assertEquals("XWiki", reference.extractReference(EntityType.SPACE).getName());
72  1 Assert.assertNull(reference.extractReference(EntityType.WIKI));
73    }
74   
 
75  1 toggle @Test
76    public void testResolveWhenNoPageReferenceSpecified()
77    {
78  1 try {
79  1 this.resolver.resolve("", EntityType.DOCUMENT);
80  0 Assert.fail("Should have thrown an exception here");
81    } catch (IllegalArgumentException expected) {
82  1 Assert.assertEquals("A Reference to a page must be passed as a parameter when the string to resolve "
83    + "doesn't specify a page", expected.getMessage());
84    }
85    }
86    }