@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); }
@Test public void shouldStoreExecutionTimesOfTests() { final int line = 1; final int time = 42; final BlockLocationBuilder block = aBlockLocation().withLocation( aLocation().withClass(this.foo)); when(this.lm.mapLines(any(ClassName.class))).thenReturn( makeCoverageMapForBlock(block, line)); final CoverageResultBuilder cr = aCoverageResult().withVisitedBlocks( block.build(1)).withExecutionTime(time); this.testee.calculateClassCoverage(cr.build()); assertEquals(Arrays.asList(42), FCollection.map( this.testee.getTestsForClassLine(new ClassLine(this.foo, line)), testInfoToExecutionTime())); }
@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 shouldProvideCoverageListWhenCoverageRecorded() { final BlockLocationBuilder block = aBlockLocation().withLocation( aLocation().withClass(this.foo)); final CoverageResultBuilder cr = aCoverageResult().withVisitedBlocks( block.build(1)); this.testee.calculateClassCoverage(cr.build()); this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest", 0, 1)); final BlockCoverage actual = this.testee.createCoverage().get(0); assertEquals(block.build(), actual.getBlock()); assertThat(actual.getTests()).contains("FooTest.fooTest"); }
private static Generator<CoverageResultBuilder, CoverageResult> CoverageResultSeed() { return b -> new CoverageResult(b._TestUnitDescription(), b._ExecutionTime(), b._GreenSuite(), b._VisitedBlocks()); }
public static CoverageResultBuilder aCoverageResult() { final ClassName fooTest = ClassName.fromString("FooTest"); return QB .builder(CoverageResultBuilder.class, CoverageResultSeed()) .withTestUnitDescription( new Description("fooTest", fooTest.asJavaName())) .withExecutionTime(1).withGreenSuite(true) .withVisitedBlocks(Collections.<BlockLocation> emptyList()); }
@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))); }