private Collection<TestInfo> pickTests(MutationDetails mutation) { if (!mutation.isInStaticInitializer()) { return this.coverage.getTestsForClassLine(mutation.getClassLine()); } else { LOG.warning("Using untargetted tests"); return this.coverage.getTestsForClass(mutation.getClassName()); } }
@Override public void recordClassPath(final Collection<HierarchicalClassId> ids, final CoverageDatabase coverageInfo) { final PrintWriter output = this.outputFactory.create(); output.println(ids.size()); for (final HierarchicalClassId each : ids) { final ClassHistory coverage = new ClassHistory(each, coverageInfo.getCoverageIdForClass(each.getName()).toString(16)); output.println(serialize(coverage)); } output.flush(); }
public MutationTestSummaryData createSummaryData( final CoverageDatabase coverage, final ClassMutationResults data) { return new MutationTestSummaryData(data.getFileName(), data.getMutations(), this.mutatorNames, coverage.getClassInfo(Collections.singleton(data .getMutatedClass())), coverage.getNumberOfCoveredLines(Collections .singleton(data.getMutatedClass()))); }
private boolean isLineCovered(final int line) { final Predicate<ClassInfo> predicate = a -> !AnnotatedLineFactory.this.statistics.getTestsForClassLine( new ClassLine(a.getName().asInternalName(), line)).isEmpty(); return FCollection.contains(this.classesInFile, predicate); }
private boolean killingTestHasNotChanged(final MutationDetails each, final MutationStatusTestPair mutationStatusTestPair) { final Collection<TestInfo> allTests = this.coverage.getTestsForClass(each .getClassName()); final List<ClassName> testClasses = allTests.stream() .filter(testIsCalled(mutationStatusTestPair.getKillingTest().get())) .map(TestInfo.toDefiningClassName()) .collect(Collectors.toList()); if (testClasses.isEmpty()) { return false; } return !this.history.hasClassChanged(testClasses.get(0)); }
private List<Line> createAnnotatedSourceCodeLines(final String sourceFile, final String packageName, final MutationResultList mutationsForThisFile) throws IOException { final Collection<ClassInfo> classes = this.coverage.getClassesForFile( sourceFile, packageName); final Optional<Reader> reader = findSourceFile(classInfoToNames(classes), sourceFile); if (reader.isPresent()) { final AnnotatedLineFactory alf = new AnnotatedLineFactory( mutationsForThisFile.list(), this.coverage, classes); return alf.convert(reader.get()); } return Collections.emptyList(); }
coverageData.createSummary());
@Test public void shouldAssignTestsForRelevantLineToGeneratedMutations() { final List<TestInfo> expected = makeTestInfos(0); when(this.coverage.getTestsForClassLine(any(ClassLine.class))).thenReturn( expected); final List<TestInfo> actual = this.testee.assignTests(makeMutation("foo")); assertEquals(expected, actual); }
private Set<ClassName> getAllClassesAndTests( final CoverageDatabase coverageData) { final Set<ClassName> names = new HashSet<>(); for (final ClassName each : this.code.getCodeUnderTestNames()) { names.add(each); FCollection.mapTo(coverageData.getTestsForClass(each), TestInfo.toDefiningClassName(), names); } return names; }
@Test public void shouldPrioritiseTestsByExecutionTime() { final List<TestInfo> unorderedTests = makeTestInfos(10000, 100, 1000, 1); when(this.coverage.getTestsForClassLine(any(ClassLine.class))).thenReturn( unorderedTests); final List<TestInfo> actual = this.testee.assignTests(makeMutation("foo")); assertEquals(Arrays.asList(1, 100, 1000, 10000), FCollection.map(actual, toTime())); }
@Test public void shouldStartPreviousKilledMutationsAtAStatusOfNotStartedWhenNeitherClassOrTestHasChanged() { final MutationDetails md = makeMutation("foo"); final String killingTest = "fooTest"; setHistoryForAllMutationsTo(DetectionStatus.KILLED, killingTest); final Collection<TestInfo> tests = Collections.singleton(new TestInfo( "TEST_CLASS", killingTest, 0, Optional.<ClassName> empty(), 0)); when(this.coverage.getTestsForClass(any(ClassName.class))) .thenReturn(tests); when(this.history.hasClassChanged(any(ClassName.class))).thenReturn(false); final MutationResult actual = this.testee .analyse(Collections.singletonList(md)).iterator().next(); assertEquals(DetectionStatus.KILLED, actual.getStatus()); assertEquals(Optional.ofNullable(killingTest), actual.getKillingTest()); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); when(this.coverage.getCoverageIdForClass(any(ClassName.class))).thenReturn( BigInteger.TEN); }
@Test public void shouldStartPreviousKilledMutationsAtAStatusOfKilledWhenNeitherClassOrTestHasChanged() { final MutationDetails md = makeMutation("foo"); final String killingTest = "fooTest"; setHistoryForAllMutationsTo(DetectionStatus.KILLED, killingTest); final Collection<TestInfo> tests = Collections.singleton(new TestInfo( "TEST_CLASS", killingTest, 0, Optional.<ClassName> empty(), 0)); when(this.coverage.getTestsForClass(any(ClassName.class))) .thenReturn(tests); when(this.history.hasClassChanged(ClassName.fromString("foo"))).thenReturn( false); when(this.history.hasClassChanged(ClassName.fromString("TEST_CLASS"))) .thenReturn(true); final MutationResult actual = this.testee .analyse(Collections.singletonList(md)).iterator().next(); assertEquals(DetectionStatus.NOT_STARTED, actual.getStatus()); }
private MutationResult analyseFromHistory(final MutationDetails each, final MutationStatusTestPair mutationStatusTestPair) { final ClassName clazz = each.getClassName(); if (this.history.hasClassChanged(clazz)) { return analyseFromScratch(each); } if (mutationStatusTestPair.getStatus() == DetectionStatus.TIMED_OUT) { return makeResult(each, DetectionStatus.TIMED_OUT); } if ((mutationStatusTestPair.getStatus() == DetectionStatus.KILLED) && killingTestHasNotChanged(each, mutationStatusTestPair)) { return makeResult(each, DetectionStatus.KILLED, mutationStatusTestPair .getKillingTests(), mutationStatusTestPair.getSucceedingTests()); } if ((mutationStatusTestPair.getStatus() == DetectionStatus.SURVIVED) && !this.history.hasCoverageChanged(clazz, this.coverage.getCoverageIdForClass(clazz))) { return makeResult(each, DetectionStatus.SURVIVED); } return analyseFromScratch(each); }
@Test public void shouldAssignAllTestsForClassWhenMutationInStaticInitialiser() { final List<TestInfo> expected = makeTestInfos(0); when(this.coverage.getTestsForClass(this.foo)).thenReturn(expected); final List<TestInfo> actual = this.testee .assignTests(makeMutation("<clinit>") .withPoisonStatus(PoisonStatus.IS_STATIC_INITIALIZER_CODE)); assertEquals(expected, actual); }