Skip to content

Commit e16b3bc

Browse files
Gaoyan1999romani
authored andcommitted
Issue #18034: Resolve PIT Mutation Suppression for NonVoidMethodCallMutation in Imports
1 parent 0cd8f7c commit e16b3bc

3 files changed

Lines changed: 29 additions & 40 deletions

File tree

config/pitest-suppressions/pitest-imports-suppressions.xml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<suppressedMutations>
3-
<mutation unstable="false">
4-
<sourceFile>ImportControlCheck.java</sourceFile>
5-
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck</mutatedClass>
6-
<mutatedMethod>setFile</mutatedMethod>
7-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
8-
<description>removed call to java/lang/String::valueOf</description>
9-
<lineContent>throw new IllegalArgumentException(UNABLE_TO_LOAD + uri, exc);</lineContent>
10-
</mutation>
11-
12-
<mutation unstable="false">
13-
<sourceFile>ImportControlLoader.java</sourceFile>
14-
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.imports.ImportControlLoader</mutatedClass>
15-
<mutatedMethod>load</mutatedMethod>
16-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
17-
<description>removed call to java/lang/String::valueOf</description>
18-
<lineContent>throw new CheckstyleException(&quot;unable to read &quot; + uri, exc);</lineContent>
19-
</mutation>
20-
21-
<mutation unstable="false">
22-
<sourceFile>ImportControlLoader.java</sourceFile>
23-
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.imports.ImportControlLoader</mutatedClass>
24-
<mutatedMethod>loadUri</mutatedMethod>
25-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
26-
<description>removed call to java/lang/String::valueOf</description>
27-
<lineContent>throw new CheckstyleException(&quot;syntax error in url &quot; + uri, exc);</lineContent>
28-
</mutation>
29-
30-
<mutation unstable="false">
31-
<sourceFile>ImportControlLoader.java</sourceFile>
32-
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.imports.ImportControlLoader</mutatedClass>
33-
<mutatedMethod>loadUri</mutatedMethod>
34-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
35-
<description>removed call to java/lang/String::valueOf</description>
36-
<lineContent>throw new CheckstyleException(&quot;unable to find &quot; + uri, exc);</lineContent>
37-
</mutation>
38-
393
<mutation unstable="false">
404
<sourceFile>ImportOrderCheck.java</sourceFile>
415
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck</mutatedClass>

src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.getExpectedThrowable;
2828

2929
import java.io.File;
30+
import java.net.URI;
3031
import java.nio.file.Files;
3132
import java.util.Arrays;
3233
import java.util.List;
@@ -148,6 +149,26 @@ public void testBroken() throws Exception {
148149
}
149150
}
150151

152+
@Test
153+
public void testSetFileContainsUriInMessage() {
154+
final ImportControlCheck check = new ImportControlCheck();
155+
final File missingFile = new File(temporaryFolder, "missing-import-control.xml");
156+
final URI uri = missingFile.toURI();
157+
158+
final IllegalArgumentException exception =
159+
getExpectedThrowable(IllegalArgumentException.class, () -> check.setFile(uri));
160+
161+
assertWithMessage("Invalid exception message")
162+
.that(exception.getMessage())
163+
.isEqualTo("Unable to load " + uri);
164+
assertWithMessage("Invalid exception cause")
165+
.that(exception.getCause())
166+
.isInstanceOf(CheckstyleException.class);
167+
assertWithMessage("Cause message should contain uri")
168+
.that(exception.getCause().getMessage())
169+
.isEqualTo("unable to find " + uri);
170+
}
171+
151172
@Test
152173
public void testOneRegExp() throws Exception {
153174
final String[] expected = {"13:1: " + getCheckMessage(MSG_DISALLOWED, "java.io.File")};

src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlLoaderTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ public void testLoad() throws CheckstyleException {
6060

6161
@Test
6262
public void testWrongFormatUri() throws Exception {
63+
final URI uri = new URI("aaa://" + getPath("InputImportControlLoaderComplete.xml"));
6364
try {
64-
ImportControlLoader.load(new URI("aaa://"
65-
+ getPath("InputImportControlLoaderComplete.xml")));
65+
ImportControlLoader.load(uri);
6666
assertWithMessage("exception expected").fail();
6767
}
6868
catch (CheckstyleException exc) {
6969
assertWithMessage("Invalid exception class")
7070
.that(exc.getCause())
7171
.isInstanceOf(MalformedURLException.class);
72+
assertWithMessage("Invalid exception message")
73+
.that(exc.getMessage())
74+
.isEqualTo("syntax error in url " + uri);
7275
assertWithMessage("Invalid exception message")
7376
.that(exc)
7477
.hasCauseThat()
@@ -119,10 +122,11 @@ public String getValue(int index) {
119122
// and is difficult to emulate
120123
public void testLoadThrowsException() {
121124
final InputSource source = new InputSource();
125+
final URI uri = new File(getPath("InputImportControlLoaderComplete.xml")).toURI();
122126
try {
123127
final Class<?> clazz = ImportControlLoader.class;
124128
TestUtil.invokeVoidStaticMethod(clazz, "load", source,
125-
new File(getPath("InputImportControlLoaderComplete.xml")).toURI());
129+
uri);
126130
assertWithMessage("exception expected").fail();
127131
}
128132
catch (ReflectiveOperationException exc) {
@@ -133,7 +137,7 @@ public void testLoadThrowsException() {
133137
.that(exc)
134138
.hasCauseThat()
135139
.hasMessageThat()
136-
.startsWith("unable to read");
140+
.isEqualTo("unable to read " + uri);
137141
}
138142
}
139143

0 commit comments

Comments
 (0)