Skip to content

Commit

Permalink
migreate IncrementsMutatorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Mar 22, 2022
1 parent 2b9ba93 commit 226b08f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@
package org.pitest.mutationtest.engine.gregor.mutators;

import static org.junit.Assert.assertEquals;
import static org.pitest.mutationtest.engine.gregor.mutators.IncrementsMutator.INCREMENTS;

import java.util.Collection;
import java.util.concurrent.Callable;

import org.junit.Before;
import org.junit.Test;
import org.pitest.mutationtest.engine.Mutant;
import org.pitest.mutationtest.engine.MutationDetails;
import org.pitest.mutationtest.engine.gregor.MutatorTestBase;
import org.pitest.verifier.mutants.MutatorVerifierStart;

public class IncrementsMutatorTest extends MutatorTestBase {
public class IncrementsMutatorTest {

@Before
public void setupEngineToMutateOnlyIncrements() {
createTesteeWith(IncrementsMutator.INCREMENTS);
}
MutatorVerifierStart v = MutatorVerifierStart.forMutator(INCREMENTS);

private static class HasIncrement implements Callable<String> {
public int containsIincInstructions(int i) {
Expand All @@ -45,19 +40,16 @@ public String call() throws Exception {
}

@Test
public void shouldNegateArgumentsToIInc() throws Exception {
final Collection<MutationDetails> actual = findMutationsFor(HasIncrement.class);
assertEquals(1, actual.size());
final Mutant mutant = getFirstMutant(actual);
assertMutantCallableReturns(new HasIncrement(), mutant, "0");
public void shouldNegateArgumentsToIInc() {
v.forCallableClass(HasIncrement.class)
.firstMutantShouldReturn("0");
}

@Test
public void shouldRecordCorrectLineNumberForMutations() {
final Collection<MutationDetails> actual = findMutationsFor(HasIncrement.class);
assertEquals(1, actual.size());
final MutationDetails first = actual.iterator().next();
assertEquals(37, first.getLineNumber());
MutationDetails actual = v.forClass(HasIncrement.class)
.firstMutant();
assertEquals(32, actual.getLineNumber());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public void noMutantsCreated() {
}

public StringAssert firstMutantIsDescription() {
List<MutationDetails> mutants = findMutations();
assertThat(mutants)
.describedAs("No mutations created")
.isNotEmpty();
return new StringAssert(findMutations().get(0).getDescription());
return new StringAssert(firstMutant().getDescription());
}

List<MutationDetails> findMutations() {
Expand All @@ -49,4 +45,11 @@ List<MutationDetails> findMutations() {
}


public MutationDetails firstMutant() {
List<MutationDetails> mutants = findMutations();
assertThat(mutants)
.describedAs("No mutations created")
.isNotEmpty();
return mutants.get(0);
}
}

0 comments on commit 226b08f

Please sign in to comment.