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