-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1116 from hcoles/feature/line_filter
feature to exclude lines 0 and 1 from mutation
- Loading branch information
Showing
6 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...-entry/src/main/java/org/pitest/mutationtest/build/intercept/exclude/FirstLineFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.pitest.mutationtest.build.intercept.exclude; | ||
|
||
import org.pitest.bytecode.analysis.ClassTree; | ||
import org.pitest.mutationtest.build.InterceptorType; | ||
import org.pitest.mutationtest.build.MutationInterceptor; | ||
import org.pitest.mutationtest.engine.Mutater; | ||
import org.pitest.mutationtest.engine.MutationDetails; | ||
|
||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
class FirstLineFilter implements MutationInterceptor { | ||
@Override | ||
public InterceptorType type() { | ||
return InterceptorType.FILTER; | ||
} | ||
|
||
@Override | ||
public void begin(ClassTree clazz) { | ||
|
||
} | ||
|
||
@Override | ||
public Collection<MutationDetails> intercept(Collection<MutationDetails> mutations, Mutater unused) { | ||
return mutations.stream() | ||
.filter(m -> m.getLineNumber() > 1) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
|
||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ain/java/org/pitest/mutationtest/build/intercept/exclude/FirstLineInterceptorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.pitest.mutationtest.build.intercept.exclude; | ||
|
||
import org.pitest.mutationtest.build.InterceptorParameters; | ||
import org.pitest.mutationtest.build.MutationInterceptor; | ||
import org.pitest.mutationtest.build.MutationInterceptorFactory; | ||
import org.pitest.plugin.Feature; | ||
|
||
public class FirstLineInterceptorFactory implements MutationInterceptorFactory { | ||
|
||
@Override | ||
public String description() { | ||
return "Filters mutants with line number <= 1"; | ||
} | ||
|
||
@Override | ||
public MutationInterceptor createInterceptor(InterceptorParameters params) { | ||
return new FirstLineFilter(); | ||
} | ||
|
||
@Override | ||
public Feature provides() { | ||
return Feature.named("nofirstline") | ||
.withDescription(description()) | ||
.withOnByDefault(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ry/src/test/java/org/pitest/mutationtest/build/intercept/exclude/FirstLineFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.pitest.mutationtest.build.intercept.exclude; | ||
|
||
import junit.framework.TestCase; | ||
import org.junit.Test; | ||
import org.pitest.mutationtest.engine.MutationDetails; | ||
import org.pitest.mutationtest.engine.MutationDetailsMother; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class FirstLineFilterTest { | ||
|
||
FirstLineFilter underTest = new FirstLineFilter(); | ||
|
||
@Test | ||
public void doesNotFilterMutantsAfterFirstLine() { | ||
List<MutationDetails> mutants = MutationDetailsMother.aMutationDetail() | ||
.withLineNumber(2) | ||
.build(10); | ||
|
||
assertThat(underTest.intercept(mutants, null)).containsAll(mutants); | ||
} | ||
|
||
@Test | ||
public void filtersMutantsOnLine1() { | ||
MutationDetails line1 = MutationDetailsMother.aMutationDetail() | ||
.withLineNumber(1) | ||
.build(); | ||
|
||
MutationDetails line2 = MutationDetailsMother.aMutationDetail() | ||
.withLineNumber(2) | ||
.build(); | ||
|
||
assertThat(underTest.intercept(asList(line1, line2), null)).containsExactly(line2); | ||
} | ||
|
||
@Test | ||
public void filtersMutantsOnLine0() { | ||
MutationDetails line0 = MutationDetailsMother.aMutationDetail() | ||
.withLineNumber(0) | ||
.build(); | ||
|
||
MutationDetails line2 = MutationDetailsMother.aMutationDetail() | ||
.withLineNumber(2) | ||
.build(); | ||
|
||
assertThat(underTest.intercept(asList(line0, line2), null)).containsExactly(line2); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...java/org/pitest/mutationtest/build/intercept/exclude/FirstLineInterceptorFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.pitest.mutationtest.build.intercept.exclude; | ||
|
||
import org.junit.Test; | ||
import org.pitest.mutationtest.build.InterceptorType; | ||
import org.pitest.verifier.interceptors.FactoryVerifier; | ||
|
||
public class FirstLineInterceptorFactoryTest { | ||
|
||
@Test | ||
public void isOnChain() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.isOnChain(); | ||
} | ||
|
||
@Test | ||
public void isOffByDefault() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.isOffByDefault(); | ||
} | ||
|
||
|
||
@Test | ||
public void featureIsCalledNoFirstLine() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.featureName().isEqualTo("nofirstline"); | ||
} | ||
|
||
@Test | ||
public void createsFilters() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.createsInterceptorsOfType(InterceptorType.FILTER); | ||
} | ||
|
||
|
||
} |
77 changes: 77 additions & 0 deletions
77
pitest-entry/src/test/java/org/pitest/verifier/interceptors/FactoryVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.pitest.verifier.interceptors; | ||
|
||
import org.assertj.core.api.AbstractStringAssert; | ||
import org.pitest.mutationtest.build.InterceptorParameters; | ||
import org.pitest.mutationtest.build.InterceptorType; | ||
import org.pitest.mutationtest.build.MutationInterceptorFactory; | ||
import org.pitest.mutationtest.config.PluginServices; | ||
import org.pitest.mutationtest.config.ReportOptions; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class FactoryVerifier { | ||
|
||
private final MutationInterceptorFactory factory; | ||
private final ReportOptions data; | ||
|
||
public FactoryVerifier(MutationInterceptorFactory factory) { | ||
this(factory, emptyOptions()); | ||
} | ||
|
||
public FactoryVerifier(MutationInterceptorFactory factory, ReportOptions data) { | ||
this.factory = factory; | ||
this.data = data; | ||
} | ||
|
||
public static FactoryVerifier confirmFactory(MutationInterceptorFactory factory) { | ||
return new FactoryVerifier(factory); | ||
} | ||
|
||
public void isOnChain() { | ||
factoryIsOnChain(factory.getClass()); | ||
} | ||
|
||
public FactoryVerifier withData(ReportOptions data) { | ||
return new FactoryVerifier(factory, data); | ||
} | ||
|
||
public void createsInterceptorsOfType(InterceptorType type) { | ||
assertThat(factory.createInterceptor(emptyParams(data)).type()).isEqualTo(type); | ||
} | ||
|
||
public void isOnByDefault() { | ||
assertThat(factory.provides().isOnByDefault()).isTrue(); | ||
} | ||
|
||
public void isOffByDefault() { | ||
assertThat(factory.provides().isOnByDefault()).isFalse(); | ||
} | ||
|
||
public AbstractStringAssert<?> featureName() { | ||
return assertThat(factory.provides().name()); | ||
} | ||
|
||
private static void factoryIsOnChain(Class<?> factory) { | ||
List<Class<?>> allInterceptors = PluginServices.makeForContextLoader().findInterceptors().stream() | ||
.map(MutationInterceptorFactory::getClass) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(allInterceptors).contains(factory); | ||
} | ||
|
||
public static InterceptorParameters emptyParams(ReportOptions data) { | ||
return new InterceptorParameters(null, data, null, null); | ||
} | ||
|
||
public static ReportOptions emptyOptions() { | ||
ReportOptions data = new ReportOptions(); | ||
data.setSourceDirs(Collections.emptyList()); | ||
data.setReportDir(""); | ||
return data; | ||
} | ||
|
||
} |