From ccadc49466f8a5f37d4f4ec18677ffcd5e7be26d Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Wed, 9 Nov 2022 19:27:11 +0000 Subject: [PATCH] filter mutations to empty Map.of --- .../EquivalentReturnMutationFilter.java | 1 + pitest-modern-verification/pom.xml | 68 +++++++++++++++++++ .../EquivalentReturnMutationFilterTest.java | 51 ++++++++++++++ .../verification/equivalent/HasListOf.java | 9 +++ .../verification/equivalent/HasMapOf.java | 10 +++ .../verification/equivalent/HasSetOf.java | 9 +++ .../equivalent/NonEmptyMapOf.java | 9 +++ pom.xml | 16 ++++- 8 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 pitest-modern-verification/pom.xml create mode 100644 pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/EquivalentReturnMutationFilterTest.java create mode 100644 pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasListOf.java create mode 100644 pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasMapOf.java create mode 100644 pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasSetOf.java create mode 100644 pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/NonEmptyMapOf.java diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/equivalent/EquivalentReturnMutationFilter.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/equivalent/EquivalentReturnMutationFilter.java index f117af6a2..6ca5e6d53 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/equivalent/EquivalentReturnMutationFilter.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/equivalent/EquivalentReturnMutationFilter.java @@ -111,6 +111,7 @@ private static Match loadsEmptyReturnOntoStack() { .or(noArgsCall("java/util/Collections", "emptyList")) .or(noArgsCall("java/util/Collections", "emptyMap")) .or(noArgsCall("java/util/Collections", "emptySet")) + .or(noArgsCall("java/util/Map", "of")) .or(noArgsCall("java/util/List", "of")) .or(noArgsCall("java/util/Set", "of")); } diff --git a/pitest-modern-verification/pom.xml b/pitest-modern-verification/pom.xml new file mode 100644 index 000000000..8d0919a84 --- /dev/null +++ b/pitest-modern-verification/pom.xml @@ -0,0 +1,68 @@ + + + + pitest-parent + org.pitest + ${revision} + + 4.0.0 + + pitest-modern-verification + Checks pitest against latest support version of java + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + maven-compiler-plugin + + 17 + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + + + junit + junit + ${junit.version} + test + + + org.pitest + pitest-entry + ${project.version} + test + + + org.pitest + pitest-entry + test-jar + ${project.version} + test + + + org.pitest + pitest + test-jar + ${project.version} + test + + + + diff --git a/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/EquivalentReturnMutationFilterTest.java b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/EquivalentReturnMutationFilterTest.java new file mode 100644 index 000000000..3d7e2a998 --- /dev/null +++ b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/EquivalentReturnMutationFilterTest.java @@ -0,0 +1,51 @@ +package org.pitest.filters.verification.equivalent; + +import org.junit.Test; +import org.pitest.mutationtest.build.intercept.equivalent.EquivalentReturnMutationFilter; +import org.pitest.verifier.interceptors.InterceptorVerifier; +import org.pitest.verifier.interceptors.VerifierStart; + +import static org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator.EMPTY_RETURNS; + + +public class EquivalentReturnMutationFilterTest { + + InterceptorVerifier v = VerifierStart.forInterceptorFactory(new EquivalentReturnMutationFilter()); + + @Test + public void filtersWhenMapOfHasNoArgs() { + v.usingMutator(EMPTY_RETURNS) + .forClass(HasMapOf.class) + .forAnyCode() + .allMutantsAreFiltered() + .verify(); + } + + @Test + public void filtersWhenSetOfHasNoArgs() { + v.usingMutator(EMPTY_RETURNS) + .forClass(HasSetOf.class) + .forAnyCode() + .allMutantsAreFiltered() + .verify(); + } + + @Test + public void filtersWhenListOfHasNoArgs() { + v.usingMutator(EMPTY_RETURNS) + .forClass(HasListOf.class) + .forAnyCode() + .allMutantsAreFiltered() + .verify(); + } + + @Test + public void doesNotFilterNonEmptyMapOf() { + v.usingMutator(EMPTY_RETURNS) + .forClass(NonEmptyMapOf.class) + .forAnyCode() + .noMutantsAreFiltered() + .verify(); + } + +} diff --git a/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasListOf.java b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasListOf.java new file mode 100644 index 000000000..2521b74a9 --- /dev/null +++ b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasListOf.java @@ -0,0 +1,9 @@ +package org.pitest.filters.verification.equivalent; + +import java.util.List; + +public class HasListOf { + public List mutateMe() { + return List.of(); + } +} \ No newline at end of file diff --git a/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasMapOf.java b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasMapOf.java new file mode 100644 index 000000000..94d22fb5b --- /dev/null +++ b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasMapOf.java @@ -0,0 +1,10 @@ +package org.pitest.filters.verification.equivalent; + +import java.util.Map; + +public class HasMapOf { + + public Map mutateMe() { + return Map.of(); + } +} diff --git a/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasSetOf.java b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasSetOf.java new file mode 100644 index 000000000..8cb2e9d91 --- /dev/null +++ b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/HasSetOf.java @@ -0,0 +1,9 @@ +package org.pitest.filters.verification.equivalent; + +import java.util.Set; + +public class HasSetOf { + public Set mutateMe() { + return Set.of(); + } +} diff --git a/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/NonEmptyMapOf.java b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/NonEmptyMapOf.java new file mode 100644 index 000000000..3ca7bc6c7 --- /dev/null +++ b/pitest-modern-verification/src/test/java/org/pitest/filters/verification/equivalent/NonEmptyMapOf.java @@ -0,0 +1,9 @@ +package org.pitest.filters.verification.equivalent; + +import java.util.Map; + +public class NonEmptyMapOf { + public Map mutateMe() { + return Map.of("A", "Z"); + } +} diff --git a/pom.xml b/pom.xml index 56af079b6..910b1d851 100644 --- a/pom.xml +++ b/pom.xml @@ -100,11 +100,23 @@ pitest-java8-verification - pitest-maven-verification + pitest-maven-verification + + verification-modern + + [17,18,19] + + !skipTests + + + + pitest-modern-verification + + release @@ -259,7 +271,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.10.1 1.8 1.8