From 0bc43372dd6869e37909cf108584050b47288e83 Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Mon, 27 Feb 2023 11:01:23 +0000 Subject: [PATCH] report only target code lines --- .../org/pitest/mutationtest/tooling/MutationCoverage.java | 5 ++--- .../mutationtest/tooling/MutationCoverageReportTest.java | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java index befb7d349..86710fbdb 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java @@ -14,7 +14,6 @@ */ package org.pitest.mutationtest.tooling; -import org.pitest.bytecode.analysis.ClassTree; import org.pitest.classinfo.CachingByteArraySource; import org.pitest.classinfo.ClassByteArraySource; import org.pitest.classinfo.ClassInfo; @@ -201,8 +200,8 @@ private ReportCoverage transformCoverage(ReportCoverage coverageData) { } private CoverageSummary createSummary(ReportCoverage modifiedCoverage) { - int numberOfCodeLines = this.code.codeTrees() - .map(ClassTree::numberOfCodeLines) + int numberOfCodeLines = this.code.getCodeUnderTestNames().stream() + .map(c -> modifiedCoverage.getCodeLinesForClass(c).getNumberOfCodeLines()) .reduce(0, Integer::sum); int coveredLines = this.code.getCodeUnderTestNames().stream() diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/MutationCoverageReportTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/MutationCoverageReportTest.java index baa48dd03..b2578b33b 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/MutationCoverageReportTest.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/MutationCoverageReportTest.java @@ -41,6 +41,7 @@ import org.pitest.classinfo.ClassName; import org.pitest.classinfo.HierarchicalClassId; import org.pitest.classpath.CodeSource; +import org.pitest.coverage.ClassLines; import org.pitest.coverage.CoverageDatabase; import org.pitest.coverage.CoverageGenerator; import org.pitest.help.Help; @@ -158,6 +159,7 @@ public void shouldRecordClassPath() { Collections.singleton(clazz)); when(this.code.getClassInfo(anyCollection())).thenReturn( Collections.singletonList(foo)); + when(this.coverageDb.getCodeLinesForClass(clazz)).thenReturn(new ClassLines(clazz, Collections.emptySet())); createAndRunTestee(); @@ -198,6 +200,7 @@ public void shouldReportMutationsFoundWhenSomeDetected() { when(this.mutater.findMutations(foo)).thenReturn(aMutantIn(Foo.class)); when(this.code.getCodeUnderTestNames()).thenReturn( Collections.singleton(foo)); + when(this.coverageDb.getCodeLinesForClass(foo)).thenReturn(new ClassLines(foo, Collections.emptySet())); final CombinedStatistics actual = createAndRunTestee(); assertEquals(1, actual.getMutationStatistics().getTotalMutations()); }