/** * Returns the method name in which this mutation is located as a string * * @return method name as string */ @Deprecated public String getLocation() { // fixme this should not be here used in string template return this.id.getLocation().describe(); }
/** * Returns the class in which this mutation is located * * @return class in which mutation is located */ public MethodName getMethod() { return this.id.getLocation().getMethodName(); }
private Function<MutationDetails, Location> mutationToLocation() { return a -> a.getId().getLocation(); }
@Override public int compareTo(final MutationIdentifier other) { int comp = this.location.compareTo(other.getLocation()); if (comp != 0) { return comp; } comp = this.mutator.compareTo(other.getMutator()); if (comp != 0) { return comp; } return this.indexes.get(0).compareTo(other.indexes.get(0)); }
private List<MutationDetails> filter( List<MutationDetails> inEquals, Mutater m) { final Location equalsMethod = inEquals.get(0).getId().getLocation(); final Optional<MethodTree> maybeEquals = this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(equalsMethod)) .findFirst(); return inEquals.stream() .filter(isShortcutEquals(maybeEquals.get(), m).negate()) .collect(Collectors.toList()); }
@Override public boolean test(MutationDetails a) { if (!MUTATOR_ID.equals(a.getMutator())) { return false; } final MethodTree method = NullReturnsFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst() .get(); final int mutatedInstruction = a.getInstructionIndex(); return returnsNull(method, mutatedInstruction); }
private Predicate<MutationDetails> isEquivalent(Mutater m) { return a -> { if (!MUTATOR_IDS.contains(a.getMutator())) { return false; } final MethodTree method = PrimitiveEquivalentFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst() .get(); return ZERO_CONSTANTS.contains(method.realInstructionBefore(a.getInstructionIndex()).getOpcode()); }; }
@Override public boolean test(MutationDetails a) { if (!MUTATOR_IDS.contains(a.getMutator())) { return false; } final int instruction = a.getInstructionIndex(); final MethodTree method = HardCodedTrueEquivalentFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst().get(); return primitiveTrue(instruction, method) || boxedTrue(instruction, method); }
public static Function<MethodTree, Predicate<MutationDetails>> matchMutationsInMethod() { return method -> { final Location methodLocation = method.asLocation(); return a -> methodLocation.equals(a.getId().getLocation()); }; } }
private static Predicate<MutationDetails> isInStaticInitializer() { return a -> a.getId().getLocation().getMethodName().equals(CLINIT); }
private Predicate<MutationDetails> inEqualsMethod() { return a -> { final Location loc = a.getId().getLocation(); return loc.getMethodDesc().equals("(Ljava/lang/Object;)Z") && loc.getMethodName().equals(MethodName.fromString("equals")); }; }
private boolean isInfiniteLoop(MutationDetails each, Mutater m) { final ClassTree mutantClass = ClassTree.fromBytes(m.getMutation(each.getId()).getBytes()); final Optional<MethodTree> mutantMethod = mutantClass.methods().stream() .filter(forLocation(each.getId().getLocation())) .findFirst(); return infiniteLoopMatcher().matches(mutantMethod.get().instructions()); }
private Predicate<MutationDetails> mutatesAForLoopCounter() { return a -> { final int instruction = a.getInstructionIndex(); final MethodTree method = AvoidForLoopCounterFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst().get(); final AbstractInsnNode mutatedInstruction = method.instruction(instruction); final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG); context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction); return MUTATED_FOR_COUNTER.matches(method.instructions(), context); }; }
private Predicate<MutationDetails> mutatesIteratorLoopPlumbing() { return a -> { final int instruction = a.getInstructionIndex(); final MethodTree method = ForEachLoopFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst() .get(); final AbstractInsnNode mutatedInstruction = method.instruction(instruction); final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG); context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction); return ITERATOR_LOOP.matches(method.instructions(), context); }; }
private Predicate<MutationDetails> isAnImplicitNullCheck() { return a -> { final int instruction = a.getInstructionIndex(); final MethodTree method = ImplicitNullCheckFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst() .get(); final AbstractInsnNode mutatedInstruction = method.instruction(instruction); final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG); context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction); return GET_CLASS_NULL_CHECK.matches(method.instructions(), context); }; }
private static MutationDetails makeCombinedMutant( final Collection<MutationDetails> value) { final MutationDetails first = value.iterator().next(); final Set<Integer> indexes = new HashSet<>(); mapTo(value, mutationToIndex(), indexes); final MutationIdentifier id = new MutationIdentifier(first.getId() .getLocation(), indexes, first.getId().getMutator()); return new MutationDetails(id, first.getFilename(), first.getDescription(), first.getLineNumber(), first.getBlock()); }
@Override public boolean matches(MutationDetails value) { return value.getId().getLocation().getMethodName().name().equals(name); } };
@Test public void shouldFilterMethodsWithGeneratedAnnotation() { final List<MutationDetails> mutations = this.mutator.findMutations(ClassName.fromClass(MethodAnnotatedWithGenerated.class)); final Collection<MutationDetails> actual = runWithTestee(mutations, MethodAnnotatedWithGenerated.class); assertThat(actual).hasSize(1); assertThat(actual.iterator().next().getId().getLocation().getMethodName().name()).isEqualTo("bar"); }
private void assertOnlyClinitMethodsMarked(Collection<MutationDetails> actual) { for (final MutationDetails each : actual ) { if (each.isInStaticInitializer()) { if (!each.getId().getLocation().getMethodName().name().equals("<clinit>")) { fail("Expected no mutants to be marked as for static initialization but " + each + " was"); } } } }
private Function<MutationDetails, Loc> toLocation(final ClassTree tree) { return a -> { final MethodTree method = tree.method(a.getId().getLocation()).get(); final Loc l = new Loc(); l.index = a.getInstructionIndex(); l.node = method.instruction(a.getInstructionIndex()); return l; }; }