Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge all values of the hierarchy using max #27

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/main/java/edu/hm/hafner/coverage/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,14 @@
private void mergeValues(final Value otherValue) {
if (getMetricsOfValues().anyMatch(v -> v.equals(otherValue.getMetric()))) {
var old = getValueOf(otherValue.getMetric());
if (hasChildren()) {
replaceValue(old.add(otherValue));
try {
var max = old.max(otherValue);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this functionality it's still a replace right? It just takes the coverage that's higer.
If there is a file with the functions a and b, coverage X covers func a and coverage Y covers function b, it's 50% overall coverage instead of 100% right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still not clear on how to merge inner nodes 😞

The code works for leaves but not for inner nodes yet. I can drop the details of inner nodes and compute them on my own but that will cause other problems...

Do you have an idea on how to implement this correctly? I do not see a solution for this problem.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much experience with coverage reports, but by just looking at the cobertura one, I would expect that the lines should be merged (identified by number and branch) and hits > 0 should be preferred

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After adding some more tests it looks that the merge using max is working correctly.

With this functionality it's still a replace right? It just takes the coverage that's higer.
If there is a file with the functions a and b, coverage X covers func a and coverage Y covers function b, it's 50% overall coverage instead of 100% right?

No, since each file has a coverage for X and Y. So X contains a=100% and b=0%, and Y contains a=0% and b=100%, then the max will produce a=100% and b=100%.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's more correct than before.
Lets say we have function A.

function A(flag: boolean) {
  if(flag) {
    console.log('true');
  } else {
   console.log('false');
  }
}

If you have two separate coverage reports, one with the file x.spec.test that tests A only with true and one with the file y.spec.test that tests A only with false, then both of them would have the same coverage (about 50%) and the code-coverage-api would return 50% right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's more correct than before. Lets say we have function A.

function A(flag: boolean) {
  if(flag) {
    console.log('true');
  } else {
   console.log('false');
  }
}

If you have two separate coverage reports, one with the file x.spec.test that tests A only with true and one with the file y.spec.test that tests A only with false, then both of them would have the same coverage (about 50%) and the code-coverage-api would return 50% right?

No, the coverage is not measured per method, it is line based. The coverage per method is computed from the line coverage. So you should get a 100% coverage in total.


replaceValue(max);
}
else {
replaceValue(old.max(otherValue));
catch (AssertionError exception) {
throw new IllegalStateException(String.format("Cannot merge coverage of %s because of: %s",
this, exception.getMessage()), exception);
}
}
}
Expand All @@ -676,7 +679,10 @@

@Override
public String toString() {
return String.format("[%s] %s <%d>", getMetric(), getName(), children.size());
return getValue(Metric.LINE)
.map(lineCoverage -> String.format("[%s] %s <%d, %s>",

Check warning on line 683 in src/main/java/edu/hm/hafner/coverage/Node.java

View check run for this annotation

ci.jenkins.io / Mutation Coverage

Not covered line

Line 683 is not covered by tests
getMetric(), getName(), getChildren().size(), lineCoverage))

Check warning on line 684 in src/main/java/edu/hm/hafner/coverage/Node.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 684 is not covered by tests

Check warning on line 684 in src/main/java/edu/hm/hafner/coverage/Node.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/edu/hm/hafner/coverage/Node.java#L684

Added line #L684 was not covered by tests
.orElse(String.format("[%s] %s <%d>", getMetric(), getName(), children.size()));
}

public boolean isEmpty() {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/edu/hm/hafner/coverage/PackageNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,4 @@ public ClassNode createClassNode(final String className) {
addChild(classNode);
return classNode;
}

@Override
public String toString() {
return String.format("[%s] %s <%d>", getMetric(), getName(), getChildren().size());
}
}
35 changes: 0 additions & 35 deletions src/test/java/edu/hm/hafner/coverage/ModuleNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.junit.jupiter.api.Test;

import edu.hm.hafner.coverage.Coverage.CoverageBuilder;

import static edu.hm.hafner.coverage.Metric.FILE;
import static edu.hm.hafner.coverage.Metric.*;
import static edu.hm.hafner.coverage.assertions.Assertions.*;
Expand Down Expand Up @@ -66,39 +64,6 @@ void shouldSplitPackagesIntoHierarchy() {
);
}

@Test
void shouldDetectExistingPackagesOnSplit() {
var root = new ModuleNode("Root");
Node eduPackage = new PackageNode("edu");
Node differentPackage = new PackageNode("org");

root.addChild(differentPackage);
root.addChild(eduPackage);

eduPackage.addChild(new FileNode("File.c", "edu/File.c"));

var builder = new CoverageBuilder().setMetric(LINE);
eduPackage.addValue(builder.setCovered(10).setMissed(0).build());

assertThat(root.getAll(PACKAGE)).hasSize(2);
assertThat(root.getValue(LINE)).contains(builder.build());

var subPackage = new PackageNode("edu.hm.hafner");
root.addChild(subPackage);
subPackage.addValue(builder.setMissed(10).build());
subPackage.addChild(new FileNode("OtherFile.c", "edu.hm.hafner/OtherFile.c"));
assertThat(root.getValue(LINE)).contains(builder.setCovered(20).setMissed(10).build());

root.splitPackages();
assertThat(root.getAll(PACKAGE)).hasSize(4);

assertThat(root.getChildren()).hasSize(2).satisfiesExactlyInAnyOrder(
org -> assertThat(org.getName()).isEqualTo("org"),
edu -> assertThat(edu.getName()).isEqualTo("edu"));

assertThat(root.getValue(LINE)).contains(builder.setCovered(20).setMissed(10).build());
}

@Test
void shouldKeepNodesAfterSplitting() {
var root = new ModuleNode("Root");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/edu/hm/hafner/coverage/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void shouldThrowErrorIfCoveredPlusMissedLinesDifferInReports() {

method.addValue(new CoverageBuilder().setMetric(LINE).setCovered(5).setMissed(5).build());
methodOtherCov.addValue(new CoverageBuilder().setMetric(LINE).setCovered(2).setMissed(7).build());
assertThatExceptionOfType(AssertionError.class)
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> module.merge(sameProject))
.withMessageContaining("Cannot compute maximum of coverages", "(5/10)", "(2/9)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,55 @@
return new CoberturaParser();
}

@Test
void shouldMergeCorrectly729() {
var builder = new CoverageBuilder();

Node a = readReport("cobertura-merge-a.xml");
assertThat(a.aggregateValues()).containsExactly(
builder.setMetric(MODULE).setCovered(1).setMissed(0).build(),
builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(),
builder.setMetric(FILE).setCovered(1).setMissed(0).build(),

Check warning on line 39 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(),</code></pre>
builder.setMetric(CLASS).setCovered(1).setMissed(0).build(),
builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),

Check warning on line 41 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),</code></pre>
builder.setMetric(LINE).setCovered(20).setMissed(0).build(),
builder.setMetric(BRANCH).setCovered(2).setMissed(1).build(),
new LinesOfCode(20));

Check warning on line 44 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(), builder.setMetric(LINE).setCovered(20).setMissed(0).build(), builder.setMetric(BRANCH).setCovered(2).setMissed(1).build(), new LinesOfCode(20));</code></pre>

Node b = readReport("cobertura-merge-b.xml");
assertThat(b.aggregateValues()).containsExactly(
builder.setMetric(MODULE).setCovered(1).setMissed(0).build(),
builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(),
builder.setMetric(FILE).setCovered(1).setMissed(0).build(),

Check warning on line 50 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(),</code></pre>
builder.setMetric(CLASS).setCovered(1).setMissed(0).build(),
builder.setMetric(METHOD).setCovered(1).setMissed(2).build(),

Check warning on line 52 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(b.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(1).setMissed(2).build(),</code></pre>

Check warning on line 52 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),</code></pre>
builder.setMetric(LINE).setCovered(16).setMissed(4).build(),
builder.setMetric(BRANCH).setCovered(0).setMissed(3).build(),
new LinesOfCode(20));

var left = a.merge(b);
var right = b.merge(a);

assertThat(left.aggregateValues()).containsExactly(
builder.setMetric(MODULE).setCovered(1).setMissed(0).build(),
builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(),
builder.setMetric(FILE).setCovered(1).setMissed(0).build(),

Check warning on line 63 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(),</code></pre>
builder.setMetric(CLASS).setCovered(1).setMissed(0).build(),
builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),

Check warning on line 65 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),</code></pre>
builder.setMetric(LINE).setCovered(20).setMissed(0).build(),
builder.setMetric(BRANCH).setCovered(2).setMissed(1).build(),
new LinesOfCode(20));

Check warning on line 68 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(), builder.setMetric(LINE).setCovered(20).setMissed(0).build(), builder.setMetric(BRANCH).setCovered(2).setMissed(1).build(), new LinesOfCode(20));</code></pre>
assertThat(right.aggregateValues()).containsExactly(
builder.setMetric(MODULE).setCovered(1).setMissed(0).build(),
builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(),
builder.setMetric(FILE).setCovered(1).setMissed(0).build(),

Check warning on line 72 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(),</code></pre>
builder.setMetric(CLASS).setCovered(1).setMissed(0).build(),
builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),

Check warning on line 74 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),</code></pre>
builder.setMetric(LINE).setCovered(20).setMissed(0).build(),
builder.setMetric(BRANCH).setCovered(2).setMissed(1).build(),
new LinesOfCode(20));

Check warning on line 77 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(), builder.setMetric(LINE).setCovered(20).setMissed(0).build(), builder.setMetric(BRANCH).setCovered(2).setMissed(1).build(), new LinesOfCode(20));</code></pre>
}

@Test
void shouldCountCorrectly625() {
Node tree = readReport("cobertura-counter-aggregation.xml");
Expand Down Expand Up @@ -91,12 +140,15 @@
var builder = new CoverageBuilder();

assertThat(tree).hasOnlyMetrics(MODULE, PACKAGE, FILE, CLASS, METHOD, LINE, BRANCH, LOC);
assertThat(tree.aggregateValues()).containsAnyOf(
assertThat(tree.aggregateValues()).containsExactly(
builder.setMetric(MODULE).setCovered(1).setMissed(0).build(),
builder.setMetric(PACKAGE).setCovered(4).setMissed(3).build(),
builder.setMetric(FILE).setCovered(6).setMissed(12).build(),
builder.setMetric(CLASS).setCovered(6).setMissed(12).build(),
builder.setMetric(METHOD).setCovered(4).setMissed(1).build());
builder.setMetric(FILE).setCovered(6).setMissed(6).build(),
builder.setMetric(CLASS).setCovered(6).setMissed(6).build(),
builder.setMetric(METHOD).setCovered(14).setMissed(24).build(),
builder.setMetric(LINE).setCovered(52).setMissed(85).build(),
builder.setMetric(BRANCH).setCovered(21).setMissed(11).build(),
new LinesOfCode(137));

assertThat(tree.findPackage("libs.env.src")).isNotEmpty().get().satisfies(
p -> {
Expand Down Expand Up @@ -167,10 +219,10 @@

assertThat(tree).hasOnlyMetrics(MODULE, PACKAGE, FILE, CLASS, METHOD, LINE, BRANCH, COMPLEXITY,
COMPLEXITY_DENSITY, COMPLEXITY_MAXIMUM, LOC);
assertThat(tree.aggregateValues()).containsExactly(
builder.setMetric(MODULE).setCovered(1).setMissed(0).build(),
builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(),
builder.setMetric(FILE).setCovered(1).setMissed(0).build(),

Check warning on line 225 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(),</code></pre>
builder.setMetric(CLASS).setCovered(1).setMissed(0).build(),
builder.setMetric(METHOD).setCovered(1).setMissed(0).build(),

Check warning on line 227 in src/test/java/edu/hm/hafner/coverage/parser/CoberturaParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(a.aggregateValues()).containsExactly( builder.setMetric(MODULE).setCovered(1).setMissed(0).build(), builder.setMetric(PACKAGE).setCovered(1).setMissed(0).build(), builder.setMetric(FILE).setCovered(1).setMissed(0).build(), builder.setMetric(CLASS).setCovered(1).setMissed(0).build(), builder.setMetric(METHOD).setCovered(3).setMissed(0).build(),</code></pre>
builder.setMetric(LINE).setCovered(9).setMissed(0).build(),
Expand Down
70 changes: 70 additions & 0 deletions src/test/java/edu/hm/hafner/coverage/parser/JacocoParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.NoSuchElementException;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -37,6 +38,75 @@ private static Coverage getCoverage(final Node node, final Metric metric) {
return (Coverage) node.getValue(metric).get();
}

@ParameterizedTest(name = "[{index}] Split packages after read: {0}")
@ValueSource(booleans = {true, false})
@DisplayName("Read and merge two coverage reports with different packages")
void shouldMergeProjects(final boolean splitPackages) {
ModuleNode model = readReport("jacoco-analysis-model.xml");

assertThat(model.getAll(PACKAGE)).extracting(Node::getName).containsExactly(
"edu.hm.hafner.analysis.parser.dry.simian",
"edu.hm.hafner.analysis.parser.gendarme",
"edu.hm.hafner.analysis.parser.dry",
"edu.hm.hafner.analysis.parser.checkstyle",
"edu.hm.hafner.analysis.registry",
"edu.hm.hafner.analysis.parser.findbugs",
"edu.hm.hafner.analysis.parser.pmd",
"edu.hm.hafner.analysis",
"edu.hm.hafner.analysis.parser.fxcop",
"edu.hm.hafner.analysis.parser.dry.dupfinder",
"edu.hm.hafner.analysis.parser.jcreport",
"edu.hm.hafner.analysis.parser.pylint",
"edu.hm.hafner.analysis.parser.pvsstudio",
"edu.hm.hafner.analysis.parser.dry.cpd",
"edu.hm.hafner.util",
"edu.hm.hafner.analysis.parser",
"edu.hm.hafner.analysis.parser.ccm",
"edu.hm.hafner.analysis.parser.violations");

ModuleNode style = readReport("jacoco-codingstyle.xml");

assertThat(style.getAll(PACKAGE)).extracting(Node::getName).containsExactly(
"edu.hm.hafner.util");

var builder = new CoverageBuilder().setMetric(LINE);

var left = new ModuleNode("root");
model.getAll(PACKAGE).forEach(p -> left.addChild(p.copyTree()));

assertThat(left.find(PACKAGE, "edu.hm.hafner.util")).isPresent()
.get().satisfies(p -> assertThat(p.getValue(LINE)).contains(
builder.setCovered(60).setTotal(62).build()));

var right = new ModuleNode("root");
style.getAll(PACKAGE).forEach(p -> right.addChild(p.copyTree()));

assertThat(right.find(PACKAGE, "edu.hm.hafner.util")).isPresent()
.get().satisfies(p -> assertThat(p.getValue(LINE)).contains(
builder.setCovered(294).setTotal(323).build()));

if (splitPackages) {
left.splitPackages();
right.splitPackages();
}

var merged = left.merge(right);

var packageName = splitPackages ? "util" : "edu.hm.hafner.util";
assertThat(merged.find(PACKAGE, packageName)).isPresent()
.get().satisfies(p -> assertThat(p.getValue(LINE)).contains(
builder.setCovered(294 + 60).setTotal(323 + 62).build()));
}

@Test
void shouldReadAndSplitSubpackage() {
ModuleNode model = readReport("file-subpackage.xml");

model.splitPackages();
assertThat(model.getAll(PACKAGE)).extracting(Node::getName).containsExactly(
"util", "hafner", "hm", "edu");
}

@Test
void shouldReadAggregationWithGroups() {
ModuleNode jenkinsRoot = readReport("jacoco-jenkins.xml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="4161" lines-covered="3788" line-rate="0.9103" branches-valid="1243" branches-covered="1032" branch-rate="0.8301999999999999" timestamp="1689142471140" complexity="0" version="0.1">
<sources>
<source>${MY_DIRECTORY_PLACEHOLDER}</source>
</sources>
<packages>
<package name="src.app.utils" line-rate="0.9923000000000001" branch-rate="0.9516">
<classes>
<class name="dateUtils.ts" filename="src\app\utils\dateUtils.ts" line-rate="1" branch-rate="0.6666">
<methods>
<method name="getTimeAgo" hits="43" signature="()V">
<lines>
<line number="35" hits="43"/>
</lines>
</method>
<method name="(anonymous_1)" hits="31" signature="()V">
<lines>
<line number="40" hits="31"/>
</lines>
</method>
<method name="isValidDate" hits="84" signature="()V">
<lines>
<line number="71" hits="84"/>
</lines>
</method>
</methods>
<lines>
<line number="1" hits="23" branch="false"/>
<line number="5" hits="23" branch="false"/>
<line number="6" hits="23" branch="false"/>
<line number="7" hits="23" branch="false"/>
<line number="8" hits="23" branch="false"/>
<line number="9" hits="23" branch="false"/>
<line number="10" hits="23" branch="false"/>
<line number="11" hits="23" branch="false"/>
<line number="20" hits="23" branch="false"/>
<line number="35" hits="23" branch="false"/>
<line number="36" hits="43" branch="false"/>
<line number="37" hits="43" branch="true" condition-coverage="100% (1/1)"/>
<line number="38" hits="34" branch="false"/>
<line number="40" hits="31" branch="true" condition-coverage="50% (1/2)"/>
<line number="41" hits="9" branch="false"/>
<line number="42" hits="9" branch="false"/>
<line number="45" hits="23" branch="false"/>
<line number="54" hits="23" branch="false"/>
<line number="60" hits="23" branch="false"/>
<line number="66" hits="23" branch="false"/>
<line number="71" hits="23" branch="false"/>
<line number="72" hits="84" branch="false"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="544" lines-covered="487" line-rate="0.8952" branches-valid="164" branches-covered="130" branch-rate="0.7926000000000001" timestamp="1689142282020" complexity="0" version="0.1">
<sources>
<source>${MY_DIRECTORY_PLACEHOLDER}</source>
</sources>
<packages>
<package name="src.app.utils" line-rate="0.8378" branch-rate="0">
<classes>
<class name="dateUtils.ts" filename="src\app\utils\dateUtils.ts" line-rate="0.7272" branch-rate="0">
<methods>
<method name="getTimeAgo" hits="0" signature="()V">
<lines>
<line number="35" hits="0"/>
</lines>
</method>
<method name="(anonymous_1)" hits="0" signature="()V">
<lines>
<line number="40" hits="0"/>
</lines>
</method>
<method name="isValidDate" hits="1070" signature="()V">
<lines>
<line number="71" hits="1070"/>
</lines>
</method>
</methods>
<lines>
<line number="1" hits="1" branch="false"/>
<line number="5" hits="1" branch="false"/>
<line number="6" hits="1" branch="false"/>
<line number="7" hits="1" branch="false"/>
<line number="8" hits="1" branch="false"/>
<line number="9" hits="1" branch="false"/>
<line number="10" hits="1" branch="false"/>
<line number="11" hits="1" branch="false"/>
<line number="20" hits="1" branch="false"/>
<line number="35" hits="1" branch="false"/>
<line number="36" hits="0" branch="false"/>
<line number="37" hits="0" branch="true" condition-coverage="0% (0/1)"/>
<line number="38" hits="0" branch="false"/>
<line number="40" hits="0" branch="true" condition-coverage="0% (0/2)"/>
<line number="41" hits="0" branch="false"/>
<line number="42" hits="0" branch="false"/>
<line number="45" hits="1" branch="false"/>
<line number="54" hits="1" branch="false"/>
<line number="60" hits="1" branch="false"/>
<line number="66" hits="1" branch="false"/>
<line number="71" hits="1" branch="false"/>
<line number="72" hits="1070" branch="false"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
Loading