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

File DefaultLESSColorThemeConverterTest.java

 

Code metrics

0
25
2
1
126
74
2
0.08
12.5
2
1

Classes

Class Line # Actions
DefaultLESSColorThemeConverterTest 54 25 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.converter;
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.lesscss.internal.cache.ColorThemeCache;
28    import org.xwiki.lesscss.internal.colortheme.ColorTheme;
29    import org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory;
30    import org.xwiki.lesscss.internal.colortheme.CurrentColorThemeGetter;
31    import org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference;
32    import org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference;
33    import org.xwiki.lesscss.internal.skin.FSSkinReference;
34    import org.xwiki.lesscss.internal.skin.SkinReferenceFactory;
35    import org.xwiki.lesscss.resources.LESSResourceReferenceFactory;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37   
38    import com.xpn.xwiki.XWiki;
39    import com.xpn.xwiki.XWikiContext;
40   
41    import static org.junit.Assert.assertEquals;
42    import static org.junit.Assert.assertNotEquals;
43    import static org.junit.Assert.assertTrue;
44    import static org.mockito.ArgumentMatchers.eq;
45    import static org.mockito.Mockito.mock;
46    import static org.mockito.Mockito.when;
47   
48    /**
49    * Test class for {@link org.xwiki.lesscss.internal.colortheme.converter.DefaultLESSColorThemeConverter}.
50    *
51    * @version $Id: 688d82d7a4f5c6da8796355fe546763bae9d3282 $
52    * @since 7.0RC1
53    */
 
54    public class DefaultLESSColorThemeConverterTest
55    {
56    @Rule
57    public MockitoComponentMockingRule<DefaultLESSColorThemeConverter> mocker =
58    new MockitoComponentMockingRule<>(DefaultLESSColorThemeConverter.class);
59   
60    private ColorThemeCache cache;
61   
62    private Provider<XWikiContext> xcontextProvider;
63   
64    private CurrentColorThemeGetter currentColorThemeGetter;
65   
66    private SkinReferenceFactory skinReferenceFactory;
67   
68    private ColorThemeReferenceFactory colorThemeReferenceFactory;
69   
70    private LESSResourceReferenceFactory lessResourceReferenceFactory;
71   
72    private XWikiContext xcontext;
73   
74    private XWiki xwiki;
75   
 
76  1 toggle @Before
77    public void setUp() throws Exception
78    {
79  1 cache = mocker.getInstance(ColorThemeCache.class);
80  1 currentColorThemeGetter = mocker.getInstance(CurrentColorThemeGetter.class);
81  1 skinReferenceFactory = mocker.getInstance(SkinReferenceFactory.class);
82  1 colorThemeReferenceFactory = mocker.getInstance(ColorThemeReferenceFactory.class);
83  1 lessResourceReferenceFactory = mocker.getInstance(LESSResourceReferenceFactory.class);
84  1 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
85  1 xcontext = mock(XWikiContext.class);
86  1 when(xcontextProvider.get()).thenReturn(xcontext);
87  1 xwiki = mock(XWiki.class);
88  1 when(xcontext.getWiki()).thenReturn(xwiki);
89  1 when(xwiki.getSkin(xcontext)).thenReturn("skin");
90  1 when(currentColorThemeGetter.getCurrentColorTheme(true, "default")).thenReturn("colorTheme");
91  1 when(skinReferenceFactory.createReference("skin")).thenReturn(new FSSkinReference("skin"));
92  1 when(colorThemeReferenceFactory.createReference("colorTheme")).thenReturn(
93    new NamedColorThemeReference("colorTheme"));
94  1 when(cache.getMutex(eq(new LESSSkinFileResourceReference("file", null, null)), eq(new FSSkinReference("skin")),
95    eq(new NamedColorThemeReference("colorTheme")))).thenReturn("mutex");
96    }
97   
 
98  1 toggle @Test
99    public void getColorThemeFromSkinFileWhenInCache() throws Exception
100    {
101    // Mocks
102  1 ColorTheme cachedColorTheme = new ColorTheme();
103  1 cachedColorTheme.put("key", "value1");
104   
105  1 LESSSkinFileResourceReference lessSkinFileResourceReference
106    = new LESSSkinFileResourceReference("file", null, null);
107  1 when(lessResourceReferenceFactory.createReferenceForSkinFile("file")).thenReturn(lessSkinFileResourceReference);
108   
109  1 when(cache.get(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")),
110    eq(new NamedColorThemeReference("colorTheme")))).thenReturn(cachedColorTheme);
111   
112    // Test
113  1 ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("file", "skin", false);
114   
115    // Verify
116  1 assertEquals(cachedColorTheme, result);
117    // Verify that the returned value is not the instance stored in the cache (that the end-user would wrongly be
118    // able to modify)
119  1 assertTrue(result != cachedColorTheme);
120    // Be extra-sure :)
121  1 result.put("key", "value2");
122  1 assertNotEquals("value2", cachedColorTheme.get("key"));
123   
124    }
125   
126    }