View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.surefire.report;
20  
21  import java.io.File;
22  import java.io.UnsupportedEncodingException;
23  import java.net.URL;
24  import java.net.URLDecoder;
25  import java.util.Locale;
26  
27  import org.apache.maven.plugin.LegacySupport;
28  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
29  import org.apache.maven.plugin.testing.ArtifactStubFactory;
30  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
31  import org.apache.maven.plugins.surefire.report.stubs.DependencyArtifactStubFactory;
32  import org.apache.maven.shared.utils.io.FileUtils;
33  import org.eclipse.aether.DefaultRepositorySystemSession;
34  import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
35  import org.eclipse.aether.repository.LocalRepository;
36  
37  import static org.apache.maven.plugins.surefire.report.Utils.toSystemNewLine;
38  import static org.hamcrest.CoreMatchers.containsString;
39  import static org.hamcrest.MatcherAssert.assertThat;
40  
41  /**
42   * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
43   */
44  @SuppressWarnings("checkstyle:linelength")
45  public class SurefireReportMojoTest extends AbstractMojoTestCase {
46      private ArtifactStubFactory artifactStubFactory;
47  
48      // Can be removed with Doxia 2.0.0
49      private Locale origLocale;
50  
51      @Override
52      protected void setUp() throws Exception {
53          super.setUp();
54          artifactStubFactory = new DependencyArtifactStubFactory(getTestFile("target"), true, false);
55          artifactStubFactory.getWorkingDir().mkdirs();
56  
57          origLocale = Locale.getDefault();
58          Locale.setDefault(Locale.ROOT);
59      }
60  
61      @Override
62      protected void tearDown() throws Exception {
63          Locale.setDefault(origLocale);
64          super.tearDown();
65      }
66  
67      protected SurefireReportMojo createReportMojo(File pluginXmlFile) throws Exception {
68          SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo("report", pluginXmlFile);
69          assertNotNull("Mojo found.", mojo);
70  
71          LegacySupport legacySupport = lookup(LegacySupport.class);
72          legacySupport.setSession(newMavenSession(new MavenProjectStub()));
73          DefaultRepositorySystemSession repoSession =
74                  (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
75          repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
76                  .newInstance(repoSession, new LocalRepository(artifactStubFactory.getWorkingDir())));
77  
78          // setVariableValueToObject( mojo, "session", legacySupport.getSession() );
79          setVariableValueToObject(mojo, "remoteRepositories", mojo.getProject().getRemoteArtifactRepositories());
80          return mojo;
81      }
82  
83      public void testBasicSurefireReport() throws Exception {
84          File testPom = new File(getUnitBaseDir(), "basic-surefire-report-test/plugin-config.xml");
85          SurefireReportMojo mojo = createReportMojo(testPom);
86          File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
87          boolean showSuccess = (Boolean) getVariableValueFromObject(mojo, "showSuccess");
88          File reportsDir = (File) getVariableValueFromObject(mojo, "reportsDirectory");
89          String outputName = (String) getVariableValueFromObject(mojo, "outputName");
90          File xrefLocation = (File) getVariableValueFromObject(mojo, "xrefLocation");
91          boolean linkXRef = (Boolean) getVariableValueFromObject(mojo, "linkXRef");
92  
93          assertEquals(new File(getBasedir() + "/target/site/unit/basic-surefire-report-test"), outputDir);
94          assertTrue(showSuccess);
95          assertEquals(
96                  new File(getBasedir() + "/src/test/resources/unit/basic-surefire-report-test/surefire-reports")
97                          .getAbsolutePath(),
98                  reportsDir.getAbsolutePath());
99          assertEquals("surefire-report", outputName);
100         assertEquals(
101                 new File(getBasedir() + "/target/site/unit/basic-surefire-report-test/xref-test").getAbsolutePath(),
102                 xrefLocation.getAbsolutePath());
103         assertTrue(linkXRef);
104 
105         mojo.execute();
106         File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-test/surefire-report.html");
107         assertTrue(report.exists());
108         String htmlContent = FileUtils.fileRead(report);
109 
110         int idx = htmlContent.indexOf("images/icon_success_sml.gif");
111         assertTrue(idx >= 0);
112     }
113 
114     private File getUnitBaseDir() throws UnsupportedEncodingException {
115         URL resource = getClass().getResource("/unit");
116         // URLDecoder.decode necessary for JDK 1.5+, where spaces are escaped to %20
117         return new File(URLDecoder.decode(resource.getPath(), "UTF-8")).getAbsoluteFile();
118     }
119 
120     public void testBasicSurefireReportIfShowSuccessIsFalse() throws Exception {
121         File testPom = new File(getUnitBaseDir(), "basic-surefire-report-success-false/plugin-config.xml");
122         SurefireReportMojo mojo = createReportMojo(testPom);
123         boolean showSuccess = (Boolean) getVariableValueFromObject(mojo, "showSuccess");
124         assertFalse(showSuccess);
125         mojo.execute();
126         File report =
127                 new File(getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire-report.html");
128         assertTrue(report.exists());
129         String htmlContent = FileUtils.fileRead(report);
130 
131         int idx = htmlContent.indexOf("images/icon_success_sml.gif");
132         assertTrue(idx < 0);
133     }
134 
135     public void testBasicSurefireReportIfLinkXrefIsFalse() throws Exception {
136         File testPom = new File(getUnitBaseDir(), "basic-surefire-report-linkxref-false/plugin-config.xml");
137         SurefireReportMojo mojo = createReportMojo(testPom);
138         boolean linkXRef = (Boolean) getVariableValueFromObject(mojo, "linkXRef");
139         assertFalse(linkXRef);
140         mojo.execute();
141         File report =
142                 new File(getBasedir(), "target/site/unit/basic-surefire-report-linkxref-false/surefire-report.html");
143         assertTrue(report.exists());
144         String htmlContent = FileUtils.fileRead(report);
145 
146         int idx = htmlContent.indexOf("./xref-test/com/shape/CircleTest.html#L44");
147         assertTrue(idx == -1);
148     }
149 
150     public void testBasicSurefireReportIfReportingIsNull() throws Exception {
151         File testPom = new File(getUnitBaseDir(), "basic-surefire-report-reporting-null/plugin-config.xml");
152         SurefireReportMojo mojo = createReportMojo(testPom);
153         mojo.execute();
154         File report =
155                 new File(getBasedir(), "target/site/unit/basic-surefire-report-reporting-null/surefire-report.html");
156         assertTrue(report.exists());
157         String htmlContent = FileUtils.fileRead(report);
158 
159         int idx = htmlContent.indexOf("./xref-test/com/shape/CircleTest.html#L44");
160         assertTrue(idx < 0);
161     }
162 
163     @SuppressWarnings("checkstyle:methodname")
164     public void testBasicSurefireReport_AnchorTestCases() throws Exception {
165         File testPom = new File(getUnitBaseDir(), "basic-surefire-report-anchor-test-cases/plugin-config.xml");
166         SurefireReportMojo mojo = createReportMojo(testPom);
167         mojo.execute();
168         File report =
169                 new File(getBasedir(), "target/site/unit/basic-surefire-report-anchor-test-cases/surefire-report.html");
170         assertTrue(report.exists());
171         String htmlContent = FileUtils.fileRead(report);
172 
173         int idx = htmlContent.indexOf("<td><a id=\"TC_com.shape.CircleTest.testX\"></a>testX</td>");
174         assertTrue(idx > 0);
175 
176         idx = htmlContent.indexOf("<td><a id=\"TC_com.shape.CircleTest.testRadius\"></a>"
177                 + "<a href=\"#com.shape.CircleTest.testRadius\">testRadius</a>");
178         assertTrue(idx > 0);
179     }
180 
181     public void testSurefireReportSingleError() throws Exception {
182         File testPom = new File(getUnitBaseDir(), "surefire-report-single-error/plugin-config.xml");
183         SurefireReportMojo mojo = createReportMojo(testPom);
184         mojo.execute();
185         File report = new File(getBasedir(), "target/site/unit/surefire-report-single-error/surefire-report.html");
186         assertTrue(report.exists());
187         String htmlContent = FileUtils.fileRead(report);
188 
189         assertThat(
190                 htmlContent,
191                 containsString(toSystemNewLine("<tr class=\"b\">\n"
192                         + "<td align=\"left\">1</td>\n"
193                         + "<td>1</td>\n"
194                         + "<td>0</td>\n"
195                         + "<td>0</td>\n"
196                         + "<td>0%</td>\n"
197                         + "<td>0 s</td>")));
198 
199         assertThat(
200                 htmlContent,
201                 containsString(toSystemNewLine("<tr class=\"b\">\n"
202                         + "<td align=\"left\"><a href=\"#surefire\">surefire</a></td>\n"
203                         + "<td>1</td>\n"
204                         + "<td>1</td>\n"
205                         + "<td>0</td>\n"
206                         + "<td>0</td>\n"
207                         + "<td>0%</td>\n"
208                         + "<td>0 s</td></tr>")));
209         assertThat(
210                 htmlContent,
211                 containsString(toSystemNewLine("<tr class=\"b\">\n"
212                         + "<td align=\"left\">"
213                         + "<a href=\"#surefire.MyTest\">"
214                         + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
215                         + "</a>"
216                         + "</td>\n"
217                         + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
218                         + "<td>1</td>\n"
219                         + "<td>1</td>\n"
220                         + "<td>0</td>\n"
221                         + "<td>0</td>\n"
222                         + "<td>0%</td>\n"
223                         + "<td>0 s</td></tr>")));
224 
225         assertThat(htmlContent, containsString(">surefire.MyTest:13</a>"));
226 
227         assertThat(htmlContent, containsString("./xref-test/surefire/MyTest.html#L13"));
228 
229         assertThat(
230                 htmlContent,
231                 containsString(toSystemNewLine("<pre>"
232                         + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
233                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
234                         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
235                         + "\tat surefire.MyTest.test(MyTest.java:13)\n"
236                         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
237                         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
238                         + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
239                         + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
240                         + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
241                         + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
242                         + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
243                         + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
244                         + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
245                         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
246                         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
247                         + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
248                         + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
249                         + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
250                         + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
251                         + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
252                         + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
253                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
254                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
255                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
256                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
257                         + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
258                         + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
259                         + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
260                         + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
261                         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
262                         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
263                         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
264                         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
265                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" + "</pre>")));
266     }
267 
268     public void testSurefireReportNestedClassTrimStackTrace() throws Exception {
269         File testPom = new File(getUnitBaseDir(), "surefire-report-nestedClass-trimStackTrace/plugin-config.xml");
270         SurefireReportMojo mojo = createReportMojo(testPom);
271         mojo.execute();
272         File report = new File(
273                 getBasedir(), "target/site/unit/surefire-report-nestedClass-trimStackTrace/surefire-report.html");
274         assertTrue(report.exists());
275         String htmlContent = FileUtils.fileRead(report);
276 
277         assertThat(
278                 htmlContent,
279                 containsString(toSystemNewLine("<tr class=\"b\">\n"
280                         + "<td align=\"left\">1</td>\n"
281                         + "<td>1</td>\n"
282                         + "<td>0</td>\n"
283                         + "<td>0</td>\n"
284                         + "<td>0%</td>\n"
285                         + "<td>0 s</td>")));
286 
287         assertThat(
288                 htmlContent,
289                 containsString(toSystemNewLine("<tr class=\"b\">\n"
290                         + "<td align=\"left\"><a href=\"#surefire\">surefire</a></td>\n"
291                         + "<td>1</td>\n"
292                         + "<td>1</td>\n"
293                         + "<td>0</td>\n"
294                         + "<td>0</td>\n"
295                         + "<td>0%</td>\n"
296                         + "<td>0 s</td></tr>")));
297         assertThat(
298                 htmlContent,
299                 containsString(toSystemNewLine("<tr class=\"b\">\n"
300                         + "<td align=\"left\">"
301                         + "<a href=\"#surefire.MyTest\">"
302                         + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
303                         + "</a>"
304                         + "</td>\n"
305                         + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
306                         + "<td>1</td>\n"
307                         + "<td>1</td>\n"
308                         + "<td>0</td>\n"
309                         + "<td>0</td>\n"
310                         + "<td>0%</td>\n"
311                         + "<td>0 s</td></tr>")));
312         assertThat(htmlContent, containsString(">surefire.MyTest:13</a>"));
313 
314         assertThat(htmlContent, containsString("./xref-test/surefire/MyTest.html#L13"));
315 
316         assertThat(
317                 htmlContent,
318                 containsString(toSystemNewLine("<pre>"
319                         + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
320                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
321                         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
322                         + "\tat surefire.MyTest.test(MyTest.java:13)\n"
323                         + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
324                         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
325                         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
326                         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
327                         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
328                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)"
329                         + "</pre>")));
330     }
331 
332     public void testSurefireReportNestedClass() throws Exception {
333         File testPom = new File(getUnitBaseDir(), "surefire-report-nestedClass/plugin-config.xml");
334         SurefireReportMojo mojo = createReportMojo(testPom);
335         mojo.execute();
336         File report = new File(getBasedir(), "target/site/unit/surefire-report-nestedClass/surefire-report.html");
337         assertTrue(report.exists());
338         String htmlContent = FileUtils.fileRead(report);
339 
340         assertThat(
341                 htmlContent,
342                 containsString(toSystemNewLine("<tr class=\"b\">\n"
343                         + "<td align=\"left\">1</td>\n"
344                         + "<td>1</td>\n"
345                         + "<td>0</td>\n"
346                         + "<td>0</td>\n"
347                         + "<td>0%</td>\n"
348                         + "<td>0 s</td>")));
349 
350         assertThat(
351                 htmlContent,
352                 containsString(toSystemNewLine("<tr class=\"b\">\n"
353                         + "<td align=\"left\"><a href=\"#surefire\">surefire</a></td>\n"
354                         + "<td>1</td>\n"
355                         + "<td>1</td>\n"
356                         + "<td>0</td>\n"
357                         + "<td>0</td>\n"
358                         + "<td>0%</td>\n"
359                         + "<td>0 s</td></tr>")));
360         assertThat(
361                 htmlContent,
362                 containsString(toSystemNewLine("<tr class=\"b\">\n"
363                         + "<td align=\"left\">"
364                         + "<a href=\"#surefire.MyTest\">"
365                         + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
366                         + "</a>"
367                         + "</td>\n"
368                         + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
369                         + "<td>1</td>\n"
370                         + "<td>1</td>\n"
371                         + "<td>0</td>\n"
372                         + "<td>0</td>\n"
373                         + "<td>0%</td>\n"
374                         + "<td>0 s</td></tr>")));
375         assertThat(htmlContent, containsString(">surefire.MyTest:13</a>"));
376 
377         assertThat(htmlContent, containsString("./xref-test/surefire/MyTest.html#L13"));
378 
379         assertThat(
380                 htmlContent,
381                 containsString(toSystemNewLine("<pre>"
382                         + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
383                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
384                         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
385                         + "\tat surefire.MyTest.test(MyTest.java:13)\n"
386                         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
387                         + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
388                         + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
389                         + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
390                         + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
391                         + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
392                         + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
393                         + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
394                         + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
395                         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
396                         + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
397                         + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
398                         + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
399                         + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
400                         + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
401                         + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
402                         + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
403                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
404                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
405                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
406                         + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
407                         + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
408                         + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
409                         + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
410                         + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
411                         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
412                         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
413                         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
414                         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
415                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)"
416                         + "</pre>")));
417     }
418 
419     public void testSurefireReportEnclosedTrimStackTrace() throws Exception {
420         File testPom = new File(getUnitBaseDir(), "surefire-report-enclosed-trimStackTrace/plugin-config.xml");
421         SurefireReportMojo mojo = createReportMojo(testPom);
422         mojo.execute();
423         File report =
424                 new File(getBasedir(), "target/site/unit/surefire-report-enclosed-trimStackTrace/surefire-report.html");
425         assertTrue(report.exists());
426         String htmlContent = FileUtils.fileRead(report);
427 
428         assertThat(
429                 htmlContent,
430                 containsString(toSystemNewLine("<tr class=\"b\">\n"
431                         + "<td align=\"left\">1</td>\n"
432                         + "<td>1</td>\n"
433                         + "<td>0</td>\n"
434                         + "<td>0</td>\n"
435                         + "<td>0%</td>\n"
436                         + "<td>0 s</td>")));
437 
438         assertThat(
439                 htmlContent,
440                 containsString(toSystemNewLine("<tr class=\"b\">\n"
441                         + "<td align=\"left\"><a href=\"#surefire\">surefire</a></td>\n"
442                         + "<td>1</td>\n"
443                         + "<td>1</td>\n"
444                         + "<td>0</td>\n"
445                         + "<td>0</td>\n"
446                         + "<td>0%</td>\n"
447                         + "<td>0 s</td></tr>")));
448         assertThat(
449                 htmlContent,
450                 containsString(toSystemNewLine("<tr class=\"b\">\n"
451                         + "<td align=\"left\">"
452                         + "<a href=\"#surefire.MyTest$A\">"
453                         + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
454                         + "</a>"
455                         + "</td>\n"
456                         + "<td><a href=\"#surefire.MyTest$A\">MyTest$A</a></td>\n"
457                         + "<td>1</td>\n"
458                         + "<td>1</td>\n"
459                         + "<td>0</td>\n"
460                         + "<td>0</td>\n"
461                         + "<td>0%</td>\n"
462                         + "<td>0 s</td></tr>")));
463 
464         assertThat(htmlContent, containsString(">surefire.MyTest$A:45</a>"));
465 
466         assertThat(htmlContent, containsString("./xref-test/surefire/MyTest$A.html#L45"));
467 
468         assertThat(
469                 htmlContent,
470                 containsString(toSystemNewLine("<pre>"
471                         + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
472                         + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
473                         + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
474                         + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
475                         + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
476                         + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n"
477                         + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
478                         + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"
479                         + "\tat surefire.MyTest$A.t(MyTest.java:45)\n"
480                         + "</pre>")));
481     }
482 
483     public void testSurefireReportEnclosed() throws Exception {
484         File testPom = new File(getUnitBaseDir(), "surefire-report-enclosed/plugin-config.xml");
485         SurefireReportMojo mojo = createReportMojo(testPom);
486         mojo.execute();
487         File report = new File(getBasedir(), "target/site/unit/surefire-report-enclosed/surefire-report.html");
488         assertTrue(report.exists());
489         String htmlContent = FileUtils.fileRead(report);
490 
491         assertThat(
492                 htmlContent,
493                 containsString(toSystemNewLine("<tr class=\"b\">\n"
494                         + "<td align=\"left\">1</td>\n"
495                         + "<td>1</td>\n"
496                         + "<td>0</td>\n"
497                         + "<td>0</td>\n"
498                         + "<td>0%</td>\n"
499                         + "<td>0 s</td>")));
500 
501         assertThat(
502                 htmlContent,
503                 containsString(toSystemNewLine("<tr class=\"b\">\n"
504                         + "<td align=\"left\"><a href=\"#surefire\">surefire</a></td>\n"
505                         + "<td>1</td>\n"
506                         + "<td>1</td>\n"
507                         + "<td>0</td>\n"
508                         + "<td>0</td>\n"
509                         + "<td>0%</td>\n"
510                         + "<td>0 s</td></tr>")));
511         assertThat(
512                 htmlContent,
513                 containsString(toSystemNewLine("<tr class=\"b\">\n"
514                         + "<td align=\"left\">"
515                         + "<a href=\"#surefire.MyTest$A\">"
516                         + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
517                         + "</a>"
518                         + "</td>\n"
519                         + "<td><a href=\"#surefire.MyTest$A\">MyTest$A</a></td>\n"
520                         + "<td>1</td>\n"
521                         + "<td>1</td>\n"
522                         + "<td>0</td>\n"
523                         + "<td>0</td>\n"
524                         + "<td>0%</td>\n"
525                         + "<td>0 s</td></tr>")));
526 
527         assertThat(htmlContent, containsString(">surefire.MyTest$A:45</a>"));
528 
529         assertThat(htmlContent, containsString("./xref-test/surefire/MyTest$A.html#L45"));
530 
531         assertThat(
532                 htmlContent,
533                 containsString(
534                         toSystemNewLine("<pre>" + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
535                                 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
536                                 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
537                                 + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"
538                                 + "\tat surefire.MyTest$A.t(MyTest.java:45)\n"
539                                 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
540                                 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
541                                 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
542                                 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
543                                 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
544                                 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
545                                 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
546                                 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
547                                 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
548                                 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
549                                 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
550                                 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
551                                 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
552                                 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
553                                 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
554                                 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
555                                 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
556                                 + "\tat org.junit.runners.Suite.runChild(Suite.java:128)\n"
557                                 + "\tat org.junit.runners.Suite.runChild(Suite.java:27)\n"
558                                 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
559                                 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
560                                 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
561                                 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
562                                 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
563                                 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
564                                 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
565                                 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
566                                 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
567                                 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
568                                 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
569                                 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
570                                 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
571                                 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
572                                 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
573                                 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
574                                 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
575                                 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
576                                 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n"
577                                 + "</pre>")));
578     }
579 
580     public void testCustomTitleAndDescriptionReport() throws Exception {
581         File testPom = new File(getUnitBaseDir(), "surefire-1183/plugin-config.xml");
582         SurefireReportMojo mojo = createReportMojo(testPom);
583 
584         File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
585         String outputName = (String) getVariableValueFromObject(mojo, "outputName");
586         File reportsDir = (File) getVariableValueFromObject(mojo, "reportsDirectory");
587 
588         assertEquals(new File(getBasedir() + "/target/site/unit/surefire-1183"), outputDir);
589         assertEquals(
590                 new File(getBasedir() + "/src/test/resources/unit/surefire-1183/acceptancetest-reports")
591                         .getAbsolutePath(),
592                 reportsDir.getAbsolutePath());
593         assertEquals("acceptance-test-report", outputName);
594 
595         mojo.execute();
596 
597         File report = new File(getBasedir(), "target/site/unit/surefire-1183/acceptance-test-report.html");
598 
599         assertTrue(report.exists());
600 
601         String htmlContent = FileUtils.fileRead(report);
602         assertTrue(htmlContent.contains("<h2><a name=\"Acceptance_Test\"></a>Acceptance Test</h2></section>"));
603     }
604 }