Skip to content

Commit

Permalink
reposition public members
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Apr 29, 2021
1 parent e0f4b9e commit 7807743
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstructionLocation, Set<TestInfo>> instructionCoverage = new LinkedHashMap<>();
private final Map<InstructionLocation, Set<TestInfo>> instructionCoverage = new LinkedHashMap<>();
private final LegacyClassCoverage legacyClassCoverage;

private final CodeSource code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,6 @@ public void loadBlockDataOnly(Collection<BlockLocation> coverageData) {
coverageData);
}

void addTestToClasses(TestInfo ti, Collection<BlockLocation> coverage) {
for (BlockLocation each : coverage) {
ClassName clazz = each.getLocation().getClassName();
Map<ClassLine, Set<TestInfo>> 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<ClassLine, Set<TestInfo>> linesToTests,
TestInfo test,
int line) {
ClassLine cl = new ClassLine(clazz, line);
Set<TestInfo> tis = linesToTests.getOrDefault(cl, new TreeSet<>(new TestInfoNameComparator()));
tis.add(test);
linesToTests.put(cl, tis);
}

@Override
public Collection<ClassInfo> getClassInfo(final Collection<ClassName> classes) {
return this.code.getClassInfo(classes);
Expand Down Expand Up @@ -97,6 +76,34 @@ public Collection<ClassInfo> getClassesForFile(final String sourceFile,
}
}

public Collection<TestInfo> getTestsForClass(ClassName clazz) {
return this.lineCoverage.getOrDefault(clazz, Collections.emptyMap()).values().stream()
.flatMap(s -> s.stream())
.collect(Collectors.toSet());
}

void addTestToClasses(TestInfo ti, Collection<BlockLocation> coverage) {
for (BlockLocation each : coverage) {
ClassName clazz = each.getLocation().getClassName();
Map<ClassLine, Set<TestInfo>> 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<ClassLine, Set<TestInfo>> linesToTests,
TestInfo test,
int line) {
ClassLine cl = new ClassLine(clazz, line);
Set<TestInfo> tis = linesToTests.getOrDefault(cl, new TreeSet<>(new TestInfoNameComparator()));
tis.add(test);
linesToTests.put(cl, tis);
}


private Map<ClassLine, Set<TestInfo>> getLineCoverageForClassName(final ClassName clazz) {
return this.lineCoverage.getOrDefault(clazz, Collections.emptyMap());
}
Expand Down Expand Up @@ -129,9 +136,4 @@ private void calculateLinesForBlocks(ClassName className) {
this.blocksToLines.putAll(lines);
}

public Collection<TestInfo> getTestsForClass(ClassName clazz) {
return this.lineCoverage.getOrDefault(clazz, Collections.emptyMap()).values().stream()
.flatMap(s -> s.stream())
.collect(Collectors.toSet());
}
}

0 comments on commit 7807743

Please sign in to comment.