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 1da8d2b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 45 deletions.
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 @@ -55,9 +55,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 +75,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

0 comments on commit 1da8d2b

Please sign in to comment.