| 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.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 |
|
@link |
| 36 |
|
|
| 37 |
|
@version |
| 38 |
|
|
| |
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 39 |
|
public class SyntaxConverterTest |
| 40 |
|
{ |
| 41 |
|
@Rule |
| 42 |
|
public MockitoComponentMockingRule<Converter<Syntax>> mocker = new MockitoComponentMockingRule<Converter<Syntax>>( |
| 43 |
|
SyntaxConverter.class); |
| 44 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 45 |
1 |
@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 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
| 55 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 69 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 76 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 83 |
1 |
@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 |
|
} |