Skip to content

Commit

Permalink
Test cleanup (#1184)
Browse files Browse the repository at this point in the history
* [tests] Cleanup test to follow logic to get rid of try catch block

* [tests] Cleanup test that ran item inside assert throws that was not the throwable one

* [tests] Cleanup code in test cases

* [tests] Remove unthrown exceptions
  • Loading branch information
hazendaz authored May 30, 2024
1 parent 1779c19 commit 1d59afc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/test/java/LiveDemoTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -20,7 +19,7 @@ class LiveDemoTest {
// what is needed to publish generated report via github.com
// http://damianszczepanik.github.io/cucumber-html-reports/overview-features.html
@Test
void generateDemoReport() throws IOException {
void generateDemoReport() {
File reportOutputDirectory = new File("target/demo");
List<String> jsonFiles = new ArrayList<>();
jsonFiles.add("src/test/resources/json/sample.json");
Expand Down
17 changes: 5 additions & 12 deletions src/test/java/net/masterthought/cucumber/ReportBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,9 @@ void copyCustomResources_OnDirAsFile_ThrowsIOException() throws Exception {
ReportBuilder builder = new ReportBuilder(Collections.<String>emptyList(), configuration);
File dir = new File("src/test/resources/js");

// then
try {
Whitebox.invokeMethod(builder, "copyCustomResources", "js", dir);
fail("Copying should fail!");
// exception depends of operating system
} catch (ValidationException e) {
// passed
}
// when & then
assertThatThrownBy(() -> Whitebox.invokeMethod(builder, "copyCustomResources", "js", dir))
.isInstanceOf(ValidationException.class);
}

@Test
Expand Down Expand Up @@ -528,15 +523,13 @@ void generateErrorPage_GeneratesErrorPage() throws Exception {
}

private File[] countHtmlFiles(Configuration configuration) {
Builder builder = WildcardFileFilter.builder().setWildcards("*.html");
FileFilter fileFilter = builder.get();
FileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.html").get();
File dir = new File(configuration.getReportDirectory(), ReportBuilder.BASE_DIRECTORY + configuration.getDirectorySuffixWithSeparator());
return dir.listFiles(fileFilter);
}

private File[] countHtmlFiles() {
Builder builder = WildcardFileFilter.builder().setWildcards("*.html");
FileFilter fileFilter = builder.get();
FileFilter fileFilter = WildcardFileFilter.builder().setWildcards("*.html").get();
File dir = new File(reportDirectory, ReportBuilder.BASE_DIRECTORY + configuration.getDirectorySuffixWithSeparator());
return dir.listFiles(fileFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class AllInOneReport extends ReportGenerator {

@Test
void unsupportedReportFormat() {
assertThrows(IllegalArgumentException.class, () -> {
// given
configuration.addReducingMethod(MERGE_FEATURES_WITH_RETEST);
// given
configuration.addReducingMethod(MERGE_FEATURES_WITH_RETEST);

assertThrows(IllegalArgumentException.class, () -> {
// when
// then
setUpWithJson(SAMPLE_FAILED_JSON, SAMPLE_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private Element buildScenario() {
}

@Test
void updateElementsOfGivenFeature_NoCoincidencesById() throws IllegalAccessException {
void updateElementsOfGivenFeature_NoCoincidencesById() {
// given
Feature feature = new Feature();
Whitebox.setInternalState(feature, "elements", new Element[] {buildBackground(), buildScenario(), buildScenario()});
Expand All @@ -53,7 +53,7 @@ void updateElementsOfGivenFeature_NoCoincidencesById() throws IllegalAccessExcep
}

@Test
void updateElementsOfGivenFeature_WithCoincidenceById() throws IllegalAccessException {
void updateElementsOfGivenFeature_WithCoincidenceById() {
// given
Feature feature = new Feature();
Element[] elements = {buildScenario(), buildBackground(), buildScenario()};
Expand Down

0 comments on commit 1d59afc

Please sign in to comment.