public void calculateClassCoverage(final CoverageResult cr) { checkForFailedTest(cr); final TestInfo ti = this.createTestInfo(cr.getTestUnitDescription(), cr.getExecutionTime(), cr.getNumberOfCoveredBlocks()); for (final BlockLocation each : cr.getCoverage()) { addTestsToBlockMap(ti, each); } }
@Override public CoverageSummary createSummary() { return new CoverageSummary(numberOfLines(), coveredLines()); }
public static BlockLocation blockLocation(final Location location, final int block) { return new BlockLocation(location, block); }
@Test public void shouldIncludeAllCoveredLinesInCoverageSummary() { final BlockLocationBuilder block = aBlockLocation(); when(this.code.getCodeUnderTestNames()).thenReturn( Collections.singleton(block.build().getLocation().getClassName())); when(this.lm.mapLines(any(ClassName.class))).thenReturn( makeCoverageMapForBlock(block, 1, 2, 3, 4)); final CoverageResultBuilder cr = aCoverageResult().withVisitedBlocks( block.build(1)); this.testee.calculateClassCoverage(cr.build()); final CoverageSummary actual = this.testee.createSummary(); assertEquals(4, actual.getNumberOfCoveredLines()); }
private Function<String, TestInfo> toTestInfo(final BlockCoverage blockData) { return a -> new TestInfo(null, a, 0, Optional.ofNullable(blockData.getBlock().getLocation().getClassName()), blockData.getBlock().getBlock()); }
@Test public void shouldReportNumberOfCoveredLinesWhenSomeCovered() { final BlockLocationBuilder block = aBlockLocation().withLocation( aLocation().withClass(this.foo)); when(this.lm.mapLines(any(ClassName.class))).thenReturn( makeCoverageMapForBlock(block, 101, 300)); final CoverageResultBuilder cr = aCoverageResult().withVisitedBlocks( block.build(1)); this.testee.calculateClassCoverage(cr.build()); assertEquals(2, this.testee.getNumberOfCoveredLines(Collections .singletonList(this.foo))); }
private static Generator<CoverageResultBuilder, CoverageResult> CoverageResultSeed() { return b -> new CoverageResult(b._TestUnitDescription(), b._ExecutionTime(), b._GreenSuite(), b._VisitedBlocks()); }
@Before public void setUp() { this.testee = new TestInfoNameComparator(); this.lhs = new TestInfo("foo", "0name", 0, Optional.<ClassName> empty(), 0); this.rhs = new TestInfo("foo", "1name", 0, Optional.<ClassName> empty(), 0); }
public static Function<TestInfo, String> toName() { return a -> a.getName(); }
private void checkForFailedTest(final CoverageResult cr) { if (!cr.isGreenTest()) { recordTestFailure(cr.getTestUnitDescription()); LOG.severe(cr.getTestUnitDescription() + " did not pass without mutation."); } }
@Test public void shouldReportAGreenSuiteWhenNoTestHasFailed() { this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest", 42, 1)); assertTrue(this.testee.allTestsGreen()); }
private CoverageResult makeCoverageResult(final String clazz, final Description desc, final int time, final int block, final boolean testPassed) { return new CoverageResult(desc, time, testPassed, makeCoverage(clazz, block)); }
private static Generator<BlockLocationBuilder, BlockLocation> blockLocationSeed() { return b -> BlockLocation.blockLocation(b._Location(), b._Block()); }
private Function<TestInfo, Integer> toTime() { return a -> a.getTime(); }
private BiFunction<Integer, ClassName, Integer> numberCoveredLines() { return (a, clazz) -> a + getNumberOfCoveredLines(clazz); }
@Override public Collection<TestInfo> getTestsForClassLine(final ClassLine classLine) { final Collection<TestInfo> result = getTestsForClassName( classLine.getClassName()).get(classLine); if (result == null) { return Collections.emptyList(); } else { return result; } }
private Predicate<CoverageResult> failingTest() { return a -> !a.isGreenTest(); }
private int weightForDirectHit(final TestInfo arg0) { return arg0.directlyHits(this.targetClass) ? this.distanceTimeWeighting : 0; }
private static Function<TestInfo, String> testInfoToString() { return a -> a.getName(); }
private static Function<TestInfo, Integer> testInfoToExecutionTime() { return a -> a.getTime(); }