Skip to content

Commit

Permalink
Merge pull request #1229 from hcoles/feature/expand_return_types
Browse files Browse the repository at this point in the history
mutate iterable to emptyList
  • Loading branch information
hcoles committed Jun 9, 2023
2 parents 6b5c769 + 8fc958b commit 7bdadd8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ public void filtersEquivalentOptionalMutantsInTryWithResourcesBlocksForOtherComp
public void filtersEquivalentStreamMutants() {
verifier.assertFiltersNMutationFromClass(1, AlreadyReturnsEmptyStream.class);
}

@Test
public void filtersEquivalentIterableMutants() {
verifier.assertFiltersNMutationFromClass(1, AlreadyReturnsEmptyIterable.class);
}
}

class Widget{}
Expand Down Expand Up @@ -475,4 +480,10 @@ class AlreadyReturnsEmptyStream {
public Stream<String> a() {
return Stream.empty();
}
}

class AlreadyReturnsEmptyIterable {
public Iterable<String> a() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AReturnMethodVisitor extends AbstractInsnMutator {
NON_NULL_MUTATIONS.put("java.util.Map", returnEmptyMap());
NON_NULL_MUTATIONS.put("java.util.Set", returnEmptySet());
NON_NULL_MUTATIONS.put("java.util.Collection", returnEmptyList());
NON_NULL_MUTATIONS.put("java.lang.Iterable", returnEmptyList());
}

AReturnMethodVisitor(final MethodMutatorFactory factory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.concurrent.Callable;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator.EMPTY_RETURNS;

Expand Down Expand Up @@ -174,6 +175,14 @@ public void mutatesToEmptyStream() {
assertThat(actual).isEmpty();
}

@Test
public void mutatesIterableToEmptyList() {
Iterable actual = v.forCallableClass(AnIterable.class)
.firstMutantReturnValue();

assertThat(actual).isEmpty();
}

private static class ObjectReturn implements Callable<Object> {
@Override
public Object call() throws Exception {
Expand Down Expand Up @@ -289,4 +298,11 @@ public Stream<String> call() throws Exception {
}
}

private static class AnIterable implements Callable<Iterable<String>> {
@Override
public Iterable<String> call() throws Exception {
return asList("hello");
}
}

}

0 comments on commit 7bdadd8

Please sign in to comment.