Skip to content

Commit

Permalink
Merge pull request #1151 from hcoles/feature/expand_interceptor_inter…
Browse files Browse the repository at this point in the history
…face

give interceptors access to full classpath
  • Loading branch information
hcoles authored Jan 30, 2023
2 parents ee6e291 + 11923c7 commit 43b16ef
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DefaultCodeSource(final ProjectClassPaths classPath) {
classPath.getClassPath())));
}

DefaultCodeSource(final ProjectClassPaths classPath,
public DefaultCodeSource(final ProjectClassPaths classPath,
final Repository classRepository) {
this.classPath = classPath;
this.classRepository = classRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pitest.mutationtest.build;

import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.classpath.CodeSource;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;

Expand Down Expand Up @@ -32,6 +33,11 @@ public CompoundMutationInterceptor filter(Predicate<MutationInterceptor> p) {
.collect(Collectors.toList()));
}

@Override
public void initialise(CodeSource code) {
this.children.forEach(each -> each.initialise(code));
}

@Override
public void begin(ClassTree clazz) {
this.children.forEach(each -> each.begin(clazz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
import java.util.Collection;

import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.classpath.CodeSource;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;

public interface MutationInterceptor {

InterceptorType type();

/**
* Called once per instance prior to intercepting
* @param code Current code source
*/
default void initialise(CodeSource code) {
// noop
}

void begin(ClassTree clazz);

Collection<MutationDetails> intercept(Collection<MutationDetails> mutations, Mutater m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ private List<MutationAnalysisUnit> buildMutationTests(CoverageDatabase coverageD
.createInterceptor(this.data, coverageData, bas)
.filter(interceptorFilter);

interceptor.initialise(this.code);

final MutationSource source = new MutationSource(mutationConfig, testPrioritiser, bas, interceptor);

final MutationAnalyser analyser = new IncrementalAnalyser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.classpath.CodeSource;
import org.pitest.classpath.DefaultCodeSource;
import org.pitest.classpath.ProjectClassPaths;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;

Expand Down Expand Up @@ -51,6 +54,16 @@ public void setUp() {
when(this.reportChild.type()).thenReturn(InterceptorType.REPORT);
}

@Test
public void initialisesAllChildren() {
this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild, this.filterChild));
final CodeSource source = new DefaultCodeSource(new ProjectClassPaths(null, null,null));

this.testee.initialise(source);
verify(this.modifyChild).initialise(source);
verify(this.filterChild).initialise(source);
}

@Test
public void shouldNotifyAllChildrenOfNewClass() {
this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild,this.filterChild));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.objectweb.asm.tree.AbstractInsnNode;
import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.classinfo.Repository;
import org.pitest.classpath.DefaultCodeSource;
import org.pitest.mutationtest.build.MutationInterceptor;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;
Expand Down

0 comments on commit 43b16ef

Please sign in to comment.