1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.ratings.internal; |
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.model.reference.DocumentReference; |
28 |
|
import org.xwiki.model.reference.EntityReference; |
29 |
|
import org.xwiki.ratings.RatingsConfiguration; |
30 |
|
import org.xwiki.ratings.RatingsManager; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
32 |
|
|
33 |
|
import static org.junit.Assert.*; |
34 |
|
import static org.mockito.Mockito.*; |
35 |
|
|
36 |
|
import java.util.Arrays; |
37 |
|
|
38 |
|
import com.xpn.xwiki.XWiki; |
39 |
|
import com.xpn.xwiki.XWikiContext; |
40 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
41 |
|
import com.xpn.xwiki.objects.BaseObject; |
42 |
|
import com.xpn.xwiki.objects.BaseProperty; |
43 |
|
|
44 |
|
@link |
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 5 |
Complexity Density: 0.16 |
|
49 |
|
public class DefaultRatingsConfigurationTest |
50 |
|
{ |
51 |
|
@Rule |
52 |
|
public MockitoComponentMockingRule<RatingsConfiguration> mocker = |
53 |
|
new MockitoComponentMockingRule<RatingsConfiguration>(DefaultRatingsConfiguration.class); |
54 |
|
|
55 |
|
private XWikiContext xcontext; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
57 |
4 |
@Before... |
58 |
|
public void configure() throws Exception |
59 |
|
{ |
60 |
4 |
xcontext = mock(XWikiContext.class); |
61 |
4 |
Provider<XWikiContext> xcontextProvider = mocker.getInstance(XWikiContext.TYPE_PROVIDER); |
62 |
4 |
when(xcontextProvider.get()).thenReturn(xcontext); |
63 |
|
|
64 |
4 |
XWiki wiki = mock(XWiki.class); |
65 |
4 |
when(xcontext.getWiki()).thenReturn(wiki); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
68 |
1 |
@Test... |
69 |
|
public void getSpaceConfigurationDocument() throws Exception |
70 |
|
{ |
71 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space1", "Space2"), "Page"); |
72 |
|
|
73 |
1 |
XWikiDocument spaceConfigurationDocument = mock(XWikiDocument.class, "Space Configuration Document"); |
74 |
|
|
75 |
1 |
DocumentReference configurationDocumentReference = new DocumentReference("wiki", "Space1", "WebPreferences"); |
76 |
1 |
when(xcontext.getWiki().getDocument((EntityReference)configurationDocumentReference, xcontext)).thenReturn(spaceConfigurationDocument); |
77 |
|
|
78 |
1 |
BaseObject configurationObject = mock(BaseObject.class); |
79 |
1 |
when(spaceConfigurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE)).thenReturn(configurationObject); |
80 |
|
|
81 |
1 |
assertEquals(spaceConfigurationDocument, mocker.getComponentUnderTest().getConfigurationDocument(documentReference)); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void getWikiConfigurationDocument() throws Exception |
86 |
|
{ |
87 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page"); |
88 |
|
|
89 |
1 |
XWikiDocument wikiConfigurationDocument = mock(XWikiDocument.class, "Wiki Configuration Document"); |
90 |
1 |
when(xcontext.getWiki().getDocument(RatingsManager.RATINGS_CONFIG_GLOBAL_REFERENCE, xcontext)).thenReturn(wikiConfigurationDocument); |
91 |
|
|
92 |
1 |
assertEquals(wikiConfigurationDocument, mocker.getComponentUnderTest().getConfigurationDocument(documentReference)); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
95 |
1 |
@Test... |
96 |
|
public void getConfigurationParameter() throws Exception |
97 |
|
{ |
98 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space1", "Space2"), "Page"); |
99 |
|
|
100 |
1 |
XWikiDocument spaceConfigurationDocument = mock(XWikiDocument.class, "Space Configuration Document"); |
101 |
|
|
102 |
1 |
DocumentReference configurationDocumentReference = new DocumentReference("wiki", "Space1", "WebPreferences"); |
103 |
1 |
when(xcontext.getWiki().getDocument((EntityReference)configurationDocumentReference, xcontext)).thenReturn(spaceConfigurationDocument); |
104 |
|
|
105 |
1 |
BaseObject configurationObject = mock(BaseObject.class); |
106 |
1 |
when(spaceConfigurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE)).thenReturn(configurationObject); |
107 |
|
|
108 |
1 |
BaseProperty displayRatings = mock(BaseProperty.class); |
109 |
1 |
when(configurationObject.get("displayRatings")).thenReturn(displayRatings); |
110 |
1 |
when(displayRatings.getValue()).thenReturn("1"); |
111 |
|
|
112 |
1 |
assertEquals("1", mocker.getComponentUnderTest().getConfigurationParameter(documentReference, "displayRatings", "1")); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
115 |
1 |
@Test... |
116 |
|
public void getConfigurationParameterDefaultValue() throws Exception |
117 |
|
{ |
118 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space1", "Space2"), "Page"); |
119 |
|
|
120 |
1 |
XWikiDocument spaceConfigurationDocument = mock(XWikiDocument.class, "Space Configuration Document"); |
121 |
|
|
122 |
1 |
DocumentReference configurationDocumentReference = new DocumentReference("wiki", "Space1", "WebPreferences"); |
123 |
1 |
when(xcontext.getWiki().getDocument((EntityReference)configurationDocumentReference, xcontext)).thenReturn(spaceConfigurationDocument); |
124 |
|
|
125 |
1 |
assertEquals("1", mocker.getComponentUnderTest().getConfigurationParameter(documentReference, "displayRatings", "1")); |
126 |
|
} |
127 |
|
} |