org.pitest.mutationtest.build.MutationInterceptor Java Examples

The following examples show how to use org.pitest.mutationtest.build.MutationInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StopMethodMatcherInterceptorFactory.java    From pitest-descartes with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters interceptorParameters) {
    Set<String> matchers = availabeMatchers.keySet();
    List<String> exclusions = interceptorParameters.getList(EXCEPT);
    if(exclusions != null)
        matchers.removeAll(exclusions);

    return new StopMethodInterceptor(
            StopMethodMatcher.any(
                    matchers.stream()
                            .map(key -> availabeMatchers.get(key))
                            .collect(Collectors.toList())
            )
    );

}
 
Example #2
Source File: MutationCoverage.java    From pitest with Apache License 2.0 5 votes vote down vote up
private List<MutationAnalysisUnit> buildMutationTests(
    final CoverageDatabase coverageData, final MutationEngine engine, EngineArguments args) {

  final MutationConfig mutationConfig = new MutationConfig(engine, coverage()
      .getLaunchOptions());

  final ClassByteArraySource bas = fallbackToClassLoader(new ClassPathByteArraySource(
      this.data.getClassPath()));

  final TestPrioritiser testPrioritiser = this.settings.getTestPrioritiser()
      .makeTestPrioritiser(this.data.getFreeFormProperties(), this.code,
          coverageData);

  final MutationInterceptor interceptor = this.settings.getInterceptor()
      .createInterceptor(this.data, bas);

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

  final MutationAnalyser analyser = new IncrementalAnalyser(
      new DefaultCodeHistory(this.code, history()), coverageData);

  final WorkerFactory wf = new WorkerFactory(this.baseDir, coverage()
      .getConfiguration(), mutationConfig, args,
      new PercentAndConstantTimeoutStrategy(this.data.getTimeoutFactor(),
          this.data.getTimeoutConstant()), this.data.isVerbose(), this.data.isFullMutationMatrix(),
          this.data.getClassPath().getLocalClassPath());

  final MutationGrouper grouper = this.settings.getMutationGrouper().makeFactory(
      this.data.getFreeFormProperties(), this.code,
      this.data.getNumberOfThreads(), this.data.getMutationUnitSize());
  final MutationTestBuilder builder = new MutationTestBuilder(wf, analyser,
      source, grouper);

  return builder.createMutationTestUnits(this.code.getCodeUnderTestNames());
}
 
Example #3
Source File: InlinedFinallyBlockFilterFactory.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  if (params.data().isDetectInlinedCode()) {
    return new InlinedFinallyBlockFilter();
  }
  return CompoundMutationInterceptor.nullInterceptor();
}
 
Example #4
Source File: EquivalentReturnMutationFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new CompoundMutationInterceptor(Arrays.asList(new PrimitiveEquivalentFilter(),
      new NullReturnsFilter(),
      new EmptyReturnsFilter(),
      new HardCodedTrueEquivalentFilter())) {
    @Override
    public InterceptorType type() {
      return InterceptorType.FILTER;
    }
  };
}
 
Example #5
Source File: LimitNumberOfMutationsPerClassFilterFactory.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  final Optional<Integer> max = params.getInteger(this.limit);
  if (!max.isPresent()) {
    throw new IllegalArgumentException("Max mutation per class filter requires a limit parameter");
  }
  return new LimitNumberOfMutationPerClassFilter(max.get());
}
 
Example #6
Source File: StopMethodInterceptorTest.java    From pitest-descartes with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MutationInterceptor getInterceptor(String... exclusions) throws IOException {
    StopMethodMatcherInterceptorFactory stopFactory = new StopMethodMatcherInterceptorFactory();
    Feature feature = stopFactory.provides();
    Map<String, List<String>> featureParameters = new HashMap<>();
    featureParameters.put("except", Arrays.asList(exclusions));
    FeatureSetting setting = new FeatureSetting(feature.name(), ToggleStatus.ACTIVATE, featureParameters);
    InterceptorParameters params = new InterceptorParameters(setting, null, null);
    return stopFactory.createInterceptor(params);
}
 
Example #7
Source File: AvoidNullInNotNullInterceptorTest.java    From pitest-descartes with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void shouldFindOnlyNullableMethods() throws IOException {
    Class<?> target = loadClass("tests.PersonKt");
    Collection<MutationDetails> mutationPoints = findMutationPoints(target, "null");
    MutationInterceptor interceptor = getInterceptor();
    interceptor.begin(getClassTree(target));
    Collection<MutationDetails> filteredMutations = interceptor.intercept(mutationPoints, null);
    Collection<String> methods = filteredMutations.stream().map(details -> details.getMethod().name()).collect(Collectors.toList());
    assertThat(methods, contains("getPossiblyNullString"));
}
 
Example #8
Source File: AvoidNullInNotNullInterceptorTest.java    From pitest-descartes with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MutationInterceptor getInterceptor() {
    AvoidNullInNotNullInterceptorFactory factory = new AvoidNullInNotNullInterceptorFactory();
    Feature feature = factory.provides();
    FeatureSetting setting = new FeatureSetting(feature.name(), ToggleStatus.ACTIVATE, Collections.emptyMap());
    InterceptorParameters params = new InterceptorParameters(setting, null, null);
    return new AvoidNullInNotNullInterceptorFactory().createInterceptor(params);
}
 
Example #9
Source File: FilterTester.java    From pitest with Apache License 2.0 4 votes vote down vote up
public FilterTester(String path, MutationInterceptor testee, MethodMutatorFactory ... mutators) {
  this(path, testee, Arrays.asList(mutators));
}
 
Example #10
Source File: FilterTester.java    From pitest with Apache License 2.0 4 votes vote down vote up
public FilterTester(String path, MutationInterceptor testee, Collection<MethodMutatorFactory> mutators) {
  this.mutators = mutators;
  this.testee = testee;
  this.path = path;
}
 
Example #11
Source File: ExcludedAnnotationInterceptorFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new ExcludedAnnotationInterceptor(determineAnnotations(params));
}
 
Example #12
Source File: KotlinFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new KotlinFilter();
}
 
Example #13
Source File: EqualsPerformanceShortcutFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new EqualsPerformanceShortcutFilter();
}
 
Example #14
Source File: KotlinInterceptorFactory.java    From pitest-kotlin with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters interceptorParameters) {
  return new KotlinInterceptor();
}
 
Example #15
Source File: AvoidForLoopCountersFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new AvoidForLoopCounterFilter();
}
 
Example #16
Source File: InfiniteForLoopFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new InfiniteForLoopFilter();
}
 
Example #17
Source File: InfiniteIteratorLoopFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new InfiniteIteratorLoopFilter();
}
 
Example #18
Source File: TryWithResourcesFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new TryWithResourcesFilter();
}
 
Example #19
Source File: ForEachLoopFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new ForEachLoopFilter();
}
 
Example #20
Source File: EnumConstructorFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
    return new EnumConstructorFilter();
}
 
Example #21
Source File: ImplicitNullCheckFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new ImplicitNullCheckFilter();
}
 
Example #22
Source File: MethodReferenceNullCheckFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new MethodReferenceNullCheckFilter();
}
 
Example #23
Source File: LoggingCallsFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new LoggingCallsFilter(params.data().getLoggingClasses());
}
 
Example #24
Source File: StaticInitializerInterceptorFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new StaticInitializerInterceptor();
}
 
Example #25
Source File: StaticInitializerFilterFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new StaticInitializerFilter();
}
 
Example #26
Source File: MutantExportFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
  return new MutantExportInterceptor(FileSystems.getDefault(), params.source(), params.data().getReportDir());
}
 
Example #27
Source File: StopMethodInterceptorTest.java    From pitest-descartes with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Collection<MutationDetails> filteredMutations(Class<?> target, String... exclusions) throws IOException {
    MutationInterceptor interceptor = getInterceptor(exclusions);
    interceptor.begin(getClassTree(target));
    return interceptor.intercept(findMutationPoints(target), null);
}
 
Example #28
Source File: AvoidNullInNotNullInterceptorFactory.java    From pitest-descartes with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public MutationInterceptor createInterceptor(InterceptorParameters interceptorParameters) {
    return new AvoidNullInNotNullInterceptor();
}
 
Example #29
Source File: TestMutationTesting.java    From pitest with Apache License 2.0 2 votes vote down vote up
private void createEngineAndRun(final ReportOptions data,
    final JavaAgent agent,
    final Collection<String> mutators) {

  // data.setConfiguration(this.config);
  final CoverageOptions coverageOptions = createCoverageOptions(data);

  final LaunchOptions launchOptions = new LaunchOptions(agent,
      new DefaultJavaExecutableLocator(), data.getJvmArgs(),
      new HashMap<String, String>());

  final PathFilter pf = new PathFilter(
      Prelude.not(new DefaultDependencyPathPredicate()),
      Prelude.not(new DefaultDependencyPathPredicate()));
  final ProjectClassPaths cps = new ProjectClassPaths(data.getClassPath(),
      data.createClassesFilter(), pf);

  final Timings timings = new Timings();
  final CodeSource code = new CodeSource(cps);

  final CoverageGenerator coverageGenerator = new DefaultCoverageGenerator(
      null, coverageOptions, launchOptions, code, new NullCoverageExporter(),
      timings, false);

  final CoverageDatabase coverageData = coverageGenerator.calculateCoverage();

  final Collection<ClassName> codeClasses = FCollection.map(code.getCode(),
      ClassInfo.toClassName());

  final EngineArguments arguments = EngineArguments.arguments()
      .withMutators(mutators);

  final MutationEngine engine = new GregorEngineFactory().createEngine(arguments);

  final MutationConfig mutationConfig = new MutationConfig(engine,
      launchOptions);

  final ClassloaderByteArraySource bas = new ClassloaderByteArraySource(
      IsolationUtils.getContextClassLoader());

  final MutationInterceptor emptyIntercpetor = CompoundMutationInterceptor.nullInterceptor();

  final MutationSource source = new MutationSource(mutationConfig, new DefaultTestPrioritiser(
          coverageData), bas, emptyIntercpetor);


  final WorkerFactory wf = new WorkerFactory(null,
      coverageOptions.getPitConfig(), mutationConfig, arguments,
      new PercentAndConstantTimeoutStrategy(data.getTimeoutFactor(),
          data.getTimeoutConstant()), data.isVerbose(), false, data.getClassPath()
          .getLocalClassPath());




  final MutationTestBuilder builder = new MutationTestBuilder(wf,
      new NullAnalyser(), source, new DefaultGrouper(0));

  final List<MutationAnalysisUnit> tus = builder
      .createMutationTestUnits(codeClasses);

  this.mae.run(tus);
}