Java Code Examples for org.pitest.classinfo.ClassName#fromClass()

The following examples show how to use org.pitest.classinfo.ClassName#fromClass() . 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: MutationCoverageReportTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRecordClassPath() {

  final ClassName clazz = ClassName.fromClass(Foo.class);

  final HierarchicalClassId fooId = new HierarchicalClassId(
      new ClassIdentifier(0, clazz), "0");
  final ClassInfo foo = ClassInfoMother.make(fooId.getId());

  when(this.code.getCodeUnderTestNames()).thenReturn(
      Collections.singleton(clazz));
  when(this.code.getClassInfo(any(List.class))).thenReturn(
      Collections.singletonList(foo));

  createAndRunTestee();

  verify(this.history).recordClassPath(Arrays.asList(fooId), this.coverageDb);
}
 
Example 2
Source File: CoverageProcessSystemTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCalculateCoverageForSmallMethodThatThrowsException()
    throws IOException, InterruptedException, ExecutionException {
  final List<CoverageResult> coveredClasses = runCoverageForTest(TestsClassWithException.class);
  assertThat(coveredClasses).anyMatch(coverageFor(CoveredBeforeExceptionTestee.class));

  final ClassName throwsException = ClassName
      .fromClass(ThrowsExceptionTestee.class);

  assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation(
      Location.location(throwsException, this.foo, "()V"), 0)));

      assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation(
      Location.location(throwsException,
          MethodName.fromString("throwsException"), "()V"), 0)));

}
 
Example 3
Source File: MutationCoverageReportTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("is triggering filter with fake classes")
public void shouldReportMutationsFoundWhenSomeDetected() {
  this.data.setFailWhenNoMutations(false);
  final ClassName foo = ClassName.fromClass(Foo.class);
  when(this.mutater.findMutations(foo)).thenReturn(
      MutationDetailsMother.aMutationDetail().build(1));
  when(this.code.getCodeUnderTestNames()).thenReturn(
      Collections.singleton(foo));
  final CombinedStatistics actual = createAndRunTestee();
  assertEquals(1, actual.getMutationStatistics().getTotalMutations());
}
 
Example 4
Source File: LoggingCallsFilterTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLeaveMutantsNotOnLoggingLinesUntouched() {
  final ClassName clazz = ClassName.fromClass(DoesNotLog.class);
  final List<MutationDetails> input = this.mutator.findMutations(clazz);
  final Collection<MutationDetails> actual = analyseWithTestee(DoesNotLog.class);

  assertThat(actual).containsExactlyElementsOf(input);
}
 
Example 5
Source File: FilterTester.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Sample makeSampleForCurrentCompiler(Class<?> clazz) {
  final ClassloaderByteArraySource source = ClassloaderByteArraySource.fromContext();
  final Sample s = new Sample();
  s.className = ClassName.fromClass(clazz);
  s.clazz = ClassTree.fromBytes(source.getBytes(clazz.getName()).get());
  s.compiler = "current";
  return s;
}
 
Example 6
Source File: FilterTester.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Sample sampleForClass(Class<?> clazz) {
  final ClassloaderByteArraySource source = ClassloaderByteArraySource.fromContext();
  final Sample s = new Sample();
  s.className = ClassName.fromClass(clazz);
  s.clazz = ClassTree.fromBytes(source.getBytes(clazz.getName()).get());
  s.compiler = "current";
  return s;
}
 
Example 7
Source File: CoverageProcessSystemTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCalculateCoverageForMethodThatThrowsExceptionWithFinallyBlock()
    throws IOException, InterruptedException, ExecutionException {
  final List<CoverageResult> coveredClasses = runCoverageForTest(TestThrowsExceptionInFinallyBlock.class);

  final ClassName clazz = ClassName
      .fromClass(ThrowsExceptionInFinallyBlockTestee.class);

  assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation(
      Location.location(clazz, this.foo, "()V"), 0)));

      assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation(
      Location.location(clazz, this.foo, "()V"), 4)));
}
 
Example 8
Source File: CoverageProcessSystemTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCalculateCoverageForLargeMethodThatThrowsException()
    throws IOException, InterruptedException, ExecutionException {
  final List<CoverageResult> coveredClasses = runCoverageForTest(TestThrowsExceptionFromLargeMethodTestee.class);

  final ClassName clazz = ClassName
      .fromClass(ThrowsExceptionFromLargeMethodTestee.class);

  assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation(
      Location.location(clazz, this.foo, "()I"), 0)));

}
 
Example 9
Source File: MutantExportInterceptorTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
private Path classBasePath(Class<?> clazz) {
  final ClassName name = ClassName.fromClass(clazz);
  return this.fileSystem.getPath("target/export",name.asInternalName().split("/"));
}
 
Example 10
Source File: LoggingCallsFilterTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
private Collection<MutationDetails> analyseWithTestee(Class<?> clazz) {
  final ClassName name = ClassName.fromClass(clazz);
  this.testee.begin(treeFor(clazz));
  final List<MutationDetails> input = this.mutator.findMutations(name);
  return this.testee.intercept(input, this.mutator);
}