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 e726b4e
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 398 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Read all about it at http://pitest.org
### 1.7.2 (unreleased)

* #943 Change default mutators - replace negate conditional with remove conditional
* #946 Mutate stream returns to empty stream instead of null

### 1.7.1

Expand Down
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 e726b4e

Please sign in to comment.