Skip to content

Commit

Permalink
Issue #12017: Kill surviving mutations in AbstractFileSetCheck relate…
Browse files Browse the repository at this point in the history
…d to fileExtensions
  • Loading branch information
Vyom-Yadav authored and nrmancuso committed Aug 9, 2022
1 parent 3968627 commit 1c92749
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 0 additions & 9 deletions .ci/pitest-suppressions/pitest-api-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
<lineContent>return Collections.unmodifiableSet(tokens);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>AbstractFileSetCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck</mutatedClass>
<mutatedMethod>getFileExtensions</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to java/util/Arrays::copyOf with argument</description>
<lineContent>return Arrays.copyOf(fileExtensions, fileExtensions.length);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>AbstractFileSetCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck</mutatedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ public void testMultiFileFireErrors() throws Exception {
.isEqualTo(2);
}

/**
* S2384 - Mutable members should not be stored or returned directly.
* Inspection is valid, a pure unit test is required as this condition can't be recreated in
* a test with checks and input file as none of the checks try to modify the fileExtensions.
*/
@Test
public void testCopiedArrayIsReturned() {
final DummyFileSetCheck check = new DummyFileSetCheck();
check.setFileExtensions(".tmp");
assertWithMessage("Extensions should be copied")
.that(check.getFileExtensions())
.isNotSameInstanceAs(check.getFileExtensions());
}

public static class DummyFileSetCheck extends AbstractFileSetCheck {

private static final String MSG_KEY = "File should not be empty.";
Expand Down

0 comments on commit 1c92749

Please sign in to comment.