Skip to content

Commit

Permalink
Merge pull request #1193 from jrmcdonald/fix/ignore-absent-files-aggr…
Browse files Browse the repository at this point in the history
…egate-builder

Ignore absent ReportAggregatorBuilder files
  • Loading branch information
hcoles authored Apr 28, 2023
2 parents 0f9f3dc + f4a1947 commit 6fc727c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ public Builder lineCoverageFiles(final List<File> lineCoverageFiles) {

public Builder addLineCoverageFile(final File lineCoverageFile) {
validateFile(lineCoverageFile);
this.lineCoverageFiles.add(lineCoverageFile);
if (lineCoverageFile.exists()) {
this.lineCoverageFiles.add(lineCoverageFile);
} else {
LOG.info("ignoring absent line coverage file " + lineCoverageFile.getAbsolutePath());
}
return this;
}

Expand All @@ -173,7 +177,11 @@ public Builder mutationResultsFiles(final List<File> mutationResultsFiles) {

public Builder addMutationResultsFile(final File mutationResultsFile) {
validateFile(mutationResultsFile);
this.mutationResultsFiles.add(mutationResultsFile);
if (mutationResultsFile.exists()) {
this.mutationResultsFiles.add(mutationResultsFile);
} else {
LOG.info("ignoring absent mutation results file " + mutationResultsFile.getAbsolutePath());
}
return this;
}

Expand Down Expand Up @@ -273,8 +281,9 @@ private void validateFile(final File file) {
if (file == null) {
throw new IllegalArgumentException("file is null");
}
if (!file.exists() || !file.isFile()) {
throw new IllegalArgumentException(file.getAbsolutePath() + " does not exist or is not a file");
// a non existent file shouldn't prevent the aggregator from being built
if (file.exists() && !file.isFile()) {
throw new IllegalArgumentException(file.getAbsolutePath() + "is not a file");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class ReportAggregatorBuilderTest {

private static final String NOT_A_FILE = "does not exist or is not a file";
private static final String NOT_A_FILE = "is not a file";
private static final String NOT_A_DIR = "is not a directory";
private static final String IS_NULL = "is null";
@Rule
Expand All @@ -38,10 +38,10 @@ public void testLineCoverageFiles_withNull() {

@Test
public void testLineCoverageFiles_withFake() {
this.expected.expect(IllegalArgumentException.class);
this.expected.expectMessage(Matchers.containsString(NOT_A_FILE));
ReportAggregator.Builder builder = ReportAggregator.builder()
.lineCoverageFiles(Arrays.asList(new File("doesnotexist.xml")));

ReportAggregator.builder().lineCoverageFiles(Arrays.asList(new File("doesnotexist.xml")));
assertTrue(builder.getMutationResultsFiles().isEmpty());
}

@Test
Expand All @@ -62,10 +62,10 @@ public void testMutationResultsFiles_withNull() {

@Test
public void testMutationResultsFiles_withFake() {
this.expected.expect(IllegalArgumentException.class);
this.expected.expectMessage(Matchers.containsString(NOT_A_FILE));
ReportAggregator.Builder builder = ReportAggregator.builder()
.mutationResultsFiles(Arrays.asList(new File("doesnotexist.xml")));

ReportAggregator.builder().mutationResultsFiles(Arrays.asList(new File("doesnotexist.xml")));
assertTrue(builder.getMutationResultsFiles().isEmpty());
}

@Test
Expand Down

0 comments on commit 6fc727c

Please sign in to comment.