1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.wiki.internal.descriptor.document

File DefaultWikiDescriptorDocumentHelperTest.java

 

Code metrics

0
22
4
1
114
68
4
0.18
5.5
4
1

Classes

Class Line # Actions
DefaultWikiDescriptorDocumentHelperTest 49 22 0% 4 0
1.0100%
 

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.wiki.internal.descriptor.document;
21   
22    import static org.junit.Assert.assertEquals;
23    import static org.mockito.ArgumentMatchers.any;
24    import static org.mockito.ArgumentMatchers.eq;
25    import static org.mockito.Mockito.mock;
26    import static org.mockito.Mockito.when;
27   
28    import javax.inject.Provider;
29   
30    import org.junit.Before;
31    import org.junit.Rule;
32    import org.junit.Test;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.model.reference.DocumentReferenceResolver;
35    import org.xwiki.query.QueryManager;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
38   
39    import com.xpn.xwiki.XWiki;
40    import com.xpn.xwiki.XWikiContext;
41    import com.xpn.xwiki.doc.XWikiDocument;
42   
43    /**
44    * Unit tests for {@link org.xwiki.wiki.internal.descriptor.document.DefaultWikiDescriptorDocumentHelper}.
45    *
46    * @version $Id: de1ff0291f8fa269434261cf732ff1cd7d4149ab $
47    * @since 6.0M1
48    */
 
49    public class DefaultWikiDescriptorDocumentHelperTest
50    {
51    @Rule
52    public org.xwiki.test.mockito.MockitoComponentMockingRule<DefaultWikiDescriptorDocumentHelper> mocker =
53    new MockitoComponentMockingRule<>(DefaultWikiDescriptorDocumentHelper.class);
54   
55    private WikiDescriptorManager wikiDescriptorManager;
56   
57    private Provider<XWikiContext> xcontextProvider;
58   
59    private QueryManager queryManager;
60   
61    private DocumentReferenceResolver<String> documentReferenceResolver;
62   
63    private XWikiContext context;
64   
65    private XWiki xwiki;
66   
 
67  3 toggle @Before
68    public void setUp() throws Exception
69    {
70  3 wikiDescriptorManager = mocker.registerMockComponent(WikiDescriptorManager.class);
71  3 when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki");
72   
73  3 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
74  3 context = mock(XWikiContext.class);
75  3 when(xcontextProvider.get()).thenReturn(context);
76  3 xwiki = mock(XWiki.class);
77  3 when(context.getWiki()).thenReturn(xwiki);
78   
79  3 queryManager = mocker.getInstance(QueryManager.class);
80  3 documentReferenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "current");
81    }
82   
 
83  1 toggle @Test
84    public void getDocumentReferenceFromId() throws Exception
85    {
86  1 DocumentReference docRef = new DocumentReference("xwiki", XWiki.SYSTEM_SPACE, "XWikiServerWikiid1");
87  1 assertEquals(docRef, this.mocker.getComponentUnderTest().getDocumentReferenceFromId("wikiid1"));
88    }
89   
 
90  1 toggle @Test
91    public void getDocumentFromWikiId() throws Exception
92    {
93  1 DocumentReference docRef = new DocumentReference("xwiki", XWiki.SYSTEM_SPACE, "XWikiServerWikiid1");
94  1 XWikiDocument document = mock(XWikiDocument.class);
95  1 when(xwiki.getDocument(eq(docRef), any(XWikiContext.class))).thenReturn(document);
96   
97  1 XWikiDocument returnedDocument = this.mocker.getComponentUnderTest().getDocumentFromWikiId("wikiid1");
98  1 assertEquals(returnedDocument, document);
99    }
100   
 
101  1 toggle @Test
102    public void getWikiIdFromDocumentFullname() throws Exception
103    {
104  1 String result = mocker.getComponentUnderTest().getWikiIdFromDocumentFullname("XWiki.XWikiServerSubwiki");
105  1 assertEquals("subwiki", result);
106   
107  1 result = mocker.getComponentUnderTest().getWikiIdFromDocumentFullname("XWiki.XWikiServerXWikiServer");
108  1 assertEquals("xwikiserver", result);
109   
110  1 result = mocker.getComponentUnderTest().getWikiIdFromDocumentFullname("XWiki.XWikiServerAbbc");
111  1 assertEquals("abbc", result);
112    }
113   
114    }