Skip to content

Commit

Permalink
3523: small mods on test code to use assertThat on Files as it should be
Browse files Browse the repository at this point in the history
  • Loading branch information
t.eitzenberger committed Sep 8, 2024
1 parent 9489abf commit 83cac81
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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());
}


Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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());

}

Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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 {

Expand Down

0 comments on commit 83cac81

Please sign in to comment.