1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 }) |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.3 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
59 |
2 |
@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 |
|
|
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
76 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
86 |
1 |
@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 |
|
} |