@Override public void begin(ClassTree clazz) { for (final MutationInterceptor each : this.children) { each.begin(clazz); } }
@Override public void end() { for (final MutationInterceptor each : this.children) { each.end(); } }
@Override public Collection<MutationDetails> intercept( Collection<MutationDetails> mutations, Mutater m) { Collection<MutationDetails> modified = mutations; for (final MutationInterceptor each : this.children) { modified = each.intercept(modified, m); } return modified; }
@Test public void shouldNotifyAllChildrenOfNewClass() { this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild,this.filterChild)); final ClassTree aClass = new ClassTree(null); this.testee.begin(aClass); verify(this.modifyChild).begin(aClass); verify(this.filterChild).begin(aClass); }
@Test public void shouldChainModifiedMutantListsThroughChildrenInCorrectOrder() { // add out of order this.testee = new CompoundMutationInterceptor(Arrays.asList(this.cosmeticChild, this.otherChild, this.modifyChild, this.reportChild, this.filterChild)); final Collection<MutationDetails> original = aMutationDetail().build(1); final Collection<MutationDetails> modifyResult = aMutationDetail().build(2); final Collection<MutationDetails> filterResult = aMutationDetail().build(3); final Collection<MutationDetails> reportResult = aMutationDetail().build(3); final Collection<MutationDetails> cosmeticResult = aMutationDetail().build(3); final Collection<MutationDetails> otherResult = aMutationDetail().build(3); when(this.modifyChild.intercept(any(Collection.class), any(Mutater.class))).thenReturn(modifyResult); when(this.filterChild.intercept(any(Collection.class), any(Mutater.class))).thenReturn(filterResult); when(this.reportChild.intercept(any(Collection.class), any(Mutater.class))).thenReturn(reportResult); when(this.cosmeticChild.intercept(any(Collection.class), any(Mutater.class))).thenReturn(cosmeticResult); when(this.otherChild.intercept(any(Collection.class), any(Mutater.class))).thenReturn(otherResult); final Collection<MutationDetails> actual = this.testee.intercept(original, this.mutater); assertThat(actual).isEqualTo(reportResult); verify(this.otherChild).intercept(original,this.mutater); verify(this.modifyChild).intercept(otherResult,this.mutater); verify(this.filterChild).intercept(modifyResult,this.mutater); verify(this.cosmeticChild).intercept(cosmeticResult,this.mutater); verify(this.reportChild).intercept(cosmeticResult,this.mutater); }
public Collection<MutationDetails> createMutations(final ClassName clazz) { final Mutater m = this.mutationConfig.createMutator(this.source); final Collection<MutationDetails> availableMutations = m .findMutations(clazz); if (availableMutations.isEmpty()) { return availableMutations; } else { final ClassTree tree = ClassTree .fromBytes(this.source.getBytes(clazz.asJavaName()).get()); this.interceptor.begin(tree); final Collection<MutationDetails> updatedMutations = this.interceptor .intercept(availableMutations, m); this.interceptor.end(); assignTestsToMutations(updatedMutations); return updatedMutations; } }
@Before public void setUp() { when(this.modifyChild.type()).thenReturn(InterceptorType.MODIFY); when(this.filterChild.type()).thenReturn(InterceptorType.FILTER); when(this.otherChild.type()).thenReturn(InterceptorType.OTHER); when(this.cosmeticChild.type()).thenReturn(InterceptorType.MODIFY_COSMETIC); when(this.reportChild.type()).thenReturn(InterceptorType.REPORT); }
@Test public void shouldDeclareTypeAsFilter() { assertThat(this.testee.type()).isEqualTo(InterceptorType.FILTER); }