| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 39 |
|
|
| 40 |
|
@since |
| 41 |
|
@version |
| 42 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0.15 |
|
| 43 |
|
public class ExpandedMacroBlockTest |
| 44 |
|
{ |
| 45 |
|
private BlockRenderer contentRenderer = mock(BlockRenderer.class); |
| 46 |
|
|
| 47 |
|
private ComponentManager componentManager = mock(ComponentManager.class); |
| 48 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 49 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 61 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 75 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 88 |
1 |
@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 |
|
} |