Skip to content

Commit 2492c76

Browse files
committed
Issue checkstyle#13809: kill mutation for AuditEventDefaultFormatter
1 parent a7fa83a commit 2492c76

File tree

3 files changed

+1
-59
lines changed

3 files changed

+1
-59
lines changed

config/pitest-suppressions/pitest-common-suppressions.xml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<suppressedMutations>
3-
<mutation unstable="false">
4-
<sourceFile>AuditEventDefaultFormatter.java</sourceFile>
5-
<mutatedClass>com.puppycrawl.tools.checkstyle.AuditEventDefaultFormatter</mutatedClass>
6-
<mutatedMethod>format</mutatedMethod>
7-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
8-
<description>removed call to com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter::calculateBufferLength</description>
9-
<lineContent>final int bufLen = calculateBufferLength(event, severityLevelName.length());</lineContent>
10-
</mutation>
11-
12-
<mutation unstable="false">
13-
<sourceFile>AuditEventDefaultFormatter.java</sourceFile>
14-
<mutatedClass>com.puppycrawl.tools.checkstyle.AuditEventDefaultFormatter</mutatedClass>
15-
<mutatedMethod>format</mutatedMethod>
16-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
17-
<description>removed call to java/lang/String::length</description>
18-
<lineContent>final int bufLen = calculateBufferLength(event, severityLevelName.length());</lineContent>
19-
</mutation>
20-
21-
<mutation unstable="false">
22-
<sourceFile>AuditEventDefaultFormatter.java</sourceFile>
23-
<mutatedClass>com.puppycrawl.tools.checkstyle.AuditEventDefaultFormatter</mutatedClass>
24-
<mutatedMethod>format</mutatedMethod>
25-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
26-
<description>replaced call to com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter::calculateBufferLength with argument</description>
27-
<lineContent>final int bufLen = calculateBufferLength(event, severityLevelName.length());</lineContent>
28-
</mutation>
29-
303
<mutation unstable="false">
314
<sourceFile>Checker.java</sourceFile>
325
<mutatedClass>com.puppycrawl.tools.checkstyle.Checker</mutatedClass>

src/main/java/com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ public String format(AuditEvent event) {
5555
severityLevelName = severityLevel.getName().toUpperCase(Locale.US);
5656
}
5757

58-
// Avoid StringBuffer.expandCapacity
59-
final int bufLen = calculateBufferLength(event, severityLevelName.length());
60-
final StringBuilder sb = new StringBuilder(bufLen);
58+
final StringBuilder sb = new StringBuilder();
6159

6260
sb.append('[').append(severityLevelName).append("] ")
6361
.append(fileName).append(':').append(event.getLine());
@@ -77,21 +75,6 @@ public String format(AuditEvent event) {
7775
return sb.toString();
7876
}
7977

80-
/**
81-
* Returns the length of the buffer for StringBuilder.
82-
* bufferLength = fileNameLength + messageLength + lengthOfAllSeparators +
83-
* + severityNameLength + checkNameLength.
84-
*
85-
* @param event audit event.
86-
* @param severityLevelNameLength length of severity level name.
87-
* @return the length of the buffer for StringBuilder.
88-
*/
89-
private static int calculateBufferLength(AuditEvent event, int severityLevelNameLength) {
90-
return LENGTH_OF_ALL_SEPARATORS + event.getFileName().length()
91-
+ event.getMessage().length() + severityLevelNameLength
92-
+ getCheckShortName(event).length();
93-
}
94-
9578
/**
9679
* Returns check name without 'Check' suffix.
9780
*

src/test/java/com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatterTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ public void testFormatModuleWithModuleId() {
7474
.isEqualTo(expected);
7575
}
7676

77-
@Test
78-
public void testCalculateBufferLength() throws Exception {
79-
final Violation violation = new Violation(1, 1,
80-
"messages.properties", "key", null, SeverityLevel.ERROR, null,
81-
getClass(), null);
82-
final AuditEvent auditEvent = new AuditEvent(new Object(), "fileName", violation);
83-
final int result = TestUtil.invokeStaticMethod(AuditEventDefaultFormatter.class,
84-
"calculateBufferLength", auditEvent, SeverityLevel.ERROR.ordinal());
85-
86-
assertWithMessage("Buffer length is not expected")
87-
.that(result)
88-
.isEqualTo(54);
89-
}
90-
9177
private static final class TestModuleCheck {
9278

9379
// no code

0 commit comments

Comments
 (0)