From 83cac81c6ed8f74b5e9685b5a787b396b306a10c Mon Sep 17 00:00:00 2001 From: "t.eitzenberger" Date: Sun, 8 Sep 2024 19:30:41 +0200 Subject: [PATCH] 3523: small mods on test code to use assertThat on Files as it should be --- .../WhenGeneratingAnHtmlReport.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/serenity-reports/src/test/java/net/thucydides/core/reports/integration/WhenGeneratingAnHtmlReport.java b/serenity-reports/src/test/java/net/thucydides/core/reports/integration/WhenGeneratingAnHtmlReport.java index d77d3c1c6..93b0ca1e7 100644 --- a/serenity-reports/src/test/java/net/thucydides/core/reports/integration/WhenGeneratingAnHtmlReport.java +++ b/serenity-reports/src/test/java/net/thucydides/core/reports/integration/WhenGeneratingAnHtmlReport.java @@ -20,17 +20,18 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.hamcrest.io.FileMatchers.anExistingFile; public class WhenGeneratingAnHtmlReport extends AbstractReportGenerationTest { @Mock TestOutcomes allTestOutcomes; - + @Before public void setupWorkingDirectory() throws IOException { - + MockitoAnnotations.initMocks(this); - + File screenshotsSourceDirectory = FileSystemUtils.getResourceAsFile("screenshots"); File[] screenshots = screenshotsSourceDirectory.listFiles(); @@ -50,7 +51,7 @@ public void should_generate_an_HTML_report_for_an_acceptance_test_run() throws E File htmlReport = reporter.generateReportFor(testOutcome); - assertThat(htmlReport.exists(), is(true)); + assertThat(htmlReport, anExistingFile()); } @Test @@ -61,7 +62,7 @@ public void should_generate_an_HTML_report_for_an_acceptance_test_run_with_no_st testOutcome.determineTestFailureCause(new AssertionError("test failed")); File htmlReport = reporter.generateReportFor(testOutcome); - assertThat(htmlReport.exists(), is(true)); + assertThat(htmlReport, anExistingFile()); } @Test @@ -73,7 +74,7 @@ public void should_generate_an_HTML_report_for_a_failing_manual_acceptance_test( testOutcome.setAnnotatedResult(TestResult.FAILURE); File htmlReport = reporter.generateReportFor(testOutcome); - assertThat(htmlReport.exists(), is(true)); + assertThat(htmlReport, anExistingFile()); } @@ -82,10 +83,10 @@ public void css_stylesheets_should_also_be_copied_to_the_output_directory() thro TestOutcome testOutcome = new TestOutcome("a_simple_test_case"); testOutcome.recordStep(TestStepFactory.successfulTestStepCalled("step 1")); reporter.generateReportFor(testOutcome); - + File cssDir = new File(outputDirectory, "css"); File cssStylesheet = new File(cssDir, "core.css"); - assertThat(cssStylesheet.exists(), is(true)); + assertThat(cssStylesheet, anExistingFile()); } @Test @@ -99,7 +100,7 @@ public void css_stylesheets_should_be_copied_to_a_non_standard_output_directory( File cssDir = new File(differentOutputDirectory, "css"); File cssStylesheet = new File(cssDir, "core.css"); - assertThat(cssStylesheet.exists(), is(true)); + assertThat(cssStylesheet, anExistingFile()); } @Test @@ -109,14 +110,14 @@ public void the_report_file_and_the_resources_should_be_together() throws Except testOutcome.recordStep(TestStepFactory.successfulTestStepCalled("step 1")); reporter.generateReportFor(testOutcome); - + File report = new File(outputDirectory,Digest.ofTextValue("a_simple_test_case") + ".html"); File cssDir = new File(outputDirectory, "css"); File cssStylesheet = new File(cssDir, "core.css"); - assertThat(cssStylesheet.exists(), is(true)); - assertThat(report.exists(), is(true)); + assertThat(cssStylesheet, anExistingFile()); + assertThat(report, anExistingFile()); } - + @Test public void screenshots_should_have_a_separate_html_report() throws Exception { TestOutcome testOutcome = TestOutcome.forTest("should_do_this", SomeTestScenario.class); @@ -130,7 +131,7 @@ public void screenshots_should_have_a_separate_html_report() throws Exception { File report = reporter.generateReportFor(testOutcome); File screenshotReport = withSuffix(report,"_screenshots"); - assertThat(screenshotReport.exists(), is(true)); + assertThat(screenshotReport, anExistingFile()); } @@ -215,7 +216,7 @@ public void the_resources_can_come_from_a_different_location_in_a_jar_file() thr final String alternativeResourceDirectory = "alt-report-resources"; reporter.setResourceDirectory(alternativeResourceDirectory); reporter.generateReportFor(testOutcome); - + File expectedCssStylesheet = new File(new File(outputDirectory,"css"), "alternative.css"); assertThat(expectedCssStylesheet.exists(), is(true)); } @@ -242,7 +243,7 @@ public void a_different_resource_location_can_be_specified_by_using_a_system_pro environmentVariables.setProperty("thucydides.report.resources", "alt-report-resources"); reporter.generateReportFor(testOutcome); - + File expectedCssStylesheet = new File(new File(outputDirectory,"css"), "alternative.css"); assertThat(expectedCssStylesheet.exists(), is(true)); } @@ -256,12 +257,12 @@ public void when_an_alternative_resource_directory_is_used_the_default_styleshee final String alternativeResourceDirectory = "alt-report-resources"; reporter.setResourceDirectory(alternativeResourceDirectory); reporter.generateReportFor(testOutcome); - + File defaultCssStylesheet = new File(new File(outputDirectory,"css"), "core.css"); assertThat(defaultCssStylesheet.exists(), is(false)); } - + @Test public void a_sample_report_should_be_generated_in_the_target_directory() throws Exception {