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

File ExpandedMacroBlockTest.java

 

Code metrics

0
27
4
1
107
66
4
0.15
6.75
4
1

Classes

Class Line # Actions
ExpandedMacroBlockTest 43 27 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.rendering.block;
21   
22    import java.util.Collections;
23    import java.util.Map;
24   
25    import org.junit.Test;
26    import org.mockito.ArgumentCaptor;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.rendering.listener.MetaData;
29    import org.xwiki.rendering.renderer.BlockRenderer;
30    import org.xwiki.rendering.renderer.printer.WikiPrinter;
31    import org.xwiki.rendering.syntax.Syntax;
32   
33    import static org.junit.Assert.*;
34    import static org.mockito.ArgumentMatchers.*;
35    import static org.mockito.Mockito.*;
36   
37    /**
38    * Unit tests for {@link ExpandedMacroBlock}.
39    *
40    * @since 3.1
41    * @version $Id: 3c7713671915c5f470e9e0de477fc53846cbbcba $
42    */
 
43    public class ExpandedMacroBlockTest
44    {
45    private BlockRenderer contentRenderer = mock(BlockRenderer.class);
46   
47    private ComponentManager componentManager = mock(ComponentManager.class);
48   
 
49  1 toggle @Test
50    public void constructorCallsSuper()
51    {
52  1 String id = "gallery";
53  1 Map<String, String> parameters = Collections.singletonMap("width", "300px");
54  1 boolean inline = true;
55  1 ExpandedMacroBlock expandedMacroBlock = new ExpandedMacroBlock(id, parameters, contentRenderer, inline);
56  1 assertEquals(id, expandedMacroBlock.getId());
57  1 assertEquals(parameters, expandedMacroBlock.getParameters());
58  1 assertEquals(inline, expandedMacroBlock.isInline());
59    }
60   
 
61  1 toggle @Test
62    public void getContentWrapsChildNodesInXDOM()
63    {
64  1 ExpandedMacroBlock expandedMacroBlock =
65    new ExpandedMacroBlock("gallery", Collections.<String, String>emptyMap(), this.contentRenderer, false);
66   
67  1 expandedMacroBlock.getContent();
68   
69  1 ArgumentCaptor<Block> block = ArgumentCaptor.forClass(Block.class);
70  1 verify(this.contentRenderer).render(block.capture(), any(WikiPrinter.class));
71  1 assertTrue(block.getValue() instanceof XDOM);
72  1 assertEquals(0, block.getValue().getChildren().size());
73    }
74   
 
75  1 toggle @Test
76    public void getContentUsesChildXDOM()
77    {
78  1 XDOM content = new XDOM(Collections.<Block>emptyList());
79  1 ExpandedMacroBlock expandedMacroBlock =
80    new ExpandedMacroBlock("gallery", Collections.<String, String>emptyMap(), this.contentRenderer, false);
81  1 expandedMacroBlock.addChild(content);
82   
83  1 expandedMacroBlock.getContent();
84   
85  1 verify(this.contentRenderer).render(same(content), any(WikiPrinter.class));
86    }
87   
 
88  1 toggle @Test
89    public void getContentUsesAnotherBlockRenderer() throws Exception
90    {
91  1 ExpandedMacroBlock expandedMacroBlock = new ExpandedMacroBlock("gallery",
92    Collections.<String, String>emptyMap(), this.contentRenderer, false, this.componentManager);
93  1 XDOM parent = new XDOM(Collections.singletonList(expandedMacroBlock));
94  1 parent.getMetaData().addMetaData(MetaData.SYNTAX, Syntax.MARKDOWN_1_1);
95   
96  1 BlockRenderer markdownRenderer = mock(BlockRenderer.class);
97  1 when(this.componentManager.hasComponent(BlockRenderer.class, Syntax.MARKDOWN_1_1.toIdString()))
98    .thenReturn(true);
99  1 when(this.componentManager.getInstance(BlockRenderer.class, Syntax.MARKDOWN_1_1.toIdString()))
100    .thenReturn(markdownRenderer);
101   
102  1 expandedMacroBlock.getContent();
103   
104  1 verify(markdownRenderer).render(any(XDOM.class), any(WikiPrinter.class));
105  1 verify(this.contentRenderer, never()).render(any(XDOM.class), any(WikiPrinter.class));
106    }
107    }