Skip to content

Commit

Permalink
Mutate stream returns to Stream.empty
Browse files Browse the repository at this point in the history
Previously stream returns were mutated to null. This was inconsistent
and resulted in less stable mutations. Special handling was also needed
to filter out null returns used only in flatMaps, as these acted like
stream.empty.

Mutating to Stream.empty is simpler and results in more useful mutations
that are harder to detect.
  • Loading branch information
Henry Coles committed Oct 12, 2021
1 parent a26264f commit 2682c9e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 398 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public boolean test(MutationDetails a) {
return returnsZeroValue(method, mutatedInstruction)
|| returnsEmptyString(method, mutatedInstruction)
|| returns(method, mutatedInstruction, "java/util/Optional","empty")
|| returns(method, mutatedInstruction, "java/util/stream/Stream","empty")
|| returns(method, mutatedInstruction, "java/util/Collections","emptyList")
|| returns(method, mutatedInstruction, "java/util/Collections","emptySet")
|| returns(method, mutatedInstruction, "java/util/List","of")
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ org.pitest.mutationtest.build.intercept.kotlin.KotlinFilterFactory
org.pitest.mutationtest.filter.LimitNumberOfMutationsPerClassFilterFactory
org.pitest.mutationtest.build.intercept.equivalent.EqualsPerformanceShortcutFilterFactory
org.pitest.mutationtest.build.intercept.equivalent.EquivalentReturnMutationFilter
org.pitest.mutationtest.build.intercept.equivalent.NullFlatMapFilterFactory

org.pitest.plugin.export.MutantExportFactory
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,6 @@ public void filtersEquivalentReturnValsMutants() {
assertThat(actual).isEmpty();
}

@Test
public void filtersEquivalentNullStreamMutantsUsedInFlatMapCalls() {
final Collection<MutationDetails> actual = findMutants(HasPrivateStreamMethodUsedOnlyInSingleFlatMap.class);

this.data.setFeatures(Collections.singletonList("-FNULLSTREAM"));
final Collection<MutationDetails> actualWithoutFilter = findMutants(HasPrivateStreamMethodUsedOnlyInSingleFlatMap.class);

assertThat(actual.size()).isLessThan(actualWithoutFilter.size());
}

@Test
public void filterMutantsInJavaRecords() {
this.data.setDetectInlinedCode(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.pitest.mutationtest.engine.gregor.mutators.returns.BooleanFalseReturnValsMutator.FALSE_RETURNS;
Expand Down Expand Up @@ -157,6 +158,11 @@ public void filtersEquivalentSetMutants() {
public void filtersEquivalentOptionalMutants() {
verifier.assertFiltersNMutationFromClass(1, AlreadyReturnsEmptyOptional.class);
}

@Test
public void filtersEquivalentStreamMutants() {
verifier.assertFiltersNMutationFromClass(1, AlreadyReturnsEmptyStream.class);
}
}

class Widget{}
Expand Down Expand Up @@ -334,3 +340,9 @@ public Optional<String> a() {
return Optional.empty();
}
}

class AlreadyReturnsEmptyStream {
public Stream<String> a() {
return Stream.empty();
}
}
Loading

0 comments on commit 2682c9e

Please sign in to comment.