Skip to content

Commit

Permalink
feat: ignore absent ReportAggregatorBuilder files
Browse files Browse the repository at this point in the history
This commit ignores absent line coverage and mutation results files when
setting up the ReportAggregator. This is because it is possible for
these files to be specified, but not actually exist, by the
gradle-pitest-plugin when used in conjunction with mested gradle
subprojects.
  • Loading branch information
jrmcdonald committed Apr 28, 2023
1 parent 0f9f3dc commit f4a1947
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 f4a1947

Please sign in to comment.