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

File XWikiContextCacheKeyFactoryTest.java

 

Code metrics

0
7
2
1
74
38
2
0.29
3.5
2
1

Classes

Class Line # Actions
XWikiContextCacheKeyFactoryTest 42 7 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.cache;
21   
22    import java.net.URL;
23   
24    import javax.inject.Provider;
25   
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.test.mockito.MockitoComponentMockingRule;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.web.XWikiURLFactory;
33   
34    import static org.junit.Assert.assertEquals;
35    import static org.mockito.ArgumentMatchers.any;
36    import static org.mockito.Mockito.mock;
37    import static org.mockito.Mockito.when;
38   
39    /**
40    * @version $Id: 4ea9edd7c330bf27a7a5089a239a4eec9431fb1f $
41    */
 
42    public class XWikiContextCacheKeyFactoryTest
43    {
44    @Rule
45    public MockitoComponentMockingRule<XWikiContextCacheKeyFactory> mocker =
46    new MockitoComponentMockingRule<>(XWikiContextCacheKeyFactory.class);
47   
48    private Provider<XWikiContext> xcontextProvider;
49   
50    private XWikiContext xcontext;
51   
 
52  1 toggle @Before
53    public void setUp() throws Exception
54    {
55  1 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
56  1 xcontext = mock(XWikiContext.class);
57  1 when(xcontextProvider.get()).thenReturn(xcontext);
58    }
59   
 
60  1 toggle @Test
61    public void getCacheKey() throws Exception
62    {
63    // Mocks
64  1 XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
65  1 when(xcontext.getURLFactory()).thenReturn(urlFactory);
66   
67  1 when(urlFactory.createSkinURL(any(), any(), any(XWikiContext.class))).thenReturn(
68    new URL("http://host/path"));
69   
70    // Test
71  1 assertEquals("XWikiContext[URLFactory[" + urlFactory.getClass().getName() + ", /path]]",
72    mocker.getComponentUnderTest().getCacheKey());
73    }
74    }