1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.lesscss.internal.colortheme

File DefaultColorThemeReferenceFactoryTest.java

 

Code metrics

0
27
4
1
130
81
4
0.15
6.75
4
1

Classes

Class Line # Actions
DefaultColorThemeReferenceFactoryTest 49 27 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.lesscss.internal.colortheme;
21   
22    import javax.inject.Provider;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.component.util.DefaultParameterizedType;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.DocumentReferenceResolver;
30    import org.xwiki.model.reference.WikiReference;
31    import org.xwiki.test.mockito.MockitoComponentMockingRule;
32    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
33   
34    import com.xpn.xwiki.XWiki;
35    import com.xpn.xwiki.XWikiContext;
36    import com.xpn.xwiki.doc.XWikiDocument;
37   
38    import static org.junit.Assert.assertEquals;
39    import static org.mockito.ArgumentMatchers.eq;
40    import static org.mockito.Mockito.mock;
41    import static org.mockito.Mockito.when;
42   
43    /**
44    * Test class for {@link org.xwiki.lesscss.internal.colortheme.DefaultColorThemeReferenceFactory}.
45    *
46    * @since 6.4M2
47    * @version $Id: 5396780e62d9afeac37b2d9c431284f11fee657a $
48    */
 
49    public class DefaultColorThemeReferenceFactoryTest
50    {
51    @Rule
52    public MockitoComponentMockingRule<DefaultColorThemeReferenceFactory> mocker =
53    new MockitoComponentMockingRule<>(DefaultColorThemeReferenceFactory.class);
54   
55    private Provider<XWikiContext> xcontextProvider;
56   
57    private DocumentReferenceResolver<String> documentReferenceResolver;
58   
59    private WikiDescriptorManager wikiDescriptorManager;
60   
61    private XWikiContext xcontext;
62   
63    private XWiki xwiki;
64   
 
65  3 toggle @Before
66    public void setUp() throws Exception
67    {
68  3 wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
69  3 documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class,
70    String.class));
71  3 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
72  3 xcontext = mock(XWikiContext.class);
73  3 when(xcontextProvider.get()).thenReturn(xcontext);
74  3 xwiki = mock(XWiki.class);
75  3 when(xcontext.getWiki()).thenReturn(xwiki);
76   
77  3 when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
78    }
79   
 
80  1 toggle @Test
81    public void createReferenceWhenItIsAColorTheme() throws Exception
82    {
83    // Mocks
84  1 DocumentReference colorThemeDocRef = new DocumentReference("otherWiki", "ColorThemes", "colorTheme");
85  1 when(documentReferenceResolver.resolve(eq("colorTheme"), eq(new WikiReference("wikiId")))).thenReturn(
86    colorThemeDocRef);
87  1 when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(true);
88  1 XWikiDocument colorThemeDoc = mock(XWikiDocument.class);
89  1 when(xwiki.getDocument(colorThemeDocRef, xcontext)).thenReturn(colorThemeDoc);
90  1 when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "ColorThemes", "ColorThemeClass")))).
91    thenReturn(1);
92   
93    // Test
94  1 assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"),
95    null), mocker.getComponentUnderTest().createReference("colorTheme"));
96    }
97   
 
98  1 toggle @Test
99    public void createReferenceWhenItIsAFlamingoTheme() throws Exception
100    {
101    // Mocks
102  1 DocumentReference colorThemeDocRef = new DocumentReference("otherWiki", "ColorThemes", "colorTheme");
103  1 when(documentReferenceResolver.resolve(eq("colorTheme"), eq(new WikiReference("wikiId")))).thenReturn(
104    colorThemeDocRef);
105  1 when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(true);
106  1 XWikiDocument colorThemeDoc = mock(XWikiDocument.class);
107  1 when(xwiki.getDocument(colorThemeDocRef, xcontext)).thenReturn(colorThemeDoc);
108  1 when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "ColorThemes", "ColorThemeClass")))).
109    thenReturn(0);
110  1 when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "FlamingoThemesCode", "ThemeClass")))).
111    thenReturn(1);
112   
113    // Test
114  1 assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"),
115    null), mocker.getComponentUnderTest().createReference("colorTheme"));
116    }
117   
 
118  1 toggle @Test
119    public void createReferenceWhenItIsDefault() throws Exception
120    {
121    // Mocks
122  1 DocumentReference colorThemeDocRef = new DocumentReference("wikiId", "Main", "default");
123  1 when(documentReferenceResolver.resolve("default")).thenReturn(colorThemeDocRef);
124  1 when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(false);
125   
126    // Test
127  1 assertEquals(new NamedColorThemeReference("default"),
128    mocker.getComponentUnderTest().createReference("default"));
129    }
130    }