|
11 | 11 | import java.io.File; |
12 | 12 | import java.io.FileWriter; |
13 | 13 | import java.io.IOException; |
| 14 | +import java.io.StringWriter; |
14 | 15 | import java.nio.file.Files; |
15 | 16 | import java.nio.file.Path; |
16 | 17 | import java.util.Arrays; |
@@ -68,6 +69,31 @@ void testExecuteWithNoReports() throws MojoExecutionException { |
68 | 69 | assertFalse(outputFile.exists()); |
69 | 70 | } |
70 | 71 |
|
| 72 | + @Test |
| 73 | + void testHelperMethods() throws Exception { |
| 74 | + // Given: a sample Surefire report |
| 75 | + createSampleSurefireReport("TEST-SampleHelperMethodsTest.xml", |
| 76 | + "com.example.helper.SampleTest", |
| 77 | + Arrays.asList( |
| 78 | + new TestCase("testMethodA", "0.111", false, false, false), |
| 79 | + new TestCase("testMethodB", "0.222", false, false, false) |
| 80 | + ) |
| 81 | + ); |
| 82 | + |
| 83 | + setField(mojo, "format", "pdf"); |
| 84 | + outputFile = tempDir.resolve("test-tag-report.pdf").toFile(); |
| 85 | + setField(mojo, "outputFile", outputFile); |
| 86 | + |
| 87 | + // When: execute |
| 88 | + mojo.execute(); |
| 89 | + // Then: output file should be created |
| 90 | + assertTrue(outputFile.exists()); |
| 91 | + |
| 92 | + String content = new String(Files.readAllBytes(outputFile.toPath())); |
| 93 | + assertTrue(content.contains("PDF")); |
| 94 | + } |
| 95 | + |
| 96 | + |
71 | 97 | @Test |
72 | 98 | void testExecuteGeneratesTextReport() throws Exception { |
73 | 99 | // Given: a sample Surefire report |
@@ -462,8 +488,8 @@ void testXmlReportStructure() throws Exception { |
462 | 488 | private void createSampleSurefireReport(String filename, String className, |
463 | 489 | List<TestCase> testCases) throws IOException { |
464 | 490 | File reportFile = new File(surefireReportsDir, filename); |
465 | | - |
466 | | - try (FileWriter writer = new FileWriter(reportFile)) { |
| 491 | + try (StringWriter writer = new StringWriter(); |
| 492 | + FileWriter fileWriter = new FileWriter(reportFile)) { |
467 | 493 | writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
468 | 494 | writer.write("<testsuite name=\"" + className + "\" "); |
469 | 495 | writer.write("tests=\"" + testCases.size() + "\" "); |
@@ -492,8 +518,9 @@ private void createSampleSurefireReport(String filename, String className, |
492 | 518 | writer.write(" </testcase>\n"); |
493 | 519 | } |
494 | 520 | } |
495 | | - |
496 | 521 | writer.write("</testsuite>\n"); |
| 522 | + log.info( "report, file : {}, content : {}", outputFile.getAbsolutePath(), writer ); |
| 523 | + fileWriter.write(writer.toString()); |
497 | 524 | } |
498 | 525 | } |
499 | 526 |
|
|
0 commit comments