org.pitest.classinfo.ClassByteArraySource Java Examples

The following examples show how to use org.pitest.classinfo.ClassByteArraySource. 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: MutationTestMinionTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  this.mutations = new ArrayList<>();
  this.tests = new ArrayList<>();

  this.args = new MinionArguments(this.mutations, this.tests,  "anEgine", EngineArguments.arguments(),
      this.timeoutStrategy, false, false, TestPluginArguments.defaults());

  when(this.is.read(MinionArguments.class)).thenReturn(this.args);
  when(this.engine.createMutator(any(ClassByteArraySource.class)))
  .thenReturn(this.mutater);

  final MutationEngineFactory factory = Mockito.mock(MutationEngineFactory.class);
  when(factory.createEngine(any(EngineArguments.class))).thenReturn(this.engine);

  when(this.settings.createEngine(any(String.class))).thenReturn(factory);

  this.testee = new MutationTestMinion(this.settings, this.is, this.reporter);
}
 
Example #2
Source File: HotSwap.java    From pitest with Apache License 2.0 6 votes vote down vote up
private void restoreLastClass(final ClassByteArraySource byteSource,
    final ClassName clazzName, final ClassLoader loader)
        throws ClassNotFoundException {
  if ((this.lastMutatedClass != null)
      && !this.lastMutatedClass.equals(clazzName)) {
    restoreForLoader(this.lastUsedLoader);
    restoreForLoader(loader);
  }

  if ((this.lastMutatedClass == null)
      || !this.lastMutatedClass.equals(clazzName)) {
    this.lastClassPreMutation = byteSource.getBytes(clazzName.asJavaName())
        .get();
  }

  this.lastMutatedClass = clazzName;
}
 
Example #3
Source File: GregorMutater.java    From pitest with Apache License 2.0 5 votes vote down vote up
public GregorMutater(final ClassByteArraySource byteSource,
    final Predicate<MethodInfo> filter,
    final Collection<MethodMutatorFactory> mutators) {
  this.filter = filter;
  this.mutators.addAll(mutators);
  this.byteSource = byteSource;
}
 
Example #4
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 #5
Source File: MutationCoverage.java    From pitest with Apache License 2.0 5 votes vote down vote up
private ClassByteArraySource fallbackToClassLoader(final ClassByteArraySource bas) {
  final ClassByteArraySource clSource = ClassloaderByteArraySource.fromContext();
  return clazz -> {
    final Optional<byte[]> maybeBytes = bas.getBytes(clazz);
    if (maybeBytes.isPresent()) {
      return maybeBytes;
    }
    LOG.log(Level.FINE, "Could not find " + clazz + " on classpath for analysis. Falling back to classloader");
    return clSource.getBytes(clazz);
  };
}
 
Example #6
Source File: MutationSource.java    From pitest with Apache License 2.0 5 votes vote down vote up
public MutationSource(final MutationConfig mutationConfig,
    final TestPrioritiser testPrioritiser,
    final ClassByteArraySource source,
    final MutationInterceptor interceptor) {
  this.mutationConfig = mutationConfig;
  this.testPrioritiser = testPrioritiser;
  this.source = new CachingByteArraySource(source, 200);
  this.interceptor = interceptor;
}
 
Example #7
Source File: CompoundInterceptorFactory.java    From pitest with Apache License 2.0 5 votes vote down vote up
public MutationInterceptor createInterceptor(
    ReportOptions data,
    ClassByteArraySource source) {
  final List<MutationInterceptor> interceptors = FCollection.map(this.features.getActiveFeatures(),
      toInterceptor(this.features, data, source));
  return new CompoundMutationInterceptor(interceptors);
}
 
Example #8
Source File: MinionSettings.java    From pitest with Apache License 2.0 5 votes vote down vote up
public Configuration getTestFrameworkPlugin(TestPluginArguments options, ClassByteArraySource source) {
  for (final TestPluginFactory each : this.plugins.findTestFrameworkPlugins()) {
    if (each.name().equals(options.getTestPlugin())) {
      return each.createTestFrameworkConfiguration(options.getGroupConfig(),
          source,
          options.getExcludedRunners(),
          options.getIncludedTestMethods());
    }
  }
  throw new PitError("Could not load requested test plugin "
      + options.getTestPlugin());
}
 
Example #9
Source File: DefaultBuildVerifierTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
private void setupClassPath(final ClassByteArraySource source,
    final String clazz) {
  final Repository repository = new Repository(source);
  final ClassInfo ci = repository.fetchClass(ClassName.fromString(clazz))
      .get();
  when(this.code.getCode()).thenReturn(Collections.singletonList(ci));
}
 
Example #10
Source File: MutationCoverageReportTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
private void mockMutationEngine() {
  when(
      this.mutationFactory.createEngine(any(EngineArguments.class))).thenReturn(
              this.engine);
  when(this.engine.createMutator(any(ClassByteArraySource.class)))
  .thenReturn(this.mutater);
}
 
Example #11
Source File: MutationSourceTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  when(this.engine.createMutator(any(ClassByteArraySource.class))).thenReturn(this.mutater);
  this.config = new MutationConfig(this.engine, new LaunchOptions(null));
  this.testee = new MutationSource(this.config, this.prioritiser
      , this.source, CompoundMutationInterceptor.nullInterceptor());
}
 
Example #12
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
MutationSource createSource(ClassByteArraySource source) {
  final SettingsFactory settings = new SettingsFactory(this.data,
      PluginServices.makeForContextLoader());
  final MutationInterceptor interceptor = settings.getInterceptor()
      .createInterceptor(this.data, source);

  final MutationEngine engine = new GregorEngineFactory().createEngine(
      EngineArguments.arguments().withExcludedMethods(this.data.getExcludedMethods())
      .withMutators(this.data.getMutators()));

  final MutationConfig config = new MutationConfig(engine, null);

  return new MutationSource(config, noTestPrioritisation(), source,
      interceptor);
}
 
Example #13
Source File: DependencyExtractor.java    From pitest with Apache License 2.0 4 votes vote down vote up
public DependencyExtractor(final ClassByteArraySource classToBytes,
    final int depth) {
  this.depth = depth;
  this.classToBytes = classToBytes;
}
 
Example #14
Source File: GregorMutationEngine.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Mutater createMutator(final ClassByteArraySource byteSource) {
  return new GregorMutater(byteSource, this.methodFilter,
      this.mutationOperators);
}
 
Example #15
Source File: HotSwap.java    From pitest with Apache License 2.0 4 votes vote down vote up
HotSwap(final ClassByteArraySource byteSource) {
  this.byteSource = byteSource;
}
 
Example #16
Source File: TestNGPlugin.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
    ClassByteArraySource source, Collection<String> excludedRunner, Collection<String> includedTestMethods) {
  return new TestNGConfiguration(config, includedTestMethods);
}
 
Example #17
Source File: SimpleTestPlugin.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
    ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedMethods) {
  return new ConfigurationForTesting();
}
 
Example #18
Source File: MutatorTestBase.java    From pitest with Apache License 2.0 4 votes vote down vote up
protected void createTesteeWith(final ClassByteArraySource source,
    final Predicate<MethodInfo> filter,
    final Collection<MethodMutatorFactory> mutators) {
  this.engine = new GregorMutater(source, filter, mutators);
}
 
Example #19
Source File: CucumberTestFrameworkPlugin.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
                                                      ClassByteArraySource source,
                                                      Collection<String> excludedRunners) {

    return new CucumberJUnitCompatibleConfiguration(config);
}
 
Example #20
Source File: CucumberTestFrameworkPlugin.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config, ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedTestMethods) {
    Objects.requireNonNull(config);
    return new CucumberJUnitCompatibleConfiguration(config);
}
 
Example #21
Source File: TestPluginFactory.java    From pitest with Apache License 2.0 4 votes vote down vote up
Configuration createTestFrameworkConfiguration(TestGroupConfig config,
ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedTestMethods);
 
Example #22
Source File: JUnitTestPlugin.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
    ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedTestMethods) {
  Objects.requireNonNull(config);
  return new JUnitCompatibleConfiguration(config, excludedRunners, includedTestMethods);
}
 
Example #23
Source File: MutationConfig.java    From pitest with Apache License 2.0 4 votes vote down vote up
public Mutater createMutator(final ClassByteArraySource source) {
  return this.engine.createMutator(source);
}
 
Example #24
Source File: InterceptorParameters.java    From pitest with Apache License 2.0 4 votes vote down vote up
public ClassByteArraySource source() {
  return this.source;
}
 
Example #25
Source File: InterceptorParameters.java    From pitest with Apache License 2.0 4 votes vote down vote up
public InterceptorParameters(FeatureSetting conf, ReportOptions data,
    ClassByteArraySource source) {
  this.conf = conf;
  this.data = data;
  this.source = source;
}
 
Example #26
Source File: JarCreatingJarFinder.java    From pitest with Apache License 2.0 4 votes vote down vote up
public JarCreatingJarFinder(final ClassByteArraySource classByteSource) {
  this.classByteSource = classByteSource;
}
 
Example #27
Source File: MutantExportInterceptor.java    From pitest with Apache License 2.0 4 votes vote down vote up
public MutantExportInterceptor(FileSystem fileSystem,
    ClassByteArraySource source, String outDir) {
  this.fileSystem = fileSystem;
  this.outDir = outDir;
  this.source = source;
}
 
Example #28
Source File: DescartesMutater.java    From pitest-descartes with GNU Lesser General Public License v3.0 4 votes vote down vote up
public DescartesMutater(final ClassByteArraySource byteSource, DescartesMutationEngine engine) {
    this.byteSource = byteSource;
    this.engine = engine;
}
 
Example #29
Source File: MutationTestMinion.java    From pitest with Apache License 2.0 3 votes vote down vote up
public void run() {
  try {

    final MinionArguments paramsFromParent = this.dis
        .read(MinionArguments.class);

    Log.setVerbose(paramsFromParent.isVerbose());

    final ClassLoader loader = IsolationUtils.getContextClassLoader();

    final ClassByteArraySource byteSource = new CachingByteArraySource(new ClassloaderByteArraySource(
        loader), CACHE_SIZE);

    final F3<ClassName, ClassLoader, byte[], Boolean> hotswap = new HotSwap(
        byteSource);

    final MutationEngine engine = createEngine(paramsFromParent.engine, paramsFromParent.engineArgs);


    final MutationTestWorker worker = new MutationTestWorker(hotswap,
        engine.createMutator(byteSource), loader, paramsFromParent.fullMutationMatrix);

    final List<TestUnit> tests = findTestsForTestClasses(loader,
        paramsFromParent.testClasses, createTestPlugin(paramsFromParent.pitConfig));

    worker.run(paramsFromParent.mutations, this.reporter,
        new TimeOutDecoratedTestSource(paramsFromParent.timeoutStrategy,
            tests, this.reporter));

    this.reporter.done(ExitCode.OK);
  } catch (final Throwable ex) {
    ex.printStackTrace(System.out);
    LOG.log(Level.WARNING, "Error during mutation test", ex);
    this.reporter.done(ExitCode.UNKNOWN_ERROR);
  }

}
 
Example #30
Source File: MutationEngine.java    From pitest with Apache License 2.0 2 votes vote down vote up
/**
 * Create a mutator using the given ClassByteArraySource as the source of
 * unmated classes
 *
 * @param source
 *          the source to use to retrieve unmated classes
 * @return a Mutater
 */
Mutater createMutator(ClassByteArraySource source);