From 7807743717c0fcf4d0c5c8eecd6de376bad1a84b Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Thu, 29 Apr 2021 14:26:06 +0100 Subject: [PATCH] reposition public members --- .../org/pitest/coverage/CoverageData.java | 2 +- .../pitest/coverage/LegacyClassCoverage.java | 54 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java b/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java index 9986a6150..6181fc5ca 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java @@ -45,7 +45,7 @@ public class CoverageData implements CoverageDatabase { // We calculate block coverage, but everything currently runs on line // coverage. Ugly mess of maps below should go when // api changed to work via blocks - private final Map> instructionCoverage = new LinkedHashMap<>(); + private final Map> instructionCoverage = new LinkedHashMap<>(); private final LegacyClassCoverage legacyClassCoverage; private final CodeSource code; diff --git a/pitest-entry/src/main/java/org/pitest/coverage/LegacyClassCoverage.java b/pitest-entry/src/main/java/org/pitest/coverage/LegacyClassCoverage.java index 77f4d0d9d..fee346778 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/LegacyClassCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/LegacyClassCoverage.java @@ -40,27 +40,6 @@ public void loadBlockDataOnly(Collection coverageData) { coverageData); } - void addTestToClasses(TestInfo ti, Collection coverage) { - for (BlockLocation each : coverage) { - ClassName clazz = each.getLocation().getClassName(); - Map> linesToTests = lineCoverage.getOrDefault(clazz, new LinkedHashMap<>(0)); - for (int line : getLinesForBlock(each)) { - addTestToClassLine(each.getLocation().getClassName(), linesToTests, ti, line); - } - // can we get blocks from different classes? - this.lineCoverage.put(each.getLocation().getClassName(), linesToTests); - } - } - private void addTestToClassLine(ClassName clazz, - Map> linesToTests, - TestInfo test, - int line) { - ClassLine cl = new ClassLine(clazz, line); - Set tis = linesToTests.getOrDefault(cl, new TreeSet<>(new TestInfoNameComparator())); - tis.add(test); - linesToTests.put(cl, tis); - } - @Override public Collection getClassInfo(final Collection classes) { return this.code.getClassInfo(classes); @@ -97,6 +76,34 @@ public Collection getClassesForFile(final String sourceFile, } } + public Collection getTestsForClass(ClassName clazz) { + return this.lineCoverage.getOrDefault(clazz, Collections.emptyMap()).values().stream() + .flatMap(s -> s.stream()) + .collect(Collectors.toSet()); + } + + void addTestToClasses(TestInfo ti, Collection coverage) { + for (BlockLocation each : coverage) { + ClassName clazz = each.getLocation().getClassName(); + Map> linesToTests = lineCoverage.getOrDefault(clazz, new LinkedHashMap<>(0)); + for (int line : getLinesForBlock(each)) { + addTestToClassLine(each.getLocation().getClassName(), linesToTests, ti, line); + } + // can we get blocks from different classes? + this.lineCoverage.put(each.getLocation().getClassName(), linesToTests); + } + } + private void addTestToClassLine(ClassName clazz, + Map> linesToTests, + TestInfo test, + int line) { + ClassLine cl = new ClassLine(clazz, line); + Set tis = linesToTests.getOrDefault(cl, new TreeSet<>(new TestInfoNameComparator())); + tis.add(test); + linesToTests.put(cl, tis); + } + + private Map> getLineCoverageForClassName(final ClassName clazz) { return this.lineCoverage.getOrDefault(clazz, Collections.emptyMap()); } @@ -129,9 +136,4 @@ private void calculateLinesForBlocks(ClassName className) { this.blocksToLines.putAll(lines); } - public Collection getTestsForClass(ClassName clazz) { - return this.lineCoverage.getOrDefault(clazz, Collections.emptyMap()).values().stream() - .flatMap(s -> s.stream()) - .collect(Collectors.toSet()); - } }