Skip to content

Commit

Permalink
Issue #13809: Kill mutation in CommonUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 authored and nrmancuso committed Nov 12, 2023
1 parent 334760d commit d52eb5d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 31 deletions.
4 changes: 2 additions & 2 deletions config/pitest-suppressions/pitest-common-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<mutatedClass>com.puppycrawl.tools.checkstyle.Checker</mutatedClass>
<mutatedMethod>acceptFileStarted</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/utils/CommonUtil::relativizeAndNormalizePath with argument</description>
<lineContent>final String stripped = CommonUtil.relativizeAndNormalizePath(basedir, fileName);</lineContent>
<description>replaced call to com/puppycrawl/tools/checkstyle/utils/CommonUtil::relativizePath with argument</description>
<lineContent>final String stripped = CommonUtil.relativizePath(basedir, fileName);</lineContent>
</mutation>

<mutation unstable="false">
Expand Down
18 changes: 0 additions & 18 deletions config/pitest-suppressions/pitest-utils-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@
<lineContent>&amp;&amp; parent.getParent().getType() == memberType</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>CommonUtil.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.utils.CommonUtil</mutatedClass>
<mutatedMethod>relativizeAndNormalizePath</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to java/nio/file/Path::normalize with receiver</description>
<lineContent>final Path pathAbsolute = Paths.get(path).normalize();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>CommonUtil.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.utils.CommonUtil</mutatedClass>
<mutatedMethod>relativizeAndNormalizePath</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to java/nio/file/Path::normalize with receiver</description>
<lineContent>final Path pathBase = Paths.get(baseDirectory).normalize();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>ModuleReflectionUtil.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil</mutatedClass>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private SortedSet<Violation> processFile(File file) throws CheckstyleException {
* @return {@code true} if the file is accepted.
*/
private boolean acceptFileStarted(String fileName) {
final String stripped = CommonUtil.relativizeAndNormalizePath(basedir, fileName);
final String stripped = CommonUtil.relativizePath(basedir, fileName);
return beforeExecutionFileFilters.accept(stripped);
}

Expand All @@ -387,7 +387,7 @@ private boolean acceptFileStarted(String fileName) {
*/
@Override
public void fireFileStarted(String fileName) {
final String stripped = CommonUtil.relativizeAndNormalizePath(basedir, fileName);
final String stripped = CommonUtil.relativizePath(basedir, fileName);
final AuditEvent event = new AuditEvent(this, stripped);
for (final AuditListener listener : listeners) {
listener.fileStarted(event);
Expand All @@ -402,7 +402,7 @@ public void fireFileStarted(String fileName) {
*/
@Override
public void fireErrors(String fileName, SortedSet<Violation> errors) {
final String stripped = CommonUtil.relativizeAndNormalizePath(basedir, fileName);
final String stripped = CommonUtil.relativizePath(basedir, fileName);
boolean hasNonFilteredViolations = false;
for (final Violation element : errors) {
final AuditEvent event = new AuditEvent(this, stripped, element);
Expand All @@ -426,7 +426,7 @@ public void fireErrors(String fileName, SortedSet<Violation> errors) {
*/
@Override
public void fireFileFinished(String fileName) {
final String stripped = CommonUtil.relativizeAndNormalizePath(basedir, fileName);
final String stripped = CommonUtil.relativizePath(basedir, fileName);
final AuditEvent event = new AuditEvent(this, stripped);
for (final AuditListener listener : listeners) {
listener.fileFinished(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static String baseClassName(String type) {
}

/**
* Constructs a normalized relative path between base directory and a given path.
* Constructs a relative path between base directory and a given path.
*
* @param baseDirectory
* the base path to which given path is relativized
Expand All @@ -255,14 +255,14 @@ public static String baseClassName(String type) {
* @return the relative normalized path between base directory and
* path or path if base directory is null.
*/
public static String relativizeAndNormalizePath(final String baseDirectory, final String path) {
public static String relativizePath(final String baseDirectory, final String path) {
final String resultPath;
if (baseDirectory == null) {
resultPath = path;
}
else {
final Path pathAbsolute = Paths.get(path).normalize();
final Path pathBase = Paths.get(baseDirectory).normalize();
final Path pathAbsolute = Paths.get(path);
final Path pathBase = Paths.get(baseDirectory);
resultPath = pathBase.relativize(pathAbsolute).toString();
}
return resultPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testBaseClassNameForSimpleName() {

@Test
public void testRelativeNormalizedPath() {
final String relativePath = CommonUtil.relativizeAndNormalizePath("/home", "/home/test");
final String relativePath = CommonUtil.relativizePath("/home", "/home/test");

assertWithMessage("Invalid relative path")
.that(relativePath)
Expand All @@ -210,7 +210,7 @@ public void testRelativeNormalizedPath() {

@Test
public void testRelativeNormalizedPathWithNullBaseDirectory() {
final String relativePath = CommonUtil.relativizeAndNormalizePath(null, "/tmp");
final String relativePath = CommonUtil.relativizePath(null, "/tmp");

assertWithMessage("Invalid relative path")
.that(relativePath)
Expand All @@ -223,7 +223,7 @@ public void testRelativeNormalizedPathWithDenormalizedBaseDirectory() throws IOE
final String absoluteFilePath = sampleAbsolutePath + "/SampleFile.java";
final String basePath = sampleAbsolutePath + PATH_DENORMALIZER;

final String relativePath = CommonUtil.relativizeAndNormalizePath(basePath,
final String relativePath = CommonUtil.relativizePath(basePath,
absoluteFilePath);

assertWithMessage("Invalid relative path")
Expand Down

0 comments on commit d52eb5d

Please sign in to comment.