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

The following examples show how to use org.pitest.classinfo.ClassName#fromString() . 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: MethodRecordTest.java    From pitest-descartes with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static MutationResult mutation(DetectionStatus status, String mutant) {
    return new MutationResult(
            new MutationDetails(
                    new MutationIdentifier(
                    new Location(
                            ClassName.fromString("AClass"),
                            MethodName.fromString("aMethod"),
                            "()I"),
                            1,
                            mutant),
                    "path/to/file",
                    "Mutation description",
                    1,
                    0),
            new MutationStatusTestPair(1, status, null));
}
 
Example 2
Source File: CoverageDataTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnNonZeroCoverageIdWhenTestsCoverClass() {

  final ClassName foo = ClassName.fromString("Foo");
  final ClassInfo ci = ClassInfoMother.make(foo);

  when(this.code.getClassInfo(any(Collection.class))).thenReturn(
      Collections.singletonList(ci));

  final BlockLocationBuilder block = aBlockLocation().withLocation(
      aLocation().withClass(foo));
  final HashMap<BlockLocation, Set<Integer>> map = makeCoverageMapForBlock(block,
      42);
  when(this.lm.mapLines(any(ClassName.class))).thenReturn(map);
  this.testee.calculateClassCoverage(aCoverageResult().withVisitedBlocks(
      block.build(1)).build());

  assertThat(this.testee.getCoverageIdForClass(foo).longValue())
      .isNotEqualTo(0);

}
 
Example 3
Source File: ObjectOutputStreamHistoryStoreTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRecordAndRetrieveClassPath() {
    final ClassHistory foo = new ClassHistory(new HierarchicalClassId(
        new ClassIdentifier(0, ClassName.fromString("foo")), ""), COV);
    final ClassHistory bar = new ClassHistory(new HierarchicalClassId(
        new ClassIdentifier(0, ClassName.fromString("bar")), ""), COV);

    recordClassPathWithTestee(foo.getId(), bar.getId());

    final Reader reader = new StringReader(this.output.toString());
    this.testee = new ObjectOutputStreamHistoryStore(this.writerFactory,
        Optional.ofNullable(reader));
    this.testee.initialize();

    final Map<ClassName, ClassHistory> expected = new HashMap<>();
    expected.put(foo.getName(), foo);
    expected.put(bar.getName(), bar);
    assertEquals(expected, this.testee.getHistoricClassPath());
}
 
Example 4
Source File: ObjectOutputStreamHistoryStoreTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRecordAndRetrieveResults() {
    final HierarchicalClassId foo = new HierarchicalClassId(
        new ClassIdentifier(0, ClassName.fromString("foo")), "");
    recordClassPathWithTestee(foo);

    final MutationResult mr = new MutationResult(
        MutationTestResultMother.createDetails("foo"),
        new MutationStatusTestPair(1, DetectionStatus.KILLED, "testName"));

    this.testee.recordResult(mr);

    final Reader reader = new StringReader(this.output.toString());
    this.testee = new ObjectOutputStreamHistoryStore(this.writerFactory,
        Optional.ofNullable(reader));
    this.testee.initialize();
    final Map<MutationIdentifier, MutationStatusTestPair> expected = new HashMap<>();
    expected.put(mr.getDetails().getId(), mr.getStatusTestPair());
    assertEquals(expected, this.testee.getHistoricResults());
}
 
Example 5
Source File: CoverageDataTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMatchPackageWhenFindingSources() {
  final ClassName foo1 = ClassName.fromString("a.b.c.foo");
  final ClassName foo2 = ClassName.fromString("d.e.f.foo");
  final ClassInfo foo1Class = ClassInfoMother.make(foo1, "foo.java");
  final ClassInfo foo2Class = ClassInfoMother.make(foo2, "foo.java");
  final Collection<ClassInfo> classes = Arrays.asList(foo1Class, foo2Class);
  when(this.code.getCode()).thenReturn(classes);

  this.testee = new CoverageData(this.code, this.lm);

  assertEquals(Arrays.asList(foo1Class),
      this.testee.getClassesForFile("foo.java", "a.b.c"));
}
 
Example 6
Source File: TestUtils.java    From pitest-descartes with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Collection<MutationDetails> findMutationPoints(Class<?> target, String... operators) throws IOException {
    DescartesEngineFactory factory = new DescartesEngineFactory();
    MutationEngine engine = factory.createEngine(EngineArguments.arguments().withMutators(Arrays.asList(operators)));
    String className = target.getName();
    ClassReader reader = new ClassReader(className);
    MutationPointFinder finder = new MutationPointFinder(ClassName.fromString(className), (DescartesMutationEngine) engine);
    reader.accept(finder, 0);
    return finder.getMutationPoints();
}
 
Example 7
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFilterMutantsInTryFinallyCompiledWithAspectJ() {
  this.data.setDetectInlinedCode(true);

  final ClassName clazz = ClassName.fromString("trywithresources/TryFinallyExample_aspectj");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(2);
}
 
Example 8
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFilterMutantsInTryFinallyCompiledWithEcj() {
  this.data.setDetectInlinedCode(true);

  final ClassName clazz = ClassName.fromString("trywithresources/TryFinallyExample_ecj");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(2);
}
 
Example 9
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFilterMutantsInTryFinallyCompiledWithJavaC() {
  this.data.setDetectInlinedCode(true);

  final ClassName clazz = ClassName.fromString("trywithresources/TryFinallyExample_javac");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(2);
}
 
Example 10
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFilterMutantsInTryCatchFinallyCompiledWithAspectJ() {
  this.data.setDetectInlinedCode(true);

  final ClassName clazz = ClassName.fromString("trywithresources/TryCatchFinallyExample_aspectj");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(3);
}
 
Example 11
Source File: BlockCoverageDataLoader.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
protected BlockCoverage mapToData(final Map<String, Object> map) {
  final String method = (String) map.get(METHOD);
  final Location location = new Location(ClassName.fromString((String) map.get(CLASSNAME)),
      MethodName.fromString(method.substring(0, method.indexOf(OPEN_PAREN))), method.substring(method.indexOf(OPEN_PAREN)));

  final BlockLocation blockLocation = new BlockLocation(location, Integer.parseInt((String) map.get(NUMBER)),
      Integer.parseInt((String) map.get(FIRST_INSN)),Integer.parseInt((String) map.get(LAST_INSN)));

  @SuppressWarnings("unchecked")
  final Collection<String> tests = (Collection<String>) map.get(TESTS);

  return new BlockCoverage(blockLocation, tests);
}
 
Example 12
Source File: MutationTestBuilderTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldOrderLargestUnitFirst() {
  final MutationDetails mutation1 = createDetails("foo");
  final MutationDetails mutation2 = createDetails("bar");
  final ClassName foo = ClassName.fromString("foo");
  final ClassName bar = ClassName.fromString("bar");
  when(this.source.createMutations(foo)).thenReturn(Arrays.asList(mutation1));
  when(this.source.createMutations(bar)).thenReturn(
      Arrays.asList(mutation2, mutation2));
  final List<MutationAnalysisUnit> actual = this.testee
      .createMutationTestUnits(Arrays.asList(foo, bar));
  assertTrue(actual.get(0).priority() > actual.get(1).priority());
}
 
Example 13
Source File: DefaultCodeHistoryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldTreatClassesWithSameHashAsUnChanged() {
  final ClassName foo = ClassName.fromString("foo");
  final HierarchicalClassId currentId = new HierarchicalClassId(0, foo, "0");
  setCurrentClassPath(currentId);
  this.historicClassPath.put(foo, makeHistory(currentId));
  assertFalse(this.testee.hasClassChanged(ClassName.fromString("foo")));
}
 
Example 14
Source File: DefaultCodeHistoryTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldTreatClassesWithDifferentHashesAsChanged() {
  final long currentHash = 42;
  final ClassName foo = ClassName.fromString("foo");
  final ClassIdentifier currentId = new ClassIdentifier(currentHash, foo);
  setCurrentClassPath(ClassInfoMother.make(currentId));
  this.historicClassPath.put(foo, makeHistory(new HierarchicalClassId(
      currentHash + 1, foo, "0")));
  assertTrue(this.testee.hasClassChanged(ClassName.fromString("foo")));
}
 
Example 15
Source File: TestInfoPriorisationComparatorTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
  this.testee = new TestInfoPriorisationComparator(ClassName.fromString(TARGET),
      TIME_WEIGHTING);
}
 
Example 16
Source File: ClassLine.java    From pitest with Apache License 2.0 4 votes vote down vote up
public ClassLine(final String clazz, final int lineNumber) {
  this(ClassName.fromString(clazz), lineNumber);
}
 
Example 17
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldFilterMutantsInTryWithResourcesClosableCompiledWithApectj() {
  final ClassName clazz = ClassName.fromString("trywithresources/TryWithTwoCloseableExample_aspectj");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(1);
}
 
Example 18
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldFilterMutantsInTryWithResourcesClosableCompiledWithEcj() {
  final ClassName clazz = ClassName.fromString("trywithresources/TryWithTwoCloseableExample_ecj");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(1);
}
 
Example 19
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldFilterMutantsInTryWithResourcesClosableCompiledWithJavac() {
  final ClassName clazz = ClassName.fromString("trywithresources/TryWithTwoCloseableExample_javac");
  final Collection<MutationDetails> actual = findMutants(clazz);
  assertThat(actual).hasSize(1);
}
 
Example 20
Source File: MutationDiscoveryTest.java    From pitest with Apache License 2.0 3 votes vote down vote up
@Test
public void shouldFilterImplicitNullChecksInLambdas() {
  final ClassName clazz = ClassName.fromString("implicitnullcheck/RemovedCallBug_javac");

  this.data.setMutators(Collections.singletonList("ALL"));

  final Collection<MutationDetails> foundByDefault = findMutants(clazz);

  this.data.setFeatures(Collections.singletonList("-FINULL"));

  final Collection<MutationDetails> foundWhenDisabled = findMutants(clazz);

  assertThat(foundWhenDisabled.size()).isGreaterThan(foundByDefault.size());
}