1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
package io.codeclou.java.junit.xml.merger; |
25 |
|
|
26 |
|
import io.codeclou.java.junit.xml.merger.model.TestSuite; |
27 |
|
import org.junit.Test; |
28 |
|
import org.mockito.internal.util.reflection.Whitebox; |
29 |
|
|
30 |
|
import java.io.File; |
31 |
|
|
32 |
|
import static junit.framework.TestCase.assertFalse; |
33 |
|
import static org.junit.Assert.*; |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (66) |
Complexity: 9 |
Complexity Density: 0,16 |
|
35 |
|
public class JunitXmlParserTest { |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
37 |
2 |
private File getTestFile(String filename) {... |
38 |
2 |
ClassLoader classLoader = getClass().getClassLoader(); |
39 |
2 |
return new File(classLoader.getResource(filename).getFile()); |
40 |
|
} |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1PASS
|
|
42 |
1 |
@Test... |
43 |
|
public void testParse() throws Exception { |
44 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
45 |
1 |
TestSuite t = parser.parseTestSuite(getTestFile("sort-model-test.xml")); |
46 |
1 |
assertEquals(Long.valueOf(0L), t.getErrors()); |
47 |
1 |
assertEquals(Long.valueOf(0L), t.getFailures()); |
48 |
1 |
assertEquals(Long.valueOf(0L), t.getSkipped()); |
49 |
1 |
assertEquals(Long.valueOf(3L), t.getTests()); |
50 |
1 |
assertTrue(t.getTime() > 0.028); |
51 |
1 |
assertEquals("ut.io.codeclou.customfield.editor.model.rest.SortModelTest", t.getName()); |
52 |
1 |
assertNotNull(t.getXml()); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1PASS
|
|
55 |
1 |
@Test... |
56 |
|
public void testParseNotSoWellFormed() throws Exception { |
57 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
58 |
1 |
TestSuite t = parser.parseTestSuite(getTestFile("my-not-so-well-formed-component-test.xml")); |
59 |
1 |
assertEquals(Long.valueOf(0L), t.getErrors()); |
60 |
1 |
assertEquals(Long.valueOf(0L), t.getFailures()); |
61 |
1 |
assertEquals(Long.valueOf(0L), t.getSkipped()); |
62 |
1 |
assertEquals(Long.valueOf(0L), t.getTests()); |
63 |
1 |
assertTrue(t.getTime() >= 0.0); |
64 |
1 |
assertEquals("i.am.empty.but.sometimes.that.happens", t.getName()); |
65 |
1 |
assertNotNull(t.getXml()); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1PASS
|
|
68 |
1 |
@Test... |
69 |
|
public void testRunInvalidInput1() throws Exception { |
70 |
1 |
String[] args = {}; |
71 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
72 |
1 |
parser.run(args); |
73 |
1 |
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors"); |
74 |
1 |
assertTrue(hasCmdLineParameterErrors); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1PASS
|
|
77 |
1 |
@Test... |
78 |
|
public void testRunInvalidInput2() throws Exception { |
79 |
1 |
String[] args = {"-i=foo"}; |
80 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
81 |
1 |
parser.run(args); |
82 |
1 |
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors"); |
83 |
1 |
assertTrue(hasCmdLineParameterErrors); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void testRunInvalidInput3() throws Exception { |
88 |
1 |
String[] args = {"-i=foo", "-o=bar.xml"}; |
89 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
90 |
1 |
parser.run(args); |
91 |
1 |
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors"); |
92 |
1 |
assertTrue(hasCmdLineParameterErrors); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1PASS
|
|
95 |
1 |
@Test... |
96 |
|
public void testRunValidInputWithInvalidFolders() throws Exception { |
97 |
1 |
String[] args = {"-i=foo", "-o=?x/bar.xml", "-s=foo"}; |
98 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
99 |
1 |
parser.run(args); |
100 |
1 |
Boolean hasFileNotFoundErrors = (Boolean) Whitebox.getInternalState(parser, "hasFileNotFoundErrors"); |
101 |
1 |
assertTrue(hasFileNotFoundErrors); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1PASS
|
|
104 |
1 |
@Test... |
105 |
|
public void testRunValidInputWithValidFolders() throws Exception { |
106 |
1 |
String[] args = {"-i=src/test/resources/", "-o=output.xml", "-s=foo bar"}; |
107 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
108 |
1 |
parser.run(args); |
109 |
1 |
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors"); |
110 |
1 |
assertFalse(hasCmdLineParameterErrors); |
111 |
1 |
Boolean hasFileNotFoundErrors = (Boolean) Whitebox.getInternalState(parser, "hasFileNotFoundErrors"); |
112 |
1 |
assertFalse(hasFileNotFoundErrors); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1PASS
|
|
115 |
1 |
@Test... |
116 |
|
public void testRunValidInputWithEmptyInputFolder() throws Exception { |
117 |
1 |
File emptyDir = new File("src/test/resources/empty/"); |
118 |
1 |
emptyDir.mkdir(); |
119 |
1 |
String[] args = {"-i=src/test/resources/empty/", "-o=output.xml", "-s=foo bar"}; |
120 |
1 |
JunitXmlParser parser = new JunitXmlParser(); |
121 |
1 |
parser.run(args); |
122 |
1 |
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors"); |
123 |
1 |
assertFalse(hasCmdLineParameterErrors); |
124 |
1 |
Boolean hasFileNotFoundErrors = (Boolean) Whitebox.getInternalState(parser, "hasFileNotFoundErrors"); |
125 |
1 |
assertFalse(hasFileNotFoundErrors); |
126 |
1 |
emptyDir.delete(); |
127 |
|
} |
128 |
|
} |