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

File DefaultRatingsConfigurationTest.java

 

Code metrics

0
31
5
1
127
75
5
0.16
6.2
5
1

Classes

Class Line # Actions
DefaultRatingsConfigurationTest 49 31 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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.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    * Unit tests for {@link org.xwiki.ratings.internal.DefaultRatingsConfiguration}.
45    *
46    * @version $Id: 6b0487830d618b98df6ce5a466a5f7cce8dc3377 $
47    * @since 8.1M2
48    */
 
49    public class DefaultRatingsConfigurationTest
50    {
51    @Rule
52    public MockitoComponentMockingRule<RatingsConfiguration> mocker =
53    new MockitoComponentMockingRule<RatingsConfiguration>(DefaultRatingsConfiguration.class);
54   
55    private XWikiContext xcontext;
56   
 
57  4 toggle @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   
 
68  1 toggle @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   
 
84  1 toggle @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   
 
95  1 toggle @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   
 
115  1 toggle @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    }