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

File SyntaxConverterTest.java

 

Code metrics

0
16
5
1
89
55
6
0.38
3.2
5
1.2

Classes

Class Line # Actions
SyntaxConverterTest 39 16 0% 6 1
0.9523809695.2%
 

Contributing tests

This file is covered by 5 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.syntax;
21   
22    import org.junit.Assert;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.properties.converter.ConversionException;
26    import org.xwiki.properties.converter.Converter;
27    import org.xwiki.rendering.parser.ParseException;
28    import org.xwiki.rendering.syntax.Syntax;
29    import org.xwiki.rendering.syntax.SyntaxFactory;
30    import org.xwiki.test.mockito.MockitoComponentMockingRule;
31   
32    import static org.mockito.Mockito.when;
33   
34    /**
35    * Unit tests for {@link SyntaxConverter}.
36    *
37    * @version $Id: 3a88f740de2cee6ab325158dc15704d8272dd330 $
38    */
 
39    public class SyntaxConverterTest
40    {
41    @Rule
42    public MockitoComponentMockingRule<Converter<Syntax>> mocker = new MockitoComponentMockingRule<Converter<Syntax>>(
43    SyntaxConverter.class);
44   
 
45  1 toggle @Test
46    public void convertToSyntaxObject() throws Exception
47    {
48  1 final SyntaxFactory factory = this.mocker.getInstance(SyntaxFactory.class);
49  1 when(factory.createSyntaxFromIdString("xwiki/2.1")).thenReturn(Syntax.XWIKI_2_1);
50   
51  1 Syntax syntax = this.mocker.getComponentUnderTest().convert(Syntax.class, "xwiki/2.1");
52  1 Assert.assertEquals(Syntax.XWIKI_2_1, syntax);
53    }
54   
 
55  1 toggle @Test
56    public void convertToSyntaxObjectWhenUnknownSyntax() throws Exception
57    {
58  1 final SyntaxFactory factory = this.mocker.getInstance(SyntaxFactory.class);
59  1 when(factory.createSyntaxFromIdString("invalid")).thenThrow(new ParseException("invalid syntax"));
60   
61  1 try {
62  1 this.mocker.getComponentUnderTest().convert(Syntax.class, "invalid");
63  0 Assert.fail("Should have thrown ConversionException");
64    } catch (ConversionException expected) {
65  1 Assert.assertEquals("Unknown syntax [invalid]", expected.getMessage());
66    }
67    }
68   
 
69  1 toggle @Test
70    public void convertToSyntaxObjectWhenNull() throws Exception
71    {
72  1 Syntax syntax = this.mocker.getComponentUnderTest().convert(Syntax.class, null);
73  1 Assert.assertNull(syntax);
74    }
75   
 
76  1 toggle @Test
77    public void convertToString() throws Exception
78    {
79  1 String syntaxId = this.mocker.getComponentUnderTest().convert(String.class, Syntax.XWIKI_2_1);
80  1 Assert.assertEquals(Syntax.XWIKI_2_1.toIdString(), syntaxId);
81    }
82   
 
83  1 toggle @Test
84    public void convertToStringWhenNull() throws Exception
85    {
86  1 String syntaxId = this.mocker.getComponentUnderTest().convert(String.class, null);
87  1 Assert.assertNull(syntaxId);
88    }
89    }