Skip to content

Commit

Permalink
Merge pull request #1107 from hcoles/feature/map_of
Browse files Browse the repository at this point in the history
filter mutations to empty Map.of
  • Loading branch information
hcoles committed Nov 10, 2022
2 parents b7dfa84 + ccadc49 commit d2ad3ea
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private static Match<AbstractInsnNode> 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"));
}
Expand Down
68 changes: 68 additions & 0 deletions pitest-modern-verification/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pitest-parent</artifactId>
<groupId>org.pitest</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>pitest-modern-verification</artifactId>
<description>Checks pitest against latest support version of java</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-entry</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-entry</artifactId>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.pitest.filters.verification.equivalent;

import java.util.List;

public class HasListOf {
public List<String> mutateMe() {
return List.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.pitest.filters.verification.equivalent;

import java.util.Map;

public class HasMapOf {

public Map<String,String> mutateMe() {
return Map.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.pitest.filters.verification.equivalent;

import java.util.Set;

public class HasSetOf {
public Set<String> mutateMe() {
return Set.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.pitest.filters.verification.equivalent;

import java.util.Map;

public class NonEmptyMapOf {
public Map<String,String> mutateMe() {
return Map.of("A", "Z");
}
}
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,23 @@
</activation>
<modules>
<module>pitest-java8-verification</module>
<module>pitest-maven-verification</module>
<module>pitest-maven-verification</module>
<!-- disabled until working with java 9+ -->
<!-- <module>pitest-groovy-verification</module> -->
</modules>
</profile>
<profile>
<id>verification-modern</id>
<activation>
<jdk>[17,18,19]</jdk>
<property>
<name>!skipTests</name>
</property>
</activation>
<modules>
<module>pitest-modern-verification</module>
</modules>
</profile>
<profile>
<id>release</id>
<activation>
Expand Down Expand Up @@ -259,7 +271,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down

0 comments on commit d2ad3ea

Please sign in to comment.