@Override public MutationInterceptor createInterceptor(InterceptorParameters params) { if (params.data().isDetectInlinedCode()) { return new InlinedFinallyBlockFilter(); } return CompoundMutationInterceptor.nullInterceptor(); }
@Override public Collection<MutationDetails> intercept( Collection<MutationDetails> mutations, Mutater m) { final List<MutationDetails> combined = new ArrayList<>( mutations.size()); final Map<LineMutatorPair, Collection<MutationDetails>> mutatorLinebuckets = bucket( mutations, toLineMutatorPair()); for (final Entry<LineMutatorPair, Collection<MutationDetails>> each : mutatorLinebuckets .entrySet()) { if (each.getValue().size() > 1) { checkForInlinedCode(combined, each); } else { combined.addAll(each.getValue()); } } /** FIXME tests rely on order of returned mutants **/ Collections.sort(combined, compareLineNumbers()); return combined; }
private void checkForInlinedCode(final Collection<MutationDetails> combined, final Entry<LineMutatorPair, Collection<MutationDetails>> each) { final List<MutationDetails> mutationsInHandlerBlock = FCollection .filter(each.getValue(), isInFinallyHandler()); if (!isPossibleToCorrectInlining(mutationsInHandlerBlock)) { combined.addAll(each.getValue()); return; } final MutationDetails baseMutation = mutationsInHandlerBlock.get(0); final int firstBlock = baseMutation.getBlock(); // check that we have at least on mutation in a different block // to the base one (is this not implied by there being only 1 mutation in // the handler ????) final List<Integer> ids = map(each.getValue(), mutationToBlock()); if (ids.stream().filter(not(isEqualTo(firstBlock))).findFirst().isPresent()) { combined.add(makeCombinedMutant(each.getValue())); } else { combined.addAll(each.getValue()); } }
@Test public void shouldCreateSingleMutantWhenSameMutationCreatedOnSameLineInDifferentBlocksAndOneIsInAHandlerBlock() { final int line = 100; final String mutator = "foo"; final int block = 1000; final List<MutationDetails> mutations = Arrays.asList( makeMutantInHandlerBlock(line, block, mutator, 0), makeMutant(line, block + 1, mutator, 1)); assertEquals( Arrays.asList(makeMutantInHandlerBlock(line, block, mutator, Arrays.asList(0, 1))), this.testee.intercept(mutations, this.unused)); }
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()); }
@Test public void shouldNotCombineMutantsWhenOnSameLineAndBlock() { final int line = 100; final int block = 1; final String mutator = "foo"; final List<MutationDetails> mutations = Arrays.asList( makeMutant(line, block, mutator, 0), makeMutant(line, block, mutator, 1)); assertEquals(mutations, this.testee.intercept(mutations, this.unused)); }
@Test public void shouldNotCombineMutantsWhenOnSameLineAndDifferentBlocksButFromDifferentMutators() { final int line = 100; final int block = 1; final List<MutationDetails> mutations = Arrays.asList( makeMutant(line, block, "Foo", 0), makeMutant(line, block + 1, "NotFoo", 1)); assertEquals(mutations, this.testee.intercept(mutations, this.unused)); }
@Test public void shouldNotCombineMutationsWhenMoreThanOneInAHandlerBlock() { final int line = 100; final String mutator = "foo"; final int block = 1000; final List<MutationDetails> mutations = Arrays.asList( makeMutantInHandlerBlock(line, block, mutator, 0), makeMutantInHandlerBlock(line, block, mutator, 2), makeMutant(line, block + 1, mutator, 1)); final Collection<MutationDetails> actual = this.testee.intercept(mutations, this.unused); assertEquals(mutations, actual); }