Search in sources :

Example 1 with StringReaderMatcher

use of org.xwiki.test.mockito.StringReaderMatcher in project xwiki-platform by xwiki.

the class RenderingScriptServiceTest method parseAndRender.

@Test
public void parseAndRender() throws Exception {
    Parser parser = this.mocker.registerMockComponent(Parser.class, "plain/1.0");
    when(parser.parse(argThat(new StringReaderMatcher("some [[TODO]] stuff")))).thenReturn(new XDOM(Collections.<Block>emptyList()));
    BlockRenderer blockRenderer = this.mocker.registerMockComponent(BlockRenderer.class, "xwiki/2.0");
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            WikiPrinter printer = (WikiPrinter) invocationOnMock.getArguments()[1];
            printer.print("some ~[~[TODO]] stuff");
            return null;
        }
    }).when(blockRenderer).render(any(XDOM.class), any());
    XDOM xdom = this.mocker.getComponentUnderTest().parse("some [[TODO]] stuff", "plain/1.0");
    assertEquals("some ~[~[TODO]] stuff", this.mocker.getComponentUnderTest().render(xdom, "xwiki/2.0"));
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StringReaderMatcher(org.xwiki.test.mockito.StringReaderMatcher) Block(org.xwiki.rendering.block.Block) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) Parser(org.xwiki.rendering.parser.Parser) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Block (org.xwiki.rendering.block.Block)1 XDOM (org.xwiki.rendering.block.XDOM)1 Parser (org.xwiki.rendering.parser.Parser)1 BlockRenderer (org.xwiki.rendering.renderer.BlockRenderer)1 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)1 StringReaderMatcher (org.xwiki.test.mockito.StringReaderMatcher)1