private void throwErrorIfCoverageBelowThreshold( final CoverageSummary coverageSummary) throws MojoFailureException { if ((this.coverageThreshold != 0) && (coverageSummary.getCoverage() < this.coverageThreshold)) { throw new MojoFailureException("Line coverage of " + coverageSummary.getCoverage() + "(" + coverageSummary.getNumberOfCoveredLines() + "/" + coverageSummary.getNumberOfLines() + ") is below threshold of " + this.coverageThreshold); } }
@Test public void shouldCorrectlyCalculateLineCoverageWhenAllLinesCovered() { assertEquals(100, new CoverageSummary(100, 100).getCoverage()); }
private static void throwErrorIfScoreBelowCoverageThreshold( CoverageSummary stats, int threshold) { if ((threshold != 0) && (stats.getCoverage() < threshold)) { throw new RuntimeException("Line coverage of " + stats.getCoverage() + " is below threshold of " + threshold); } }
@Override public CoverageSummary createSummary() { return new CoverageSummary(numberOfLines(), coveredLines()); }
@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()); }
@Test public void shouldCorrectlyCalculateLineCoverageWhenPartiallyCovered() { assertEquals(50, new CoverageSummary(100, 50).getCoverage()); }
@Test public void shouldCorrectlyCalculateLineCoverageWhenNoLinesPresent() { assertEquals(100, new CoverageSummary(0, 0).getCoverage()); }
private void throwErrorIfCoverageBelowThreshold( final CoverageSummary coverageSummary) throws MojoFailureException { if ((this.coverageThreshold != 0) && (coverageSummary.getCoverage() < this.coverageThreshold)) { throw new MojoFailureException("Line coverage of " + coverageSummary.getCoverage() + "(" + coverageSummary.getNumberOfCoveredLines() + "/" + coverageSummary.getNumberOfLines() + ") is below threshold of " + this.coverageThreshold); } }
@Test public void shouldCorrectlyCalculateLineCoverageWhenNoLinesCovered() { assertEquals(0, new CoverageSummary(100, 0).getCoverage()); }