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 java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.junit.Assert; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
29 |
|
import org.xwiki.properties.ConverterManager; |
30 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
31 |
|
|
32 |
|
import com.google.common.reflect.TypeToken; |
33 |
|
|
34 |
|
import static org.junit.Assert.assertEquals; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.36 |
|
41 |
|
public class ListConverterTest extends AbstractComponentTestCase |
42 |
|
{ |
43 |
|
private ConverterManager converterManager; |
44 |
|
|
45 |
|
public List<Integer> listField1; |
46 |
|
|
47 |
|
public List<List<Integer>> listField2; |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
49 |
4 |
@Before... |
50 |
|
@Override |
51 |
|
public void setUp() throws Exception |
52 |
|
{ |
53 |
4 |
super.setUp(); |
54 |
|
|
55 |
4 |
this.converterManager = getComponentManager().getInstance(ConverterManager.class); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
58 |
1 |
@Test... |
59 |
|
public void testConvertFromString() throws SecurityException, NoSuchFieldException |
60 |
|
{ |
61 |
1 |
Assert.assertEquals(Arrays.asList("1", "2", "3"), this.converterManager.convert(List.class, "1, 2, 3")); |
62 |
|
|
63 |
1 |
Assert.assertEquals(Arrays.asList("1", "\n", "2", "\n", "3"), |
64 |
|
this.converterManager.convert(List.class, "1,\n 2,\n 3")); |
65 |
|
|
66 |
1 |
Assert.assertEquals(Arrays.asList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)), |
67 |
|
this.converterManager.convert(ListConverterTest.class.getField("listField1").getGenericType(), "1, 2, 3")); |
68 |
|
|
69 |
1 |
Assert.assertEquals(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6)), this.converterManager |
70 |
|
.convert(ListConverterTest.class.getField("listField2").getGenericType(), "'\\'1\\', 2, 3', \"4, 5, 6\"")); |
71 |
|
|
72 |
1 |
Assert.assertEquals(Arrays.asList("1:2"), this.converterManager.convert(List.class, "1:2")); |
73 |
|
|
74 |
1 |
assertEquals(Arrays.asList(1, 2, 3), |
75 |
|
this.converterManager.convert(new DefaultParameterizedType(null, List.class, Integer.class), "1, 2, 3")); |
76 |
|
|
77 |
1 |
assertEquals(Arrays.asList(1, 2, 3), this.converterManager.convert(new TypeToken<List<? extends Integer>>() |
78 |
|
{ |
79 |
|
}.getType(), "1, 2, 3")); |
80 |
|
|
81 |
1 |
assertEquals(Arrays.asList("1", "2", "3"), this.converterManager.convert(new TypeToken<List<?>>() |
82 |
|
{ |
83 |
|
}.getType(), "1, 2, 3")); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void testConvertFromIterable() throws SecurityException |
88 |
|
{ |
89 |
1 |
assertEquals(Arrays.asList(1, 2, 3), this.converterManager |
90 |
|
.convert(new DefaultParameterizedType(null, List.class, Integer.class), Arrays.asList("1", "2", "3"))); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
93 |
1 |
@Test... |
94 |
|
public void testConvertFromArray() throws SecurityException |
95 |
|
{ |
96 |
1 |
assertEquals(Arrays.asList(1, 2, 3), this.converterManager |
97 |
|
.convert(new DefaultParameterizedType(null, List.class, Integer.class), new String[] { "1", "2", "3" })); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
100 |
1 |
@Test... |
101 |
|
public void testConvertFromList() |
102 |
|
{ |
103 |
1 |
List<String> expect = Arrays.asList("1", "2", "3"); |
104 |
|
|
105 |
1 |
Assert.assertSame(expect, this.converterManager.convert(List.class, expect)); |
106 |
|
} |
107 |
|
} |