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

File CacheKeyFactoryTest.java

 

Code metrics

0
16
3
1
84
48
3
0.19
5.33
3
1

Classes

Class Line # Actions
CacheKeyFactoryTest 34 16 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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.cache;
21   
22    import org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.lesscss.internal.colortheme.ColorThemeReference;
26    import org.xwiki.lesscss.internal.skin.SkinReference;
27    import org.xwiki.lesscss.resources.LESSResourceReference;
28    import org.xwiki.test.mockito.MockitoComponentMockingRule;
29   
30    import static org.junit.Assert.assertEquals;
31    import static org.mockito.Mockito.mock;
32    import static org.mockito.Mockito.when;
33   
 
34    public class CacheKeyFactoryTest
35    {
36    @Rule
37    public MockitoComponentMockingRule<CacheKeyFactory> mocker =
38    new MockitoComponentMockingRule<>(CacheKeyFactory.class);
39   
40    private XWikiContextCacheKeyFactory xcontextCacheKeyFactory;
41   
 
42  2 toggle @Before
43    public void setUp() throws Exception
44    {
45  2 xcontextCacheKeyFactory = mocker.getInstance(XWikiContextCacheKeyFactory.class);
46    }
47   
 
48  1 toggle @Test
49    public void getCacheKeyWithContext() throws Exception
50    {
51    // Mocks
52  1 LESSResourceReference lessResource = mock(LESSResourceReference.class);
53  1 SkinReference skin = mock(SkinReference.class);
54  1 ColorThemeReference colorTheme = mock(ColorThemeReference.class);
55   
56  1 when(lessResource.serialize()).thenReturn("lessResource");
57  1 when(skin.serialize()).thenReturn("skin");
58  1 when(colorTheme.serialize()).thenReturn("colorTheme");
59  1 when(xcontextCacheKeyFactory.getCacheKey()).thenReturn("XWikiContext[Mock]");
60   
61    // Test
62  1 assertEquals("12_lessResource_4_skin_10_colorTheme_18_XWikiContext[Mock]",
63    mocker.getComponentUnderTest().getCacheKey(lessResource, skin, colorTheme, true));
64    }
65   
 
66  1 toggle @Test
67    public void getCacheKeyWithoutContext() throws Exception
68    {
69    // Mocks
70  1 LESSResourceReference lessResource = mock(LESSResourceReference.class);
71  1 SkinReference skin = mock(SkinReference.class);
72  1 ColorThemeReference colorTheme = mock(ColorThemeReference.class);
73   
74  1 when(lessResource.serialize()).thenReturn("lessResource");
75  1 when(skin.serialize()).thenReturn("skin");
76  1 when(colorTheme.serialize()).thenReturn("colorTheme");
77   
78    // Test
79  1 assertEquals("12_lessResource_4_skin_10_colorTheme",
80    mocker.getComponentUnderTest().getCacheKey(lessResource, skin, colorTheme, false));
81    }
82   
83   
84    }