1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.properties.internal.converter; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.component.manager.ComponentLookupException; |
26 |
|
import org.xwiki.properties.ConverterManager; |
27 |
|
import org.xwiki.properties.converter.ConversionException; |
28 |
|
import org.xwiki.properties.internal.DefaultConverterManager; |
29 |
|
import org.xwiki.test.annotation.AllComponents; |
30 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
31 |
|
|
32 |
|
|
33 |
|
@link |
34 |
|
|
35 |
|
@version |
36 |
|
|
37 |
|
@AllComponents |
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.5 |
|
38 |
|
public class ConvertUtilsConverterTest |
39 |
|
{ |
40 |
|
@Rule |
41 |
|
public MockitoComponentMockingRule<ConverterManager> mocker = new MockitoComponentMockingRule<ConverterManager>( |
42 |
|
DefaultConverterManager.class); |
43 |
|
|
44 |
|
public Integer[] field; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
46 |
1 |
@Test... |
47 |
|
public void testConvert() throws SecurityException, ComponentLookupException |
48 |
|
{ |
49 |
1 |
Assert.assertEquals(Integer.valueOf(42), this.mocker.getComponentUnderTest().convert(Integer.class, "42")); |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
52 |
1 |
@Test... |
53 |
|
public void testConvertArrays() throws SecurityException, NoSuchFieldException, ComponentLookupException |
54 |
|
{ |
55 |
1 |
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, this.mocker.getComponentUnderTest().<int[]>convert(int[].class, "1, 2, 3")); |
56 |
|
|
57 |
1 |
Assert.assertArrayEquals(new Integer[] { 1, 2, 3 }, |
58 |
|
this.mocker.getComponentUnderTest().<Integer[]>convert(Integer[].class, "1, 2, 3")); |
59 |
|
|
60 |
1 |
Assert.assertArrayEquals(new Integer[] { 1, 2, 3 }, this.mocker.getComponentUnderTest().<Integer[]>convert( |
61 |
|
ConvertUtilsConverterTest.class.getField("field").getGenericType(), "1, 2, 3")); |
62 |
|
} |
63 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void testConvertWhenNoConverterAvailable() throws ComponentLookupException |
66 |
|
{ |
67 |
1 |
try { |
68 |
1 |
this.mocker.getComponentUnderTest().convert(ConvertUtilsConverter.class, ""); |
69 |
0 |
Assert.fail("Should have thrown an exception here"); |
70 |
|
} catch (ConversionException expected) { |
71 |
1 |
Assert.assertEquals("Failed to find a Converter to convert from [java.lang.String] to " + "[" |
72 |
|
+ ConvertUtilsConverter.class.getName() + "]", expected.getMessage()); |
73 |
|
} |
74 |
|
} |
75 |
|
} |