Skip to content

Commit

Permalink
Merge pull request #119 from maxwai/feat/metrics-report
Browse files Browse the repository at this point in the history
Added PMD Metrics Parser
  • Loading branch information
uhafner authored Sep 17, 2024
2 parents 8e2431a + 8626bcf commit a00b4e0
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ This library consists basically of two separate parts:
* [JUnit](https://junit.org/junit5/) test results
* [NUnit](https://nunit.org) test results
* [XUnit](https://xunit.net) test results
* Metrics XML report

All source code is licensed under the MIT license. Contributions to this library are welcome!
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CyclomaticComplexity(final int complexity, final Metric metric) {
}

@Override
protected IntegerValue create(final int value) {
return new CyclomaticComplexity(value);
protected IntegerValue create(final int value, final Metric metric) {
return new CyclomaticComplexity(value, metric);
}
}
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/coverage/IntegerValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public int getValue() {

@Override
public IntegerValue add(final Value other) {
return castAndMap(other, o -> create(integer + o.getValue()));
return castAndMap(other, o -> create(integer + o.getValue(), o.getMetric()));
}

protected abstract IntegerValue create(int value);
protected abstract IntegerValue create(int value, Metric metric);

@Override
public IntegerValue max(final Value other) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/coverage/LinesOfCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LinesOfCode(final int loc) {
}

@Override
protected IntegerValue create(final int value) {
protected IntegerValue create(final int value, final Metric ignored) {
return new LinesOfCode(value);
}
}
5 changes: 4 additions & 1 deletion src/main/java/edu/hm/hafner/coverage/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public enum Metric {
COMPLEXITY_MAXIMUM(new MethodMaxComplexityFinder(), MetricTendency.SMALLER_IS_BETTER),
COMPLEXITY_DENSITY(new DensityEvaluator(), MetricTendency.SMALLER_IS_BETTER),
LOC(new LocEvaluator(), MetricTendency.SMALLER_IS_BETTER),
TESTS(new ValuesAggregator(), MetricTendency.LARGER_IS_BETTER);
TESTS(new ValuesAggregator(), MetricTendency.LARGER_IS_BETTER),
NCSS(new ValuesAggregator(), MetricTendency.SMALLER_IS_BETTER),
COGNITIVE_COMPLEXITY(new ValuesAggregator(), MetricTendency.SMALLER_IS_BETTER),
NPATH_COMPLEXITY(new ValuesAggregator(), MetricTendency.SMALLER_IS_BETTER);

/**
* Returns the metric that belongs to the specified tag.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/coverage/TestCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TestCount(final int tests) {
}

@Override
protected IntegerValue create(final int value) {
protected IntegerValue create(final int value, final Metric ignored) {
return new TestCount(value);
}
}
6 changes: 6 additions & 0 deletions src/main/java/edu/hm/hafner/coverage/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public static Value valueOf(final String stringRepresentation) {
return new LinesOfCode(Integer.parseInt(value));
case TESTS:
return new TestCount(Integer.parseInt(value));
case NCSS:
return new CyclomaticComplexity(Integer.parseInt(value), Metric.NCSS);
case NPATH_COMPLEXITY:
return new CyclomaticComplexity(Integer.parseInt(value), Metric.NPATH_COMPLEXITY);
case COGNITIVE_COMPLEXITY:
return new CyclomaticComplexity(Integer.parseInt(value), Metric.COGNITIVE_COMPLEXITY);
}
}
}
Expand Down
254 changes: 254 additions & 0 deletions src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
package edu.hm.hafner.coverage.parser;

import java.io.Reader;
import java.nio.file.Paths;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

import com.google.errorprone.annotations.CanIgnoreReturnValue;

import edu.hm.hafner.coverage.ClassNode;
import edu.hm.hafner.coverage.CoverageParser;
import edu.hm.hafner.coverage.CyclomaticComplexity;
import edu.hm.hafner.coverage.FileNode;
import edu.hm.hafner.coverage.MethodNode;
import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.ModuleNode;
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.coverage.PackageNode;
import edu.hm.hafner.util.FilteredLog;
import edu.hm.hafner.util.PathUtil;
import edu.hm.hafner.util.SecureXmlParserFactory;
import edu.hm.hafner.util.TreeString;

/**
* Parses Metrics reports into a hierarchical Java Object Model.
*
* @author Maximilian Waidelich
*/
@SuppressWarnings("PMD.GodClass")
public class MetricsParser extends CoverageParser {
private static final long serialVersionUID = -4461747681863455621L;

/** XML elements. */
private static final QName METRICS = new QName("metrics");
private static final QName PACKAGE = new QName("package");
private static final QName CLASS = new QName("class");
private static final QName METHOD = new QName("method");
private static final QName METRIC = new QName("metric");
private static final QName FILE = new QName("file");

/** Attributes of the XML elements. */
private static final QName PROJECT_NAME = new QName("projectName");
private static final QName NAME = new QName("name");
private static final QName BEGIN_LINE = new QName("beginline");
private static final QName VALUE = new QName("value");

private static final String CYCLOMATIC_COMPLEXITY = "CyclomaticComplexity";
private static final String COGNITIVE_COMPLEXITY = "CognitiveComplexity";
private static final String NCSS = "NCSS";
private static final String NPATH_COMPLEXITY = "NPathComplexity";

private static final PathUtil PATH_UTIL = new PathUtil();

/**
* Creates a new instance of {@link MetricsParser}.
*/
public MetricsParser() {
this(ProcessingMode.FAIL_FAST);
}

Check warning on line 62 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered lines

Lines 61-62 are not covered by tests

Check warning on line 62 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 61-62 are not covered by tests

/**
* Creates a new instance of {@link MetricsParser}.
*
* @param processingMode
* determines whether to ignore errors
*/
public MetricsParser(final ProcessingMode processingMode) {
super(processingMode);
}

@Override
protected ModuleNode parseReport(final Reader reader, final String fileName, final FilteredLog log) {
try {
var factory = new SecureXmlParserFactory();
var eventReader = factory.createXmlEventReader(reader);

ModuleNode root = new ModuleNode("");

while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();

if (event.isStartElement()) {
var startElement = event.asStartElement();
var tagName = startElement.getName();
if (METRICS.equals(tagName)) {

Check warning on line 88 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
root = new ModuleNode(getOptionalValueOf(startElement, PROJECT_NAME).orElse(""));
}
else if (PACKAGE.equals(tagName)) {

Check warning on line 91 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
readPackage(eventReader, root, startElement, fileName);
}
}
}
if (root.hasChildren()) {
return root;
}
else {
handleEmptyResults(fileName, log);
return new ModuleNode("empty");
}
}
catch (XMLStreamException exception) {
throw new ParsingException(exception);
}
}

@CanIgnoreReturnValue
private PackageNode readPackage(final XMLEventReader reader, final ModuleNode root,
final StartElement startElement, final String fileName) throws XMLStreamException {
var packageName = getValueOf(startElement, NAME);
var packageNode = root.findOrCreatePackageNode(packageName);
while (reader.hasNext()) {

Check warning on line 114 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 114 is only partially covered, one branch is missing

Check warning on line 114 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 114 is only partially covered, one branch is missing
XMLEvent event = reader.nextEvent();

if (event.isStartElement()) {
var nextElement = event.asStartElement();
if (FILE.equals(nextElement.getName())) {

Check warning on line 119 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
readSourceFile(reader, packageNode, nextElement, fileName);
}
else if (METRIC.equals(nextElement.getName())) {

Check warning on line 122 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.

Check warning on line 122 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 122 is only partially covered, one branch is missing

Check warning on line 122 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 122 is only partially covered, one branch is missing
readValueCounter(packageNode, nextElement);
}
}
else if (event.isEndElement()) {
var endElement = event.asEndElement();
if (PACKAGE.equals(endElement.getName())) {

Check warning on line 128 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.

Check warning on line 128 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 128 (NegateConditionalsMutator)
Raw output
Survived mutations:
- negated conditional (org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator)
return packageNode;

Check warning on line 129 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 129 (NullReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with null for edu/hm/hafner/coverage/parser/MetricsParser::readPackage (org.pitest.mutationtest.engine.gregor.mutators.returns.NullReturnValsMutator)
}
}
}
throw createEofException(fileName);

Check warning on line 133 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 133 is not covered by tests

Check warning on line 133 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 133 is not covered by tests
}

@CanIgnoreReturnValue
private Node readClass(final XMLEventReader reader, final FileNode fileNode, final StartElement startElement,
final String fileName, final PackageNode packageNode) throws XMLStreamException {
ClassNode classNode = fileNode.findOrCreateClassNode(packageNode.getName() + "." + getValueOf(startElement, NAME));
while (reader.hasNext()) {

Check warning on line 140 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 140 is only partially covered, one branch is missing

Check warning on line 140 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 140 is only partially covered, one branch is missing
XMLEvent event = reader.nextEvent();

if (event.isStartElement()) {
var nextElement = event.asStartElement();
if (METHOD.equals(nextElement.getName())) {

Check warning on line 145 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
readMethod(reader, classNode, nextElement, fileName);
}
else if (METRIC.equals(nextElement.getName())) {

Check warning on line 148 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.

Check warning on line 148 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 148 is only partially covered, one branch is missing

Check warning on line 148 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 148 is only partially covered, one branch is missing
readValueCounter(classNode, nextElement);
}
}
else if (event.isEndElement()) {
var endElement = event.asEndElement();
if (CLASS.equals(endElement.getName())) {

Check warning on line 154 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
return classNode;

Check warning on line 155 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 155 (NullReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with null for edu/hm/hafner/coverage/parser/MetricsParser::readClass (org.pitest.mutationtest.engine.gregor.mutators.returns.NullReturnValsMutator)
}
}
}
throw createEofException(fileName);

Check warning on line 159 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 159 is not covered by tests

Check warning on line 159 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 159 is not covered by tests
}

private TreeString internPath(final String filePath) {
return getTreeStringBuilder().intern(PATH_UTIL.getRelativePath(Paths.get(filePath)));
}

@CanIgnoreReturnValue
private Node readSourceFile(final XMLEventReader reader, final PackageNode packageNode,
final StartElement startElement, final String fileName)
throws XMLStreamException {
String sourceFileName = getSourceFileName(startElement);
var fileNode = packageNode.findOrCreateFileNode(sourceFileName,
internPath(getValueOf(startElement, NAME)));

while (reader.hasNext()) {

Check warning on line 174 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 174 is only partially covered, one branch is missing

Check warning on line 174 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 174 is only partially covered, one branch is missing
XMLEvent event = reader.nextEvent();

if (event.isStartElement()) {
var nextElement = event.asStartElement();
if (CLASS.equals(nextElement.getName())) {

Check warning on line 179 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
readClass(reader, fileNode, nextElement, fileName, packageNode);
}
else if (METRIC.equals(nextElement.getName())) {

Check warning on line 182 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.

Check warning on line 182 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 182 is only partially covered, one branch is missing

Check warning on line 182 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 182 is only partially covered, one branch is missing
readValueCounter(fileNode, nextElement);
}
}
else if (event.isEndElement()) {
var endElement = event.asEndElement();
if (FILE.equals(endElement.getName())) {

Check warning on line 188 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
return fileNode;

Check warning on line 189 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 189 (NullReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with null for edu/hm/hafner/coverage/parser/MetricsParser::readSourceFile (org.pitest.mutationtest.engine.gregor.mutators.returns.NullReturnValsMutator)
}
}
}
throw createEofException(fileName);

Check warning on line 193 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 193 is not covered by tests

Check warning on line 193 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 193 is not covered by tests
}

private String getSourceFileName(final StartElement startSourceFileElement) {
var sourceFilePath = Paths.get(getValueOf(startSourceFileElement, NAME)).getFileName();
if (sourceFilePath == null) {

Check warning on line 198 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 198 is only partially covered, one branch is missing

Check warning on line 198 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 198 is only partially covered, one branch is missing
return getValueOf(startSourceFileElement, NAME);

Check warning on line 199 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 199 is not covered by tests

Check warning on line 199 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 199 is not covered by tests

Check warning on line 199 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 199 is not covered by tests
}
else {
return sourceFilePath.toString();
}
}

@CanIgnoreReturnValue
private Node readMethod(final XMLEventReader reader, final ClassNode classNode,
final StartElement startElement, final String fileName) throws XMLStreamException {
String methodName = getValueOf(startElement, NAME) + "#" + getValueOf(startElement, BEGIN_LINE);

MethodNode methodNode = createMethod(startElement, methodName);
classNode.addChild(methodNode);

while (reader.hasNext()) {

Check warning on line 214 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 214 is only partially covered, one branch is missing

Check warning on line 214 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 214 is only partially covered, one branch is missing
XMLEvent event = reader.nextEvent();

if (event.isStartElement()) {
var nextElement = event.asStartElement();
if (METRIC.equals(nextElement.getName())) {

Check warning on line 219 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.

Check warning on line 219 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 219 is only partially covered, one branch is missing

Check warning on line 219 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 219 is only partially covered, one branch is missing
readValueCounter(methodNode, nextElement);
}
}
else if (event.isEndElement()) {
var endElement = event.asEndElement();
if (METHOD.equals(endElement.getName())) {

Check warning on line 225 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
return methodNode;

Check warning on line 226 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Mutation survived

One mutation survived in line 226 (NullReturnValsMutator)
Raw output
Survived mutations:
- replaced return value with null for edu/hm/hafner/coverage/parser/MetricsParser::readMethod (org.pitest.mutationtest.engine.gregor.mutators.returns.NullReturnValsMutator)
}
}
}
throw createEofException(fileName);

Check warning on line 230 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 230 is not covered by tests

Check warning on line 230 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 230 is not covered by tests
}

private MethodNode createMethod(final StartElement startElement, final String methodName) {
return new MethodNode(methodName, "", parseInteger(getValueOf(startElement, BEGIN_LINE)));
}

private void readValueCounter(final Node node, final StartElement startElement) {
// FIXME: create Metric Values independent of Metric Name
String currentType = getValueOf(startElement, NAME);
int value = parseInteger(getValueOf(startElement, VALUE));
if (CYCLOMATIC_COMPLEXITY.equals(currentType)) {

Check warning on line 241 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
node.addValue(new CyclomaticComplexity(value));
}
else if (COGNITIVE_COMPLEXITY.equals(currentType)) {

Check warning on line 244 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
node.addValue(new CyclomaticComplexity(value, Metric.COGNITIVE_COMPLEXITY));
}
else if (NCSS.equals(currentType)) {

Check warning on line 247 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.
node.addValue(new CyclomaticComplexity(value, Metric.NCSS));
}
else if (NPATH_COMPLEXITY.equals(currentType)) {

Check warning on line 250 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Error Prone: YodaCondition

The non-constant portion of an equals check generally comes first. Prefer e.equals(CONSTANT) if e is non-null or Objects.equals(e, CONSTANT) if e may be.

Check warning on line 250 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 250 is only partially covered, one branch is missing

Check warning on line 250 in src/main/java/edu/hm/hafner/coverage/parser/MetricsParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 250 is only partially covered, one branch is missing
node.addValue(new CyclomaticComplexity(value, Metric.NPATH_COMPLEXITY));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.hm.hafner.coverage.parser.CoberturaParser;
import edu.hm.hafner.coverage.parser.JacocoParser;
import edu.hm.hafner.coverage.parser.JunitParser;
import edu.hm.hafner.coverage.parser.MetricsParser;
import edu.hm.hafner.coverage.parser.NunitParser;
import edu.hm.hafner.coverage.parser.OpenCoverParser;
import edu.hm.hafner.coverage.parser.PitestParser;
Expand All @@ -28,7 +29,8 @@ public enum CoverageParserType {
PIT,
JUNIT,
VECTORCAST,
XUNIT
XUNIT,
METRICS
}

/**
Expand Down Expand Up @@ -79,6 +81,8 @@ public CoverageParser get(final CoverageParserType parser, final ProcessingMode
return new XunitParser(processingMode);
case VECTORCAST:
return new VectorCastParser(processingMode);
case METRICS:
return new MetricsParser(processingMode);
}
throw new IllegalArgumentException("Unknown parser type: " + parser);

Check warning on line 87 in src/main/java/edu/hm/hafner/coverage/registry/ParserRegistry.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 87 is not covered by tests
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/edu/hm/hafner/coverage/IntegerValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void shouldCreateValue() {
var value = createValue(123);
assertThat(value.serialize()).startsWith(value.getMetric().name()).endsWith(": 123");

assertThat(value.create(100)).hasValue(100);
assertThat(value.create(-100)).hasValue(-100);
assertThat(value.create(0)).hasValue(0);
assertThat(value.create(100, Metric.COMPLEXITY)).hasValue(100);
assertThat(value.create(-100, Metric.COMPLEXITY)).hasValue(-100);
assertThat(value.create(0, Metric.COMPLEXITY)).hasValue(0);
}

@Test
Expand Down
Loading

0 comments on commit a00b4e0

Please sign in to comment.