Clover icon

java-junit-xml-merger 1.0.1

  1. Project Clover database Mi Okt 4 2017 15:38:24 MESZ
  2. Package io.codeclou.java.junit.xml.merger

File JunitXmlParserTest.java

 

Code metrics

0
57
9
1
128
92
9
0,16
6,33
9
1

Classes

Class Line # Actions
JunitXmlParserTest 35 57 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * MIT License
3    *
4    * Copyright (c) 2017 Bernhard Grünewaldt
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy
7    * of this software and associated documentation files (the "Software"), to deal
8    * in the Software without restriction, including without limitation the rights
9    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10    * copies of the Software, and to permit persons to whom the Software is
11    * furnished to do so, subject to the following conditions:
12    *
13    * The above copyright notice and this permission notice shall be included in all
14    * copies or substantial portions of the Software.
15    *
16    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18    * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19    * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21    * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22    * SOFTWARE.
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   
 
35    public class JunitXmlParserTest {
36   
 
37  2 toggle private File getTestFile(String filename) {
38  2 ClassLoader classLoader = getClass().getClassLoader();
39  2 return new File(classLoader.getResource(filename).getFile());
40    }
41   
 
42  1 toggle @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   
 
55  1 toggle @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   
 
68  1 toggle @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   
 
77  1 toggle @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   
 
86  1 toggle @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   
 
95  1 toggle @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   
 
104  1 toggle @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   
 
115  1 toggle @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    }