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

File WikiUIExtensionRendererTest.java

 

Code metrics

0
21
2
1
94
61
2
0.1
10.5
2
1

Classes

Class Line # Actions
WikiUIExtensionRendererTest 46 21 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.uiextension;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.component.wiki.internal.bridge.ContentParser;
27    import org.xwiki.context.Execution;
28    import org.xwiki.context.ExecutionContext;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.block.XDOM;
32    import org.xwiki.rendering.internal.transformation.MutableRenderingContext;
33    import org.xwiki.rendering.syntax.Syntax;
34    import org.xwiki.rendering.transformation.RenderingContext;
35    import org.xwiki.rendering.transformation.Transformation;
36    import org.xwiki.test.mockito.MockitoComponentManagerRule;
37    import org.xwiki.uiextension.internal.WikiUIExtensionRenderer;
38   
39    import com.xpn.xwiki.XWiki;
40    import com.xpn.xwiki.XWikiContext;
41    import com.xpn.xwiki.doc.XWikiDocument;
42   
43    import static org.mockito.Mockito.mock;
44    import static org.mockito.Mockito.when;
45   
 
46    public class WikiUIExtensionRendererTest
47    {
48    private Execution execution;
49   
50    private RenderingContext renderingContext;
51   
52    private ContentParser contentParser;
53   
54    private XDOM xdom;
55   
56    private static final DocumentReference DOC_REF = new DocumentReference("xwiki", "XWiki", "MyUIExtension");
57   
58    @Rule
59    public MockitoComponentManagerRule cm = new MockitoComponentManagerRule();
60   
 
61  1 toggle @Before
62    public void setUp() throws Exception
63    {
64  1 execution = cm.registerMockComponent(Execution.class);
65  1 ExecutionContext executionContext = mock(ExecutionContext.class);
66  1 renderingContext = mock(MutableRenderingContext.class);
67  1 cm.registerComponent(RenderingContext.class, renderingContext);
68  1 cm.registerMockComponent(Transformation.class, "macro");
69  1 contentParser = cm.registerMockComponent(ContentParser.class);
70  1 when(execution.getContext()).thenReturn(executionContext);
71  1 xdom = mock(XDOM.class);
72    }
73   
 
74  1 toggle @Test
75    public void executeWithEmptyContent() throws Exception
76    {
77  1 XWikiContext xcontext = mock(XWikiContext.class);
78  1 XWikiDocument xdoc = mock(XWikiDocument.class);
79  1 XWiki xwiki = mock(XWiki.class);
80   
81  1 when(contentParser.parse("", Syntax.XWIKI_2_1, DOC_REF)).thenReturn(xdom);
82  1 when(xdom.clone()).thenReturn(xdom);
83  1 when(execution.getContext().getProperty("xwikicontext")).thenReturn(xcontext);
84  1 when(xcontext.getWiki()).thenReturn(xwiki);
85  1 when(xwiki.getDocument(DOC_REF, xcontext)).thenReturn(xdoc);
86  1 when(xcontext.getWiki().getDocument(DOC_REF, xcontext)).thenReturn(xdoc);
87  1 when(xdoc.getSyntax()).thenReturn(Syntax.XWIKI_2_1);
88   
89  1 WikiUIExtensionRenderer renderer = new WikiUIExtensionRenderer("roleHint", "", DOC_REF, cm);
90   
91  1 Block block = renderer.execute();
92  1 Assert.assertEquals(0, block.getChildren().size());
93    }
94    }