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