1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
45 |
|
|
46 |
|
@since |
47 |
|
@version |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0.15 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
65 |
3 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void createReferenceWhenItIsAColorTheme() throws Exception |
82 |
|
{ |
83 |
|
|
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 |
|
|
94 |
1 |
assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"), |
95 |
|
null), mocker.getComponentUnderTest().createReference("colorTheme")); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void createReferenceWhenItIsAFlamingoTheme() throws Exception |
100 |
|
{ |
101 |
|
|
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 |
|
|
114 |
1 |
assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"), |
115 |
|
null), mocker.getComponentUnderTest().createReference("colorTheme")); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
118 |
1 |
@Test... |
119 |
|
public void createReferenceWhenItIsDefault() throws Exception |
120 |
|
{ |
121 |
|
|
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 |
|
|
127 |
1 |
assertEquals(new NamedColorThemeReference("default"), |
128 |
|
mocker.getComponentUnderTest().createReference("default")); |
129 |
|
} |
130 |
|
} |