Skip to content

Commit

Permalink
feat: add merge api to merge two coverage together (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
danglotb authored Oct 7, 2021
1 parent ee2e633 commit 5597805
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ public int getHitCountForLine(int line) {
.filter(coverage -> coverage.line == line)
.findFirst()
.orElse(new LineCoverage(0, 0))
.hitCount;
.getHitCount();
}

public void merge(ClassCoverage that) {
for (LineCoverage coverage : that.coverages) {
this.coverages.stream()
.filter(lineCoverage -> lineCoverage.line == coverage.line)
.findFirst()
.orElse(coverage)
.merge(coverage);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public Map<String, Integer> getHitCountFromClassNameForLineForAll(String classNa
return allHitCountFromClassNameForLine;
}

public void merge(Coverage that) {
for (String testClass : that.testClassCoverage.keySet()) {
if (!this.testClassCoverage.containsKey(testClass)) {
this.testClassCoverage.put(testClass, that.testClassCoverage.get(testClass));
} else {
this.testClassCoverage.get(testClass).merge(that.testClassCoverage.get(testClass));
}
}
}

@Override
public String toString() {
return "Coverage{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ public class LineCoverage {

public final int line;

public final int hitCount;
private int hitCount;

public LineCoverage(int line, int hitCount) {
this.line = line;
this.hitCount = hitCount;
}

public int getHitCount() {
return this.hitCount;
}

public void merge(LineCoverage that) {
this.hitCount += that.hitCount;
}

@Override
public String toString() {
return "LineCoverage{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public Map<String, Integer> getHitCountFromClassNameForLineForAll(String classNa
return hitCountForLinePerTestMethodName;
}

public void merge(TestClassCoverage that) {
for (String testMethodName : that.testMethodsCoverage.keySet()) {
if (!this.testMethodsCoverage.containsKey(testMethodName)) {
this.testMethodsCoverage.put(testMethodName, that.testMethodsCoverage.get(testMethodName));
} else {
this.testMethodsCoverage.get(testMethodName).merge(that.testMethodsCoverage.get(testMethodName));
}
}
}

@Override
public String toString() {
return "TestClassCoverage{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public int getHitCountFromClassNameForLine(String className, int line) {
}
}

public void merge(TestMethodCoverage that) {
for (String className : that.classCoverageList.keySet()) {
if (!this.classCoverageList.containsKey(className)) {
this.classCoverageList.put(className, that.classCoverageList.get(className));
} else {
this.classCoverageList.get(className).merge(that.classCoverageList.get(className));
}
}
}

@Override
public String toString() {
return "TestMethodCoverage{" +
Expand Down

0 comments on commit 5597805

Please sign in to comment.