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

File DefaultMacroContentParserTest.java

 

Code metrics

0
10
3
1
96
59
3
0.3
3.33
3
1

Classes

Class Line # Actions
DefaultMacroContentParserTest 48 10 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.rendering.internal.macro;
21   
22    import java.io.Reader;
23    import java.util.Arrays;
24    import java.util.Collections;
25   
26    import org.junit.Assert;
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.block.MacroBlock;
32    import org.xwiki.rendering.block.ParagraphBlock;
33    import org.xwiki.rendering.block.WordBlock;
34    import org.xwiki.rendering.block.XDOM;
35    import org.xwiki.rendering.macro.MacroContentParser;
36    import org.xwiki.rendering.parser.Parser;
37    import org.xwiki.rendering.syntax.Syntax;
38    import org.xwiki.rendering.syntax.SyntaxType;
39    import org.xwiki.rendering.transformation.MacroTransformationContext;
40    import org.xwiki.rendering.transformation.RenderingContext;
41    import org.xwiki.test.annotation.ComponentList;
42    import org.xwiki.test.mockito.MockitoComponentManagerRule;
43   
44    import static org.mockito.ArgumentMatchers.any;
45    import static org.mockito.Mockito.when;
46   
47    @ComponentList({ DefaultMacroContentParser.class })
 
48    public class DefaultMacroContentParserTest
49    {
50    @Rule
51    public final MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
52   
53    private MacroTransformationContext macroContext = new MacroTransformationContext();
54   
55    private Parser mockParser;
56   
57    private MacroContentParser macroContentParser;
58   
 
59  2 toggle @Before
60    public void setUp() throws Exception
61    {
62  2 this.componentManager.registerMockComponent(RenderingContext.class);
63   
64  2 Syntax testSyntax = new Syntax(new SyntaxType("test", "test"), "1.0");
65   
66  2 this.macroContext = new MacroTransformationContext();
67  2 this.macroContext.setSyntax(testSyntax);
68   
69  2 this.mockParser = this.componentManager.registerMockComponent(Parser.class, testSyntax.toIdString());
70   
71  2 this.macroContentParser = this.componentManager.getInstance(MacroContentParser.class);
72    }
73   
74    // Tests
75   
 
76  1 toggle @Test
77    public void testParseInline() throws Exception
78    {
79  1 when(this.mockParser.parse(any(Reader.class))).thenReturn(
80    new XDOM(Arrays.<Block>asList(new ParagraphBlock(Arrays.<Block>asList(new WordBlock("word"))))));
81   
82  1 Assert.assertEquals(new XDOM(Arrays.<Block>asList(new WordBlock("word"))),
83    this.macroContentParser.parse("content", this.macroContext, false, true));
84    }
85   
 
86  1 toggle @Test
87    public void testParseInlineWithStandaloneMacro() throws Exception
88    {
89  1 when(this.mockParser.parse(any(Reader.class))).thenReturn(
90    new XDOM(Arrays.<Block>asList(new MacroBlock("macro", Collections.EMPTY_MAP, null, false))));
91   
92  1 Assert.assertEquals(
93    new XDOM(Arrays.<Block>asList(new MacroBlock("macro", Collections.EMPTY_MAP, null, true))),
94    this.macroContentParser.parse("content", this.macroContext, false, true));
95    }
96    }