View Javadoc
1   package org.apache.maven.plugins.surefire.report;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.ByteArrayInputStream;
23  import java.io.File;
24  import java.io.InputStream;
25  import java.io.InputStreamReader;
26  import java.util.Collection;
27  import java.util.List;
28  
29  import org.junit.Test;
30  
31  import static org.junit.Assert.*;
32  import static org.junit.Assume.assumeTrue;
33  import static org.hamcrest.CoreMatchers.*;
34  import static org.hamcrest.MatcherAssert.assertThat;
35  
36  /**
37   * @author Kristian Rosenvold
38   */
39  public class TestSuiteXmlParserTest
40  {
41      private static final String[] linePatterns = { "at org.apache.Test.", "at org.apache.Test$" };
42  
43      @Test
44      public void testParse()
45          throws Exception
46      {
47          TestSuiteXmlParser testSuiteXmlParser = new TestSuiteXmlParser();
48          String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
49              "<testsuite failures=\"4\" time=\"0.005\" errors=\"0\" skipped=\"0\" tests=\"4\" name=\"wellFormedXmlFailures.TestSurefire3\">\n"
50              +
51              "  <properties>\n" +
52              "    <property name=\"java.runtime.name\" value=\"Java(TM) SE Runtime Environment\"/>\n" +
53              "    <property name=\"sun.cpu.isalist\" value=\"amd64\"/>\n" +
54              "  </properties>\n" +
55              "  <testcase time=\"0.005\" classname=\"wellFormedXmlFailures.TestSurefire3\" name=\"testLower\">\n" +
56              "    <failure message=\"&lt;\" type=\"junit.framework.AssertionFailedError\"><![CDATA[junit.framework.AssertionFailedError: <\n"
57              +
58              "\tat junit.framework.Assert.fail(Assert.java:47)\n" +
59              "\tat wellFormedXmlFailures.TestSurefire3.testLower(TestSurefire3.java:30)\n" +
60              "]]></failure>\n" +
61              "  </testcase>\n" +
62              "  <testcase time=\"0\" classname=\"wellFormedXmlFailures.TestSurefire3\" name=\"testU0000\">\n" +
63              "    <failure message=\"&amp;0#;\" type=\"junit.framework.AssertionFailedError\">junit.framework.AssertionFailedError:  \n"
64              +
65              "\tat junit.framework.Assert.fail(Assert.java:47)\n" +
66              "\tat wellFormedXmlFailures.TestSurefire3.testU0000(TestSurefire3.java:40)\n" +
67              "</failure>\n" +
68              "  </testcase>\n" +
69              "  <testcase time=\"0\" classname=\"wellFormedXmlFailures.TestSurefire3\" name=\"testGreater\">\n" +
70              "    <failure message=\"&gt;\" type=\"junit.framework.AssertionFailedError\">junit.framework.AssertionFailedError: >\n"
71              +
72              "\tat junit.framework.Assert.fail(Assert.java:47)\n" +
73              "\tat wellFormedXmlFailures.TestSurefire3.testGreater(TestSurefire3.java:35)\n" +
74              "</failure>\n" +
75              "  </testcase>\n" +
76              "  <testcase time=\"0\" classname=\"wellFormedXmlFailures.TestSurefire3\" name=\"testQuote\">\n" +
77              "    <failure message=\"&quot;\" type=\"junit.framework.AssertionFailedError\">junit.framework.AssertionFailedError: \"\n"
78              +
79              "\tat junit.framework.Assert.fail(Assert.java:47)\n" +
80              "\tat wellFormedXmlFailures.TestSurefire3.testQuote(TestSurefire3.java:25)\n" +
81              "</failure>\n" +
82              "  </testcase>\n" +
83              "</testsuite>";
84          InputStream byteArrayIs = new ByteArrayInputStream( xml.getBytes() );
85          List<ReportTestSuite> parse = testSuiteXmlParser.parse( new InputStreamReader(byteArrayIs, "UTF-8") );
86          assertThat( parse.size(), is( 1 ) );
87          ReportTestSuite report = parse.get( 0 );
88          assertThat( report.getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );
89          assertThat( report.getName(), is( "TestSurefire3" ) );
90          assertThat( report.getPackageName(), is( "wellFormedXmlFailures" ) );
91          assertThat( report.getNumberOfTests(), is( 4 ) );
92          assertThat( report.getNumberOfSkipped(), is( 0 ) );
93          assertThat( report.getNumberOfErrors(), is( 0 ) );
94          assertThat( report.getNumberOfFailures(), is( 4 ) );
95          assertThat( report.getNumberOfFlakes(), is( 0 ) );
96          assertThat( report.getTimeElapsed(), is( 0.005f ) );
97          assertThat( report.getTestCases().size(), is( 4 ) );
98  
99          List<ReportTestCase> tests = report.getTestCases();
100         assertThat( tests.get( 0 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );
101         assertThat( tests.get( 0 ).getName(), is( "testLower" ) );
102         assertThat( tests.get( 0 ).getFailureDetail(),
103                     is( "junit.framework.AssertionFailedError: <\n"
104                             + "\tat junit.framework.Assert.fail(Assert.java:47)\n"
105                             + "\tat wellFormedXmlFailures.TestSurefire3.testLower(TestSurefire3.java:30)\n" ) );
106         assertThat( tests.get( 0 ).getClassName(), is( "TestSurefire3" ) );
107         assertThat( tests.get( 0 ).getTime(), is( 0.005f ) );
108         assertThat( tests.get( 0 ).getFailureErrorLine(), is( "30" ) );
109         assertThat( tests.get( 0 ).getFailureMessage(), is( "<" ) );
110         assertThat( tests.get( 0 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testLower" ) );
111         assertThat( tests.get( 0 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );
112 
113         assertThat( tests.get( 1 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );
114         assertThat( tests.get( 1 ).getName(), is( "testU0000" ) );
115         assertThat( tests.get( 1 ).getFailureDetail(),
116                     is( "junit.framework.AssertionFailedError:  \n"
117                             + "\tat junit.framework.Assert.fail(Assert.java:47)\n"
118                             + "\tat wellFormedXmlFailures.TestSurefire3.testU0000(TestSurefire3.java:40)\n" ) );
119         assertThat( tests.get( 1 ).getClassName(), is( "TestSurefire3" ) );
120         assertThat( tests.get( 1 ).getTime(), is( 0f ) );
121         assertThat( tests.get( 1 ).getFailureErrorLine(), is( "40" ) );
122         assertThat( tests.get( 1 ).getFailureMessage(), is( "&0#;" ) );
123         assertThat( tests.get( 1 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testU0000" ) );
124         assertThat( tests.get( 1 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );
125 
126         assertThat( tests.get( 2 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );
127         assertThat( tests.get( 2 ).getName(), is( "testGreater" ) );
128         assertThat( tests.get( 2 ).getFailureDetail(),
129                     is( "junit.framework.AssertionFailedError: >\n"
130                             + "\tat junit.framework.Assert.fail(Assert.java:47)\n"
131                             + "\tat wellFormedXmlFailures.TestSurefire3.testGreater(TestSurefire3.java:35)\n" ) );
132         assertThat( tests.get( 2 ).getClassName(), is( "TestSurefire3" ) );
133         assertThat( tests.get( 2 ).getTime(), is( 0f ) );
134         assertThat( tests.get( 2 ).getFailureErrorLine(), is( "35" ) );
135         assertThat( tests.get( 2 ).getFailureMessage(), is( ">" ) );
136         assertThat( tests.get( 2 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testGreater" ) );
137         assertThat( tests.get( 2 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );
138 
139         assertThat( tests.get( 3 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );
140         assertThat( tests.get( 3 ).getName(), is( "testQuote" ) );
141         assertThat( tests.get( 3 ).getFailureDetail(),
142                     is( "junit.framework.AssertionFailedError: \"\n"
143                             + "\tat junit.framework.Assert.fail(Assert.java:47)\n"
144                             + "\tat wellFormedXmlFailures.TestSurefire3.testQuote(TestSurefire3.java:25)\n" ) );
145         assertThat( tests.get( 3 ).getClassName(), is( "TestSurefire3" ) );
146         assertThat( tests.get( 3 ).getTime(), is( 0f ) );
147         assertThat( tests.get( 3 ).getFailureErrorLine(), is( "25" ) );
148         assertThat( tests.get( 3 ).getFailureMessage(), is( "\"" ) );
149         assertThat( tests.get( 3 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testQuote" ) );
150         assertThat( tests.get( 3 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );
151     }
152 
153     @Test
154     public void testParser()
155         throws Exception
156     {
157         TestSuiteXmlParser parser = new TestSuiteXmlParser();
158 
159         Collection<ReportTestSuite> oldResult = parser.parse(
160             "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" );
161 
162         assertNotNull( oldResult );
163 
164         assertEquals( 1, oldResult.size() );
165         ReportTestSuite next = oldResult.iterator().next();
166         assertEquals( 2, next.getNumberOfTests() );
167     }
168 
169     @Test
170     public void successfulSurefireTestReport()
171         throws Exception
172     {
173         TestSuiteXmlParser parser = new TestSuiteXmlParser();
174         File surefireReport = new File( "src/test/resources/junit-pathWith√úmlaut/TEST-umlautTest.BasicTest.xml" );
175         assumeTrue( surefireReport.isFile() );
176         Collection<ReportTestSuite> suites = parser.parse( surefireReport.getCanonicalPath() );
177         assertNotNull( suites );
178         assertEquals( 1, suites.size() );
179         ReportTestSuite suite = suites.iterator().next();
180         assertThat( suite.getNumberOfTests(), is( 1 ) );
181         assertEquals( 1, suite.getNumberOfTests() );
182         assertEquals( 0, suite.getNumberOfFlakes() );
183         assertEquals( 0, suite.getNumberOfFailures() );
184         assertEquals( 0, suite.getNumberOfErrors() );
185         assertEquals( 0, suite.getNumberOfSkipped() );
186         assertThat( suite.getTimeElapsed(), is( 0.002f ) );
187         assertThat( suite.getFullClassName(), is( "umlautTest.BasicTest" ) );
188         assertThat( suite.getPackageName(), is( "umlautTest" ) );
189         assertThat( suite.getName(), is( "BasicTest" ) );
190         ReportTestCase test = suite.getTestCases().iterator().next();
191         assertFalse( test.hasFailure() );
192         assertNull( test.getFailureDetail() );
193         assertNull( test.getFailureErrorLine() );
194         assertNull( test.getFailureType() );
195         assertThat( test.getTime(), is( 0.002f ) );
196         assertThat( test.getFullClassName(), is( "umlautTest.BasicTest" ) );
197         assertThat( test.getClassName(), is( "BasicTest" ) );
198         assertThat( test.getName(), is( "testSetUp" ) );
199         assertThat( test.getFullName(), is( "umlautTest.BasicTest.testSetUp" ) );
200     }
201 
202     @Test
203     public void testParserHitsFailsafeSummary()
204         throws Exception
205     {
206         TestSuiteXmlParser parser = new TestSuiteXmlParser();
207 
208         parser.parse( "src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml" );
209 
210         assertFalse( parser.isValid() );
211 
212         parser.parse(
213             "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" );
214 
215         assertTrue( parser.isValid() );
216     }
217 
218     @Test
219     public void lastIndexOfPatternOfOrdinalTest()
220     {
221         final StringBuilder stackTrace = new StringBuilder(
222             "\tat org.apache.Test.util(Test.java:60)\n"
223                 + "\tat org.apache.Test.test(Test.java:30)\n"
224                 + "\tat com.sun.Impl.xyz(Impl.java:258)\n" );
225 
226         int[] result = TestSuiteXmlParser.lastIndexOf( stackTrace, linePatterns );
227         assertThat( result[0], is( 40 ) );
228         assertThat( result[1], is( 0 ) );
229         String errorLine = TestSuiteXmlParser.parseErrorLine( stackTrace, "org.apache.Test" );
230         assertThat( errorLine, is( "30" ) );
231     }
232 
233     @Test
234     public void lastIndexOfPatternOfOrdinalTestWithCause()
235     {
236         final StringBuilder stackTrace = new StringBuilder(
237             "\tat org.apache.Test.util(Test.java:60)\n"
238                 + "\tat org.apache.Test.test(Test.java:30)\n"
239                 + "\tat com.sun.Impl.xyz(Impl.java:258)\n"
240                 + "\tat Caused by: java.lang.IndexOutOfBoundsException\n"
241                 + "\tat org.apache.Test.util(Test.java:70)\n" );
242 
243         int[] result = TestSuiteXmlParser.lastIndexOf( stackTrace, linePatterns );
244         assertThat( result[0], is( 40 ) );
245         assertThat( result[1], is( 0 ) );
246         String errorLine = TestSuiteXmlParser.parseErrorLine( stackTrace, "org.apache.Test" );
247         assertThat( errorLine, is( "30" ) );
248     }
249 
250     @Test
251     public void lastIndexOfPatternOfEnclosedTest()
252     {
253         final StringBuilder source = new StringBuilder(
254             "\tat org.apache.Test.util(Test.java:60)\n"
255                 + "\tat org.apache.Test$Nested.test(Test.java:30)\n"
256                 + "\tat com.sun.Impl.xyz(Impl.java:258)\n" );
257 
258         int[] result = TestSuiteXmlParser.lastIndexOf( source, linePatterns );
259         assertThat( result[0], is( 40 ) );
260         assertThat( result[1], is( 1 ) );
261         String errorLine = TestSuiteXmlParser.parseErrorLine( source, "org.apache.Test$Nested" );
262         assertThat( errorLine, is( "30" ) );
263     }
264 
265     @Test
266     public void lastIndexOfPatternOfEnclosedTestWithCause()
267     {
268         final StringBuilder source = new StringBuilder(
269             "\tat org.apache.Test.util(Test.java:60)\n"
270                 + "\tat org.apache.Test$Nested.test(Test.java:30)\n"
271                 + "\tat com.sun.Impl.xyz(Impl.java:258)\n"
272                 + "\tat Caused by: java.lang.IndexOutOfBoundsException\n"
273                 + "\tat org.apache.Test$Nested.util(Test.java:70)\n" );
274 
275         int[] result = TestSuiteXmlParser.lastIndexOf( source, linePatterns );
276         assertThat( result[0], is( 40 ) );
277         assertThat( result[1], is( 1 ) );
278         String errorLine = TestSuiteXmlParser.parseErrorLine( source, "org.apache.Test$Nested" );
279         assertThat( errorLine, is( "30" ) );
280     }
281 
282     @Test
283     public void shouldParserEverythingInOrdinalTest()
284         throws Exception
285     {
286         TestSuiteXmlParser parser = new TestSuiteXmlParser();
287         List<ReportTestSuite> tests =
288             parser.parse( "src/test/resources/fixture/testsuitexmlparser/TEST-surefire.MyTest.xml" );
289         assertTrue( parser.isValid() );
290         assertThat( tests.size(), is( 1 ) );
291         assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );
292         assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );
293         assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );
294         assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );
295         assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );
296         assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );
297         assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );
298         assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );
299         assertTrue( tests.get( 0 ).getTestCases().get( 0 ).hasFailure() );
300         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "13" ) );
301         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(), is( "java.lang.RuntimeException" ) );
302         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );
303         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest" ) );
304         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "test" ) );
305         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest.test" ) );
306         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0.1f ) );
307         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(), is( "this is different message" ) );
308 
309         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),
310                     is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
311         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
312         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
313         + "\tat surefire.MyTest.test(MyTest.java:13)\n"
314         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
315         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
316         + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
317         + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
318         + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
319         + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
320         + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
321         + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
322         + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
323         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
324         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
325         + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
326         + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
327         + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
328         + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
329         + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
330         + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
331         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
332         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
333         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
334         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
335         + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
336         + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
337         + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
338         + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
339         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
340         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
341         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
342         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
343         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" ) );
344     }
345 
346     @Test
347     public void shouldParserEverythingInEnclosedTest()
348         throws Exception
349     {
350         TestSuiteXmlParser parser = new TestSuiteXmlParser();
351         List<ReportTestSuite> tests =
352             parser.parse( "src/test/resources/fixture/testsuitexmlparser/TEST-surefire.MyTest-enclosed.xml" );
353         assertTrue( parser.isValid() );
354         assertThat( tests.size(), is( 1 ) );
355         assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );
356         assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );
357         assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );
358         assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );
359         assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );
360         assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );
361         assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );
362         assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );
363         assertTrue( tests.get( 0 ).getTestCases().get( 0 ).hasFailure() );
364         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "45" ) );
365         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),
366                     is( "java.lang.RuntimeException" ) );
367         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );
368         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest$A" ) );
369         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "t" ) );
370         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest$A.t" ) );
371         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );
372 
373         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),
374                     is( "java.lang.IndexOutOfBoundsException" ) );
375 
376         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),
377                     is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
378         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
379         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
380         + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"
381         + "\tat surefire.MyTest$A.t(MyTest.java:45)\n"
382         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
383         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
384         + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
385         + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
386         + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
387         + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
388         + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
389         + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
390         + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
391         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
392         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
393         + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
394         + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
395         + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
396         + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
397         + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
398         + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
399         + "\tat org.junit.runners.Suite.runChild(Suite.java:128)\n"
400         + "\tat org.junit.runners.Suite.runChild(Suite.java:27)\n"
401         + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
402         + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
403         + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
404         + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
405         + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
406         + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
407         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
408         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
409         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
410         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
411         + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
412         + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
413         + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
414         + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
415         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
416         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
417         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
418         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
419         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n" ) );
420     }
421 
422     @Test
423     public void shouldParserEverythingInEnclosedTrimStackTraceTest()
424         throws Exception
425     {
426         TestSuiteXmlParser parser = new TestSuiteXmlParser();
427         List<ReportTestSuite> tests = parser.parse( "src/test/resources/fixture/testsuitexmlparser/"
428                                                         + "TEST-surefire.MyTest-enclosed-trimStackTrace.xml" );
429         assertTrue( parser.isValid() );
430         assertThat( tests.size(), is( 1 ) );
431         assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );
432         assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );
433         assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );
434         assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );
435         assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );
436         assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );
437         assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );
438         assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );
439         assertTrue( tests.get( 0 ).getTestCases().get( 0 ).hasFailure() );
440         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "45" ) );
441         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),
442                     is( "java.lang.RuntimeException" ) );
443         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );
444         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest$A" ) );
445         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "t" ) );
446         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest$A.t" ) );
447         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );
448 
449         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),
450                     is( "java.lang.IndexOutOfBoundsException" ) );
451 
452         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),
453                     is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
454                             + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
455                             + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
456                             + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
457                             + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
458                             + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n"
459                             + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
460                             + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"
461                             + "\tat surefire.MyTest$A.t(MyTest.java:45)\n" ) );
462     }
463 
464     @Test
465     public void shouldParserEverythingInNestedClassTest()
466         throws Exception
467     {
468         TestSuiteXmlParser parser = new TestSuiteXmlParser();
469         List<ReportTestSuite> tests = parser.parse( "src/test/resources/fixture/testsuitexmlparser/"
470                                                         + "TEST-surefire.MyTest-nestedClass.xml" );
471         assertTrue( parser.isValid() );
472         assertThat( tests.size(), is( 1 ) );
473         assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );
474         assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );
475         assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );
476         assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );
477         assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );
478         assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );
479         assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );
480         assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );
481         assertTrue( tests.get( 0 ).getTestCases().get( 0 ).hasFailure() );
482         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "13" ) );
483         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),
484                     is( "java.lang.RuntimeException" ) );
485         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );
486         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest" ) );
487         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "test" ) );
488         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest.test" ) );
489         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );
490 
491         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),
492                     is( "java.lang.IndexOutOfBoundsException" ) );
493 
494         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),
495                     is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
496         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
497         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
498         + "\tat surefire.MyTest.test(MyTest.java:13)\n"
499         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
500         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
501         + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
502         + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
503         + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
504         + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
505         + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
506         + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
507         + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
508         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
509         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
510         + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
511         + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
512         + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
513         + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
514         + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
515         + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
516         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
517         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
518         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
519         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
520         + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
521         + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
522         + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
523         + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
524         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
525         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
526         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
527         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
528         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" ) );
529     }
530 
531     @Test
532     public void shouldParserEverythingInNestedClassTrimStackTraceTest()
533         throws Exception
534     {
535         TestSuiteXmlParser parser = new TestSuiteXmlParser();
536         List<ReportTestSuite> tests = parser.parse( "src/test/resources/fixture/testsuitexmlparser/"
537                                                         + "TEST-surefire.MyTest-nestedClass-trimStackTrace.xml" );
538         assertTrue( parser.isValid() );
539         assertThat( tests.size(), is( 1 ) );
540         assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );
541         assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );
542         assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );
543         assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );
544         assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );
545         assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );
546         assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );
547         assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );
548         assertTrue( tests.get( 0 ).getTestCases().get( 0 ).hasFailure() );
549         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "13" ) );
550         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),
551                     is( "java.lang.RuntimeException" ) );
552         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );
553         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest" ) );
554         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "test" ) );
555         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest.test" ) );
556         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );
557 
558         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),
559                     is( "java.lang.IndexOutOfBoundsException" ) );
560 
561         assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),
562                     is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
563                             + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
564                             + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
565                             + "\tat surefire.MyTest.test(MyTest.java:13)\n"
566                             + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
567                             + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
568                             + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
569                             + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
570                             + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
571                             + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" ) );
572     }
573 
574     @Test
575     public void shouldTestNotBlank()
576     {
577         assertFalse( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', ' ', ' ', '\n' ) );
578         assertFalse( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', '\t', ' ', '\n' ) );
579         assertFalse( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', ' ', '\r', '\n' ) );
580         assertFalse( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', ' ', '\f', '\n' ) );
581         assertTrue( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', 'a', ' ', '\n' ) );
582         assertTrue( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', ' ', 'a', '\n' ) );
583         assertTrue( TestSuiteXmlParser.isNotBlank( 1, 2, ' ', 'a', 'b', '\n' ) );
584     }
585 
586     @Test
587     public void shouldTestIsNumeric()
588     {
589         assertFalse( TestSuiteXmlParser.isNumeric( new StringBuilder( "0?5142" ), 1, 3 ) );
590         assertTrue( TestSuiteXmlParser.isNumeric( new StringBuilder( "0?51M2" ), 2, 4 ) );
591         assertFalse( TestSuiteXmlParser.isNumeric( new StringBuilder( "0?51M2" ), 2, 5 ) );
592     }
593 }