1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.parser

File DefaultContentParserTest.java

 
parseWhenNoParser: Failed to find a parser for syntax [XWiki 2.1]
 

Code metrics

0
14
5
1
111
72
5
0.36
2.8
5
1

Classes

Class Line # Actions
DefaultContentParserTest 58 14 0% 5 5
0.736842173.7%
 

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.internal.parser;
21   
22    import static org.hamcrest.CoreMatchers.any;
23    import static org.hamcrest.CoreMatchers.equalTo;
24    import static org.hamcrest.CoreMatchers.nullValue;
25    import static org.junit.Assert.assertEquals;
26    import static org.junit.Assert.assertThat;
27    import static org.mockito.hamcrest.MockitoHamcrest.argThat;
28    import static org.mockito.Mockito.when;
29   
30    import java.io.Reader;
31    import java.util.Collections;
32   
33    import org.junit.Before;
34    import org.junit.Rule;
35    import org.junit.Test;
36    import org.junit.rules.ExpectedException;
37    import org.xwiki.component.internal.ContextComponentManagerProvider;
38    import org.xwiki.component.manager.ComponentLookupException;
39    import org.xwiki.model.reference.DocumentReference;
40    import org.xwiki.model.reference.EntityReferenceSerializer;
41    import org.xwiki.rendering.block.Block;
42    import org.xwiki.rendering.block.XDOM;
43    import org.xwiki.rendering.listener.MetaData;
44    import org.xwiki.rendering.parser.ContentParser;
45    import org.xwiki.rendering.parser.MissingParserException;
46    import org.xwiki.rendering.parser.Parser;
47    import org.xwiki.rendering.syntax.Syntax;
48    import org.xwiki.test.annotation.ComponentList;
49    import org.xwiki.test.mockito.MockitoComponentMockingRule;
50   
51    /**
52    * Unit tests for {@link org.xwiki.rendering.internal.parser.DefaultContentParser}.
53    *
54    * @version $Id: 4cc4a5dcbce6031d26df7f40b3706233f1fcf4cd $
55    * @since 6.0M2
56    */
57    @ComponentList(ContextComponentManagerProvider.class)
 
58    public class DefaultContentParserTest
59    {
60    @Rule
61    public final MockitoComponentMockingRule<ContentParser> mocker =
62    new MockitoComponentMockingRule<>(DefaultContentParser.class);
63   
64    @Rule
65    public ExpectedException thrown = ExpectedException.none();
66   
67    private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("wiki", "space", "page");
68    private static final String SOURCE = "wiki:space.page";
69   
 
70  4 toggle @Before
71    public void configure() throws Exception
72    {
73  4 Parser parser = mocker.registerMockComponent(Parser.class, Syntax.PLAIN_1_0.toIdString());
74  4 when(parser.parse(argThat(any(Reader.class)))).thenReturn(new XDOM(Collections.<Block>emptyList()));
75   
76  4 EntityReferenceSerializer<String> serializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
77  4 when(serializer.serialize(DOCUMENT_REFERENCE)).thenReturn(SOURCE);
78    }
79   
 
80  1 toggle @Test
81    public void parseHasNoMetadataSource() throws Exception
82    {
83  1 XDOM xdom = mocker.getComponentUnderTest().parse("", Syntax.PLAIN_1_0);
84   
85  1 assertThat(xdom.getMetaData().getMetaData(MetaData.SOURCE), nullValue());
86    }
87   
 
88  1 toggle @Test
89    public void parseIsAddingMetadataSource() throws Exception
90    {
91  1 XDOM xdom = mocker.getComponentUnderTest().parse("", Syntax.PLAIN_1_0, DOCUMENT_REFERENCE);
92   
93  1 assertThat(xdom.getMetaData().getMetaData(MetaData.SOURCE), equalTo(SOURCE));
94    }
95   
 
96  0 toggle @Test
97    public void parseWhenNoParser() throws Exception
98    {
99  0 thrown.expect(MissingParserException.class);
100  0 thrown.expectMessage("Failed to find a parser for syntax [XWiki 2.1]");
101  0 thrown.expectCause(any(ComponentLookupException.class));
102  0 Test failure here mocker.getComponentUnderTest().parse("", Syntax.XWIKI_2_1, DOCUMENT_REFERENCE);
103    }
104   
 
105  1 toggle @Test
106    public void parseWhenNullSource() throws Exception
107    {
108  1 XDOM xdom = mocker.getComponentUnderTest().parse(null, Syntax.PLAIN_1_0);
109  1 assertEquals(0, xdom.getChildren().size());
110    }
111    }