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

File LESSExportActionListenerTest.java

 

Code metrics

0
17
4
1
92
52
4
0.24
4.25
4
1

Classes

Class Line # Actions
LESSExportActionListenerTest 43 17 0% 4 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.lesscss.internal.listeners;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.bridge.event.ActionExecutingEvent;
25    import org.xwiki.lesscss.internal.LESSContext;
26    import org.xwiki.test.mockito.MockitoComponentMockingRule;
27   
28    import com.xpn.xwiki.XWikiContext;
29    import com.xpn.xwiki.web.XWikiRequest;
30   
31    import static org.junit.Assert.assertEquals;
32    import static org.mockito.Mockito.mock;
33    import static org.mockito.Mockito.verify;
34    import static org.mockito.Mockito.verifyZeroInteractions;
35    import static org.mockito.Mockito.when;
36   
37    /**
38    * Unit tests for {@link LESSExportActionListener}.
39    *
40    * @version $Id: 1723abbf3d302fbe0f7349216dfaf1d3517d2ea5 $
41    * @since 6.2RC1
42    */
 
43    public class LESSExportActionListenerTest
44    {
45    @Rule
46    public MockitoComponentMockingRule<LESSExportActionListener> mocker =
47    new MockitoComponentMockingRule<>(LESSExportActionListener.class);
48   
 
49  1 toggle @Test
50    public void getName() throws Exception
51    {
52  1 assertEquals("lessexport", this.mocker.getComponentUnderTest().getName());
53    }
54   
 
55  1 toggle @Test
56    public void getEvents() throws Exception
57    {
58  1 assertEquals(1, this.mocker.getComponentUnderTest().getEvents().size());
59  1 assertEquals(new ActionExecutingEvent("export"), this.mocker.getComponentUnderTest().getEvents().get(0));
60    }
61   
 
62  1 toggle @Test
63    public void onEventWhenHTMLExport() throws Exception
64    {
65  1 XWikiContext xcontext = mock(XWikiContext.class);
66  1 XWikiRequest request = mock(XWikiRequest.class);
67  1 when(xcontext.getRequest()).thenReturn(request);
68  1 when(request.get("format")).thenReturn("html");
69   
70  1 this.mocker.getComponentUnderTest().onEvent(new ActionExecutingEvent("export"), null, xcontext);
71   
72    // The test is here: we verify that the cache is disabled!
73  1 LESSContext lessContext = mocker.getInstance(LESSContext.class);
74  1 verify(lessContext).setHtmlExport(true);
75    }
76   
 
77  1 toggle @Test
78    public void onEventWhenNonHTMLExport() throws Exception
79    {
80  1 XWikiContext xcontext = mock(XWikiContext.class);
81  1 XWikiRequest request = mock(XWikiRequest.class);
82  1 when(xcontext.getRequest()).thenReturn(request);
83  1 when(request.get("format")).thenReturn("xar");
84   
85  1 this.mocker.getComponentUnderTest().onEvent(new ActionExecutingEvent("export"), null, xcontext);
86   
87    // The test is here: we verify that the we do not disable the LESS cache (since the export is not an HTML
88    // export). Actually that the context object was not called at all...
89  1 LESSContext lessContext = mocker.getInstance(LESSContext.class);
90  1 verifyZeroInteractions(lessContext);
91    }
92    }