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 org.apache.maven.doxia.module.xhtml.XhtmlSink;
23  import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
24  import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
25  import org.junit.Test;
26  
27  import java.io.File;
28  import java.io.StringWriter;
29  
30  import static java.util.Collections.singletonList;
31  import static java.util.Locale.ENGLISH;
32  import static org.hamcrest.MatcherAssert.assertThat;
33  import static org.hamcrest.CoreMatchers.containsString;
34  import static org.apache.maven.plugins.surefire.report.Utils.toSystemNewLine;
35  
36  /**
37   * Prevent fom NPE if failure type and message is null however detail presents.
38   */
39  public class Surefire597Test
40  {
41      @Test
42      public void corruptedTestCaseFailureWithMissingErrorTypeAndMessage()
43          throws Exception
44      {
45          File basedir = new File( "." ).getCanonicalFile();
46          File report = new File( basedir, "target/test-classes/surefire-597" );
47          ConsoleLogger log = new NullConsoleLogger();
48          SurefireReportGenerator gen = new SurefireReportGenerator( singletonList( report ), ENGLISH, true, null, log );
49          StringWriter writer = new StringWriter();
50          gen.doGenerateReport( new SurefireReportMojo().getBundle( ENGLISH ), new XhtmlSink( writer ) {} );
51          String xml = writer.toString();
52          assertThat( xml, containsString( toSystemNewLine(
53              "<table border=\"1\" class=\"bodyTable\">\n"
54                  + "<tr class=\"a\">\n"
55                  + "<th>Tests</th>\n"
56                  + "<th>Errors</th>\n"
57                  + "<th>Failures</th>\n"
58                  + "<th>Skipped</th>\n"
59                  + "<th>Success Rate</th>\n"
60                  + "<th>Time</th></tr>\n"
61                  + "<tr class=\"b\">\n"
62                  + "<td>1</td>\n"
63                  + "<td>1</td>\n"
64                  + "<td>0</td>\n"
65                  + "<td>0</td>\n"
66                  + "<td>0%</td>\n"
67                  + "<td>0</td>"
68                  + "</tr>"
69                  + "</table>" ) ) );
70          assertThat( xml, containsString( toSystemNewLine(
71              "<table border=\"1\" class=\"bodyTable\">\n"
72                  + "<tr class=\"a\">\n"
73                  + "<th>Package</th>\n"
74                  + "<th>Tests</th>\n"
75                  + "<th>Errors</th>\n"
76                  + "<th>Failures</th>\n"
77                  + "<th>Skipped</th>\n"
78                  + "<th>Success Rate</th>\n"
79                  + "<th>Time</th></tr>\n"
80                  + "<tr class=\"b\">\n"
81                  + "<td><a href=\"#surefire\">surefire</a></td>\n"
82                  + "<td>1</td>\n"
83                  + "<td>1</td>\n"
84                  + "<td>0</td>\n"
85                  + "<td>0</td>\n"
86                  + "<td>0%</td>\n"
87                  + "<td>0</td></tr></table>" ) ) );
88          assertThat( xml, containsString( toSystemNewLine(
89              "<table border=\"1\" class=\"bodyTable\">\n"
90                  + "<tr class=\"a\">\n"
91                  + "<th></th>\n"
92                  + "<th>Class</th>\n"
93                  + "<th>Tests</th>\n"
94                  + "<th>Errors</th>\n"
95                  + "<th>Failures</th>\n"
96                  + "<th>Skipped</th>\n"
97                  + "<th>Success Rate</th>\n"
98                  + "<th>Time</th></tr>\n"
99                  + "<tr class=\"b\">\n"
100                 + "<td><a href=\"#surefire.MyTest\"><img src=\"images/icon_error_sml.gif\" alt=\"\" /></a></td>\n"
101                 + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
102                 + "<td>1</td>\n"
103                 + "<td>1</td>\n"
104                 + "<td>0</td>\n"
105                 + "<td>0</td>\n"
106                 + "<td>0%</td>\n"
107                 + "<td>0</td></tr></table>" ) ) );
108         assertThat( xml, containsString( toSystemNewLine(
109             "<table border=\"1\" class=\"bodyTable\">\n"
110                 + "<tr class=\"a\">\n"
111                 + "<td><img src=\"images/icon_error_sml.gif\" alt=\"\" /></td>\n"
112                 + "<td><a name=\"surefire.MyTest.test\"></a>test</td></tr>\n"
113                 + "<tr class=\"b\">\n"
114                 + "<td></td>\n"
115                 + "<td>java.lang.RuntimeException: java.lang.IndexOutOfBoundsException: msg</td></tr>\n"
116                 + "<tr class=\"a\">\n"
117                 + "<td></td>\n"
118                 + "<td>\n"
119                 + "<div id=\"test-error\">surefire.MyTest:13</div></td></tr></table>" ) ) );
120     }
121 }