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