File tree Expand file tree Collapse file tree 4 files changed +24
-6
lines changed
main/java/io/codeclou/java/junit/xml/merger
java/io/codeclou/java/junit/xml/merger Expand file tree Collapse file tree 4 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 44 <modelVersion >4.0.0</modelVersion >
55 <groupId >io.codeclou</groupId >
66 <artifactId >java-junit-xml-merger</artifactId >
7- <version >1.0.0 </version >
7+ <version >1.0.1 </version >
88 <organization >
99 <name >codeclou.io</name >
1010 <url >http://codeclou.io/</url >
Original file line number Diff line number Diff line change 2727import io .codeclou .java .junit .xml .merger .model .TestSuites ;
2828import org .apache .commons .cli .*;
2929import org .w3c .dom .Document ;
30+ import org .w3c .dom .NamedNodeMap ;
3031import org .w3c .dom .Node ;
3132import org .xml .sax .SAXException ;
3233
@@ -59,12 +60,13 @@ protected TestSuite parseTestSuite(File filename) throws ParserConfigurationExce
5960
6061 public TestSuite transform (Node testSuite ) {
6162 TestSuite t = new TestSuite ();
62- t .setTests (Long .valueOf (testSuite .getAttributes ().getNamedItem ("tests" ).getNodeValue ()));
63- t .setErrors (Long .valueOf (testSuite .getAttributes ().getNamedItem ("errors" ).getNodeValue ()));
64- t .setFailures (Long .valueOf (testSuite .getAttributes ().getNamedItem ("failures" ).getNodeValue ()));
65- t .setSkipped (Long .valueOf (testSuite .getAttributes ().getNamedItem ("skipped" ).getNodeValue ()));
63+ NamedNodeMap attrs = testSuite .getAttributes ();
64+ t .setTests (attrs .getNamedItem ("tests" ) != null ? Long .valueOf (attrs .getNamedItem ("tests" ).getNodeValue ()) : 0L );
65+ t .setErrors (attrs .getNamedItem ("errors" ) != null ? Long .valueOf (testSuite .getAttributes ().getNamedItem ("errors" ).getNodeValue ()) : 0L );
66+ t .setFailures (attrs .getNamedItem ("failures" ) != null ? Long .valueOf (testSuite .getAttributes ().getNamedItem ("failures" ).getNodeValue ()) : 0L );
67+ t .setSkipped (attrs .getNamedItem ("skipped" ) != null ? Long .valueOf (testSuite .getAttributes ().getNamedItem ("skipped" ).getNodeValue ()) : 0L );
6668 t .setName (testSuite .getAttributes ().getNamedItem ("name" ).getNodeValue ());
67- t .setTime (Double .valueOf (testSuite .getAttributes ().getNamedItem ("time" ).getNodeValue ()));
69+ t .setTime (attrs . getNamedItem ( "time" ) != null ? Double .valueOf (testSuite .getAttributes ().getNamedItem ("time" ).getNodeValue ()) : 0.0 );
6870 t .setXml (testSuite );
6971 return t ;
7072 }
Original file line number Diff line number Diff line change @@ -52,6 +52,19 @@ public void testParse() throws Exception {
5252 assertNotNull (t .getXml ());
5353 }
5454
55+ @ Test
56+ public void testParseNotSoWellFormed () throws Exception {
57+ JunitXmlParser parser = new JunitXmlParser ();
58+ TestSuite t = parser .parseTestSuite (getTestFile ("my-not-so-well-formed-component-test.xml" ));
59+ assertEquals (Long .valueOf (0L ), t .getErrors ());
60+ assertEquals (Long .valueOf (0L ), t .getFailures ());
61+ assertEquals (Long .valueOf (0L ), t .getSkipped ());
62+ assertEquals (Long .valueOf (0L ), t .getTests ());
63+ assertTrue (t .getTime () >= 0.0 );
64+ assertEquals ("i.am.empty.but.sometimes.that.happens" , t .getName ());
65+ assertNotNull (t .getXml ());
66+ }
67+
5568 @ Test
5669 public void testRunInvalidInput1 () throws Exception {
5770 String [] args = {};
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <testsuite name =" i.am.empty.but.sometimes.that.happens" >
3+ </testsuite >
You can’t perform that action at this time.
0 commit comments