Clover icon

java-junit-xml-merger 1.0.0

  1. Project Clover database Sa Sep 9 2017 13:37:19 MESZ
  2. Package io.codeclou.java.junit.xml.merger

File JunitXmlParserTest.java

 

Code metrics

0
48
8
1
115
80
8
0,17
6
8
1

Classes

Class Line # Actions
JunitXmlParserTest 35 48 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 7 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  1 toggle private File getTestFile(String filename) {
38  1 ClassLoader classLoader = getClass().getClassLoader();
39  1 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 testRunInvalidInput1() throws Exception {
57  1 String[] args = {};
58  1 JunitXmlParser parser = new JunitXmlParser();
59  1 parser.run(args);
60  1 Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
61  1 assertTrue(hasCmdLineParameterErrors);
62    }
63   
 
64  1 toggle @Test
65    public void testRunInvalidInput2() throws Exception {
66  1 String[] args = {"-i=foo"};
67  1 JunitXmlParser parser = new JunitXmlParser();
68  1 parser.run(args);
69  1 Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
70  1 assertTrue(hasCmdLineParameterErrors);
71    }
72   
 
73  1 toggle @Test
74    public void testRunInvalidInput3() throws Exception {
75  1 String[] args = {"-i=foo", "-o=bar.xml"};
76  1 JunitXmlParser parser = new JunitXmlParser();
77  1 parser.run(args);
78  1 Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
79  1 assertTrue(hasCmdLineParameterErrors);
80    }
81   
 
82  1 toggle @Test
83    public void testRunValidInputWithInvalidFolders() throws Exception {
84  1 String[] args = {"-i=foo", "-o=?x/bar.xml", "-s=foo"};
85  1 JunitXmlParser parser = new JunitXmlParser();
86  1 parser.run(args);
87  1 Boolean hasFileNotFoundErrors = (Boolean) Whitebox.getInternalState(parser, "hasFileNotFoundErrors");
88  1 assertTrue(hasFileNotFoundErrors);
89    }
90   
 
91  1 toggle @Test
92    public void testRunValidInputWithValidFolders() throws Exception {
93  1 String[] args = {"-i=src/test/resources/", "-o=output.xml", "-s=foo bar"};
94  1 JunitXmlParser parser = new JunitXmlParser();
95  1 parser.run(args);
96  1 Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
97  1 assertFalse(hasCmdLineParameterErrors);
98  1 Boolean hasFileNotFoundErrors = (Boolean) Whitebox.getInternalState(parser, "hasFileNotFoundErrors");
99  1 assertFalse(hasFileNotFoundErrors);
100    }
101   
 
102  1 toggle @Test
103    public void testRunValidInputWithEmptyInputFolder() throws Exception {
104  1 File emptyDir = new File("src/test/resources/empty/");
105  1 emptyDir.mkdir();
106  1 String[] args = {"-i=src/test/resources/empty/", "-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  1 emptyDir.delete();
114    }
115    }