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)); }
@Test public void shouldReturnUniqueTestsForClassWhenSomeTestsCoverClass() { this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest", 0, 1)); this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest", 0, 2)); this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest2", 0, 2)); assertEquals(Arrays.asList("fooTest", "fooTest2"), FCollection.map( this.testee.getTestsForClass(this.foo), testInfoToString())); }
@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())); }
private CoverageResult makeCoverageResult(final String clazz, final String testName, final int time, final int block) { return makeCoverageResult(clazz, new Description(testName), time, block, true); }
@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 shouldReportAGreenSuiteWhenNoTestHasFailed() { this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest", 42, 1)); assertTrue(this.testee.allTestsGreen()); }
@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 shouldNotReportAGreenSuiteWhenATestHasFailed() { this.testee.calculateClassCoverage(makeCoverageResult("foo", new Description("fooTest"), 42, 1, false)); assertFalse(this.testee.allTestsGreen()); }
@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))); }
@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"); }