Skip to content

Kill surviving mutations in SuppressWithNearbyTextFilter #12952

@stoyanK7

Description

@stoyanK7

After #12151 gets merged, it will introduce 2 new surviving mutations.

  <mutation unstable="false">
    <sourceFile>SuppressWithNearbyTextFilter.java</sourceFile>
    <mutatedClass>com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyTextFilter</mutatedClass>
    <mutatedMethod>accept</mutatedMethod>
    <mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
    <description>removed call to java/lang/String::equals</description>
    <lineContent>if (!cachedFileAbsolutePath.equals(eventFileTextAbsolutePath)) {</lineContent>
  </mutation>

  <mutation unstable="false">
    <sourceFile>SuppressWithNearbyTextFilter.java</sourceFile>
    <mutatedClass>com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyTextFilter</mutatedClass>
    <mutatedMethod>accept</mutatedMethod>
    <mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
    <description>removed conditional - replaced equality check with true</description>
    <lineContent>if (!cachedFileAbsolutePath.equals(eventFileTextAbsolutePath)) {</lineContent>
  </mutation>

First is the real line and the hardcoded mutation below it:

if (!cachedFileAbsolutePath.equals(eventFileTextAbsolutePath)) {
if (true) {

The mutation shows that there is no test to assert that the caching happens only once per file.

We need to write a test to assert that any method inside the if statement is called only once - could be collectSuppressions() or getFileText().


Because getFileText()'s implementation is the exact same in both this filter and SuppressWithPlainTextCommentFilter, it can be extracted to FilterUtil and we can assert that this method is invoked only once - 383b079

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions