Java源码示例:org.pitest.classinfo.ClassByteArraySource

示例1
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;
}
 
示例2
@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);
}
 
示例3
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());
}
 
示例4
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);
  };
}
 
示例5
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;
}
 
示例6
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);
}
 
示例7
private void mockMutationEngine() {
  when(
      this.mutationFactory.createEngine(any(EngineArguments.class))).thenReturn(
              this.engine);
  when(this.engine.createMutator(any(ClassByteArraySource.class)))
  .thenReturn(this.mutater);
}
 
示例8
@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());
}
 
示例9
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);
}
 
示例10
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));
}
 
示例11
public GregorMutater(final ClassByteArraySource byteSource,
    final Predicate<MethodInfo> filter,
    final Collection<MethodMutatorFactory> mutators) {
  this.filter = filter;
  this.mutators.addAll(mutators);
  this.byteSource = byteSource;
}
 
示例12
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());
}
 
示例13
public DescartesMutater(final ClassByteArraySource byteSource, DescartesMutationEngine engine) {
    this.byteSource = byteSource;
    this.engine = engine;
}
 
示例14
public MutantExportInterceptor(FileSystem fileSystem,
    ClassByteArraySource source, String outDir) {
  this.fileSystem = fileSystem;
  this.outDir = outDir;
  this.source = source;
}
 
示例15
public JarCreatingJarFinder(final ClassByteArraySource classByteSource) {
  this.classByteSource = classByteSource;
}
 
示例16
public InterceptorParameters(FeatureSetting conf, ReportOptions data,
    ClassByteArraySource source) {
  this.conf = conf;
  this.data = data;
  this.source = source;
}
 
示例17
public ClassByteArraySource source() {
  return this.source;
}
 
示例18
public Mutater createMutator(final ClassByteArraySource source) {
  return this.engine.createMutator(source);
}
 
示例19
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
    ClassByteArraySource source, Collection<String> excludedRunner, Collection<String> includedTestMethods) {
  return new TestNGConfiguration(config, includedTestMethods);
}
 
示例20
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
    ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedTestMethods) {
  Objects.requireNonNull(config);
  return new JUnitCompatibleConfiguration(config, excludedRunners, includedTestMethods);
}
 
示例21
Configuration createTestFrameworkConfiguration(TestGroupConfig config,
ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedTestMethods);
 
示例22
@Override
public Mutater createMutator(final ClassByteArraySource byteSource) {
  return new GregorMutater(byteSource, this.methodFilter,
      this.mutationOperators);
}
 
示例23
HotSwap(final ClassByteArraySource byteSource) {
  this.byteSource = byteSource;
}
 
示例24
public DependencyExtractor(final ClassByteArraySource classToBytes,
    final int depth) {
  this.depth = depth;
  this.classToBytes = classToBytes;
}
 
示例25
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
    ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedMethods) {
  return new ConfigurationForTesting();
}
 
示例26
protected void createTesteeWith(final ClassByteArraySource source,
    final Predicate<MethodInfo> filter,
    final Collection<MethodMutatorFactory> mutators) {
  this.engine = new GregorMutater(source, filter, mutators);
}
 
示例27
public Configuration createTestFrameworkConfiguration(TestGroupConfig config,
                                                      ClassByteArraySource source,
                                                      Collection<String> excludedRunners) {

    return new CucumberJUnitCompatibleConfiguration(config);
}
 
示例28
@Override
public Configuration createTestFrameworkConfiguration(TestGroupConfig config, ClassByteArraySource source, Collection<String> excludedRunners, Collection<String> includedTestMethods) {
    Objects.requireNonNull(config);
    return new CucumberJUnitCompatibleConfiguration(config);
}
 
示例29
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);
  }

}
 
示例30
public Mutater createMutator(final ClassByteArraySource byteSource) {

        return new DescartesMutater(byteSource, this);
    }