private CoverageData calculateCoverage(final CodeSource codeSource, final MutationMetaData metadata) throws ReportAggregationException { final Collection<BlockCoverage> coverageData = this.blockCoverageLoader.loadData(); try { final Map<BlockLocation, Set<TestInfo>> blockCoverageMap = blocksToMap(coverageData); return new CoverageData(codeSource, new LineMapper(codeSource),blockCoverageMap); } catch (final Exception e) { throw new ReportAggregationException(e.getMessage(), e); } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); when(this.lm.mapLines(any(ClassName.class))).thenReturn( new HashMap<BlockLocation, Set<Integer>>()); when(this.code.findTestee(any())).thenReturn(Optional.empty()); this.testee = new CoverageData(this.code, this.lm); }
@Test public void shouldProvideListOfClassesForSourceFile() { final ClassInfo fooClass = ClassInfoMother.make(this.foo, "foo.java"); final ClassInfo barClass = ClassInfoMother.make(this.bar, "bar.java"); final Collection<ClassInfo> classes = Arrays.asList(fooClass, barClass); when(this.code.getCode()).thenReturn(classes); this.testee = new CoverageData(this.code, this.lm); assertEquals(Arrays.asList(barClass), this.testee.getClassesForFile("bar.java", "")); }
@Override public CoverageData calculateCoverage() { try { final long t0 = System.currentTimeMillis(); this.timings.registerStart(Timings.Stage.SCAN_CLASS_PATH); final Collection<ClassInfo> tests = this.code.getTests(); this.timings.registerEnd(Timings.Stage.SCAN_CLASS_PATH); final CoverageData coverage = new CoverageData(this.code, new LineMapper( this.code)); this.timings.registerStart(Timings.Stage.COVERAGE); gatherCoverageData(tests, coverage); this.timings.registerEnd(Timings.Stage.COVERAGE); final long time = (System.currentTimeMillis() - t0) / 1000; LOG.info("Calculated coverage in " + time + " seconds."); verifyBuildSuitableForMutationTesting(coverage); this.exporter.recordCoverage(coverage.createCoverage()); return coverage; } catch (final PitHelpError phe) { throw phe; } catch (final Exception e) { throw Unchecked.translateCheckedException(e); } }
@Test public void shouldMatchPackageWhenFindingSources() { final ClassName foo1 = ClassName.fromString("a.b.c.foo"); final ClassName foo2 = ClassName.fromString("d.e.f.foo"); final ClassInfo foo1Class = ClassInfoMother.make(foo1, "foo.java"); final ClassInfo foo2Class = ClassInfoMother.make(foo2, "foo.java"); final Collection<ClassInfo> classes = Arrays.asList(foo1Class, foo2Class); when(this.code.getCode()).thenReturn(classes); this.testee = new CoverageData(this.code, this.lm); assertEquals(Arrays.asList(foo1Class), this.testee.getClassesForFile("foo.java", "a.b.c")); }