1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.test.integration; |
21 |
|
|
22 |
|
import java.io.InputStream; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collection; |
25 |
|
import java.util.regex.Pattern; |
26 |
|
|
27 |
|
import org.reflections.Reflections; |
28 |
|
import org.reflections.scanners.ResourcesScanner; |
29 |
|
import org.reflections.util.ClasspathHelper; |
30 |
|
import org.reflections.util.ConfigurationBuilder; |
31 |
|
import org.reflections.util.FilterBuilder; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 90% |
Uncovered Elements: 3 (30) |
Complexity: 5 |
Complexity Density: 0.2 |
|
39 |
|
public class TestDataGenerator |
40 |
|
{ |
41 |
|
private TestDataParser parser = new TestDataParser(); |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
43 |
3 |
public Collection<TestConfiguration> generateData(String testPackage, String pattern)... |
44 |
|
{ |
45 |
3 |
Reflections reflections = |
46 |
|
new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()) |
47 |
|
.setUrls(ClasspathHelper.forPackage("")) |
48 |
|
.filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix(testPackage)))); |
49 |
|
|
50 |
3 |
Collection<TestConfiguration> data = new ArrayList<TestConfiguration>(); |
51 |
3 |
for (String testResourceName : reflections.getResources(Pattern.compile(pattern))) { |
52 |
15 |
data.addAll(parseSingleResource(testResourceName)); |
53 |
|
} |
54 |
|
|
55 |
3 |
return data; |
56 |
|
} |
57 |
|
|
|
|
| 85.7% |
Uncovered Elements: 3 (21) |
Complexity: 3 |
Complexity Density: 0.16 |
|
58 |
15 |
private Collection<TestConfiguration> parseSingleResource(String testResourceName)... |
59 |
|
{ |
60 |
15 |
String resourceName = "/" + testResourceName; |
61 |
15 |
TestResourceData data; |
62 |
15 |
try { |
63 |
15 |
InputStream source = getClass().getResourceAsStream(resourceName); |
64 |
15 |
if (source == null) { |
65 |
0 |
throw new RuntimeException("Failed to find test file [" + resourceName + "]"); |
66 |
|
} |
67 |
15 |
data = this.parser.parse(source, resourceName); |
68 |
|
} catch (Exception e) { |
69 |
0 |
throw new RuntimeException("Failed to read test data from [" + resourceName + "]", e); |
70 |
|
} |
71 |
|
|
72 |
15 |
Collection<TestConfiguration> result = new ArrayList<TestConfiguration>(); |
73 |
15 |
for (InputTestConfiguration inputConfiguration : data.inputs) { |
74 |
22 |
for (ExpectTestConfiguration expectConfiguration : data.expects) { |
75 |
32 |
TestConfiguration testConfiguration = new TestConfiguration(); |
76 |
|
|
77 |
32 |
testConfiguration.resourceName = data.resourceName; |
78 |
|
|
79 |
32 |
testConfiguration.configuration = data.configuration; |
80 |
|
|
81 |
|
|
82 |
32 |
testConfiguration.inputConfiguration = new InputTestConfiguration(inputConfiguration); |
83 |
|
|
84 |
|
|
85 |
32 |
testConfiguration.expectConfiguration = new ExpectTestConfiguration(expectConfiguration); |
86 |
|
|
87 |
|
|
88 |
32 |
testConfiguration.name = |
89 |
|
computeTestName(testResourceName, inputConfiguration.typeId, expectConfiguration.typeId); |
90 |
|
|
91 |
|
|
92 |
32 |
result.add(testConfiguration); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
15 |
return result; |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
32 |
private String computeTestName(String prefix, String parserId, String targetSyntaxId)... |
100 |
|
{ |
101 |
|
|
102 |
|
|
103 |
32 |
return prefix + " [" + parserId + ", " + targetSyntaxId + "]"; |
104 |
|
} |
105 |
|
} |