Java Code Examples for org.pitest.functional.FCollection#filter()

The following examples show how to use org.pitest.functional.FCollection#filter() . 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: AbstractPitAggregationReportMojo.java    From pitest with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private List<File> getCompiledDirs(final MavenProject project)
    throws Exception {
  final List<String> sourceRoots = new ArrayList<>();
  for (final Object artifactObj : FCollection
      .filter(project.getPluginArtifactMap().values(), new DependencyFilter(
          new PluginServices(this.getClass().getClassLoader())))) {

    final Artifact artifact = (Artifact) artifactObj;
    sourceRoots.add(artifact.getFile().getAbsolutePath());
  }
  return convertToRootDirs(project.getTestClasspathElements(),
      Arrays.asList(project.getBuild().getOutputDirectory(),
          project.getBuild().getTestOutputDirectory()),
      sourceRoots);
}
 
Example 2
Source File: GregorMutater.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Override
public Mutant getMutation(final MutationIdentifier id) {

  final ClassContext context = new ClassContext();
  context.setTargetMutation(Optional.ofNullable(id));

  final Optional<byte[]> bytes = this.byteSource.getBytes(id.getClassName()
      .asJavaName());

  final ClassReader reader = new ClassReader(bytes.get());
  final ClassWriter w = new ComputeClassWriter(this.byteSource,
      this.computeCache, FrameOptions.pickFlags(bytes.get()));
  final MutatingClassVisitor mca = new MutatingClassVisitor(w, context,
      filterMethods(), FCollection.filter(this.mutators,
          isMutatorFor(id)));
  reader.accept(mca, ClassReader.EXPAND_FRAMES);

  final List<MutationDetails> details = context.getMutationDetails(context
      .getTargetMutation().get());

  return new Mutant(details.get(0), w.toByteArray());

}
 
Example 3
Source File: InlinedFinallyBlockFilter.java    From pitest with Apache License 2.0 6 votes vote down vote up
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().anyMatch(not(isEqual(firstBlock)))) {
    combined.add(makeCombinedMutant(each.getValue()));
  } else {
    combined.addAll(each.getValue());
  }
}
 
Example 4
Source File: DefaultBuildVerifier.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public void verify(final CodeSource code) {
  final Collection<ClassInfo> codeClasses = FCollection.filter(code.getCode(), isNotSynthetic());

  if (hasMutableCode(codeClasses)) {
    checkAtLeastOneClassHasLineNumbers(codeClasses);
    codeClasses.forEach(throwErrorIfHasNoSourceFile());
  }
}
 
Example 5
Source File: KotlinInterceptor.java    From pitest-kotlin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<MutationDetails> intercept(
    Collection<MutationDetails> mutations, Mutater m) {
  if(!isKotlinClass) {
    return mutations;
  }
  return FCollection.filter(mutations, isKotlinJunkMutation(currentClass).negate());
}
 
Example 6
Source File: ExcludedAnnotationInterceptor.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<MutationDetails> intercept(
    Collection<MutationDetails> mutations, Mutater m) {
  if (this.skipClass) {
    return Collections.emptyList();
  }

  return FCollection.filter(mutations, Prelude.not(this.annotatedMethodMatcher));
}
 
Example 7
Source File: DependencyExtractor.java    From pitest with Apache License 2.0 5 votes vote down vote up
public Collection<String> extractCallDependenciesForPackages(
    final String clazz, final Predicate<String> targetPackages)
        throws IOException {
  final Set<String> allDependencies = extractCallDependencies(clazz,
      new IgnoreCoreClasses());
  return FCollection.filter(allDependencies,
      and(asJVMNamePredicate(targetPackages), notSuppliedClass(clazz)));
}
 
Example 8
Source File: EqualsPerformanceShortcutFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<MutationDetails> intercept(
    Collection<MutationDetails> mutations, Mutater m) {
 final List<MutationDetails> doNotTouch = FCollection.filter(mutations, inEqualsMethod().negate());
 if (doNotTouch.size() != mutations.size()) {
   final List<MutationDetails> inEquals = FCollection.filter(mutations, inEqualsMethod());
   final List<MutationDetails> filtered = filter(inEquals, m);
   doNotTouch.addAll(filtered);
 }
 return doNotTouch;
}
 
Example 9
Source File: DependencyExtractor.java    From pitest with Apache License 2.0 5 votes vote down vote up
public Collection<String> extractCallDependenciesForPackages(
    final String clazz, final Predicate<String> targetPackages,
    final Predicate<DependencyAccess> doNotTraverse) throws IOException {
  final Set<String> allDependencies = extractCallDependencies(clazz,
      doNotTraverse);
  return FCollection.filter(allDependencies, targetPackages);
}
 
Example 10
Source File: DependencyFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
List<TestUnit> filterTestsByDependencyAnalysis(final List<TestUnit> tus) {
  if (this.analyser.getMaxDistance() < 0) {
    return tus;
  } else {
    return FCollection.filter(tus, isWithinReach());
  }
}
 
Example 11
Source File: BasicTestUnitFinder.java    From pitest with Apache License 2.0 5 votes vote down vote up
private InstantiationStrategy findInstantiationStrategy(final Class<?> clazz) {
  final List<InstantiationStrategy> strategies = FCollection.filter(
      this.instantiationStrategies, canInstantiate(clazz));
  if (strategies.isEmpty()) {
    throw new PitError("Cannot instantiate " + clazz);
  } else {
    return strategies.get(0);
  }
}
 
Example 12
Source File: DependencyExtractor.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Set<DependencyAccess> extractRelevantDependencies(final String clazz,
    final Predicate<DependencyAccess> filter) throws IOException {
  final List<DependencyAccess> dependencies = extract(clazz, filter);
  final Set<DependencyAccess> relevantDependencies = new TreeSet<>(
      equalDestinationComparator());
  FCollection.filter(dependencies, filter, relevantDependencies);
  return relevantDependencies;
}
 
Example 13
Source File: MutationTestBuilder.java    From pitest with Apache License 2.0 5 votes vote down vote up
public List<MutationAnalysisUnit> createMutationTestUnits(
    final Collection<ClassName> codeClasses) {
  final List<MutationAnalysisUnit> tus = new ArrayList<>();

  final List<MutationDetails> mutations = FCollection.flatMap(codeClasses,
      classToMutations());

  mutations.sort(comparing(MutationDetails::getId));

  final Collection<MutationResult> analysedMutations = this.analyser
      .analyse(mutations);

  final Collection<MutationDetails> needAnalysis = analysedMutations.stream()
      .filter(statusNotKnown())
      .map(resultToDetails())
      .collect(Collectors.toList());

  final List<MutationResult> analysed = FCollection.filter(analysedMutations,
      Prelude.not(statusNotKnown()));

  if (!analysed.isEmpty()) {
    tus.add(makePreAnalysedUnit(analysed));
  }

  if (!needAnalysis.isEmpty()) {
    for (final Collection<MutationDetails> ms : this.grouper.groupMutations(
        codeClasses, needAnalysis)) {
      tus.add(makeUnanalysedUnit(ms));
    }
  }

  tus.sort(new AnalysisPriorityComparator());
  return tus;
}
 
Example 14
Source File: SettingsFactory.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Iterable<MutationResultListenerFactory> findListeners() {
  final Iterable<? extends MutationResultListenerFactory> listeners = this.plugins
      .findListeners();
  final Collection<MutationResultListenerFactory> matches = FCollection
      .filter(listeners, nameMatches(this.options.getOutputFormats()));
  if (matches.size() < this.options.getOutputFormats().size()) {
    throw new PitError("Unknown listener requested in "
        + String.join(",", this.options.getOutputFormats()));
  }
  return matches;
}
 
Example 15
Source File: MojoToReportOptionsConverter.java    From pitest with Apache License 2.0 4 votes vote down vote up
private Collection<Artifact> filteredDependencies() {
  return FCollection.filter(this.mojo.getPluginArtifactMap().values(),
      this.dependencyFilter);
}
 
Example 16
Source File: ForEachLoopFilter.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<MutationDetails> intercept(
    Collection<MutationDetails> mutations, Mutater m) {
  return FCollection.filter(mutations, Prelude.not(mutatesIteratorLoopPlumbing()));
}
 
Example 17
Source File: EquivalentReturnMutationFilter.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<MutationDetails> intercept(
    Collection<MutationDetails> mutations, Mutater m) {
  return FCollection.filter(mutations, Prelude.not(isEquivalent(m)));
}
 
Example 18
Source File: ClassContext.java    From pitest with Apache License 2.0 4 votes vote down vote up
public List<MutationDetails> getMutationDetails(final MutationIdentifier id) {
  return FCollection.filter(this.mutations, hasId(id));
}
 
Example 19
Source File: WrappingProcess.java    From pitest with Apache License 2.0 4 votes vote down vote up
private static void addLaunchJavaAgents(List<String> cmd) {
  final RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
  final List<String> agents = FCollection.filter(rt.getInputArguments(),
      or(isJavaAgentParam(), isEnvironmentSetting()));
  cmd.addAll(agents);
}
 
Example 20
Source File: StaticInitializerFilter.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<MutationDetails> intercept(
    Collection<MutationDetails> mutations, Mutater m) {
  return FCollection.filter(mutations, Prelude.not(isInStaticInitCode()));
}