Skip to content

Commit

Permalink
Issue checkstyle#13809: kill mutation for AuditEventDefaultFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 committed Oct 4, 2023
1 parent a7fa83a commit 02690a6
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter.java</fileName>
<specifier>argument</specifier>
<message>incompatible argument for parameter capacity of StringBuilder.</message>
<lineContent>final StringBuilder sb = new StringBuilder(bufLen);</lineContent>
<details>
found : int
required: @NonNegative int
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/DetailAstImpl.java</fileName>
<specifier>argument</specifier>
Expand Down
27 changes: 0 additions & 27 deletions config/pitest-suppressions/pitest-common-suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressedMutations>
<mutation unstable="false">
<sourceFile>AuditEventDefaultFormatter.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.AuditEventDefaultFormatter</mutatedClass>
<mutatedMethod>format</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter::calculateBufferLength</description>
<lineContent>final int bufLen = calculateBufferLength(event, severityLevelName.length());</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>AuditEventDefaultFormatter.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.AuditEventDefaultFormatter</mutatedClass>
<mutatedMethod>format</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to java/lang/String::length</description>
<lineContent>final int bufLen = calculateBufferLength(event, severityLevelName.length());</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>AuditEventDefaultFormatter.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.AuditEventDefaultFormatter</mutatedClass>
<mutatedMethod>format</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter::calculateBufferLength with argument</description>
<lineContent>final int bufLen = calculateBufferLength(event, severityLevelName.length());</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>Checker.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.Checker</mutatedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
*/
public class AuditEventDefaultFormatter implements AuditEventFormatter {

/** Length of all separators. */
private static final int LENGTH_OF_ALL_SEPARATORS = 10;

/** Suffix of module names like XXXXCheck. */
private static final String SUFFIX = "Check";

Expand All @@ -55,9 +52,7 @@ public String format(AuditEvent event) {
severityLevelName = severityLevel.getName().toUpperCase(Locale.US);
}

// Avoid StringBuffer.expandCapacity
final int bufLen = calculateBufferLength(event, severityLevelName.length());
final StringBuilder sb = new StringBuilder(bufLen);
final StringBuilder sb = new StringBuilder();

sb.append('[').append(severityLevelName).append("] ")
.append(fileName).append(':').append(event.getLine());
Expand All @@ -77,21 +72,6 @@ public String format(AuditEvent event) {
return sb.toString();
}

/**
* Returns the length of the buffer for StringBuilder.
* bufferLength = fileNameLength + messageLength + lengthOfAllSeparators +
* + severityNameLength + checkNameLength.
*
* @param event audit event.
* @param severityLevelNameLength length of severity level name.
* @return the length of the buffer for StringBuilder.
*/
private static int calculateBufferLength(AuditEvent event, int severityLevelNameLength) {
return LENGTH_OF_ALL_SEPARATORS + event.getFileName().length()
+ event.getMessage().length() + severityLevelNameLength
+ getCheckShortName(event).length();
}

/**
* Returns check name without 'Check' suffix.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
import com.puppycrawl.tools.checkstyle.api.Violation;
import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;

public class AuditEventDefaultFormatterTest {

Expand Down Expand Up @@ -74,20 +73,6 @@ public void testFormatModuleWithModuleId() {
.isEqualTo(expected);
}

@Test
public void testCalculateBufferLength() throws Exception {
final Violation violation = new Violation(1, 1,
"messages.properties", "key", null, SeverityLevel.ERROR, null,
getClass(), null);
final AuditEvent auditEvent = new AuditEvent(new Object(), "fileName", violation);
final int result = TestUtil.invokeStaticMethod(AuditEventDefaultFormatter.class,
"calculateBufferLength", auditEvent, SeverityLevel.ERROR.ordinal());

assertWithMessage("Buffer length is not expected")
.that(result)
.isEqualTo(54);
}

private static final class TestModuleCheck {

// no code
Expand Down

0 comments on commit 02690a6

Please sign in to comment.