mockit.coverage.reporting.ListOfCallPoints Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for automated developer testing.
It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external
APIs; JUnit (4 & 5) and TestNG test runners are supported.
It also contains an advanced code coverage tool.
The newest version!
/*
* Copyright (c) 2006 JMockit developers
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.coverage.reporting;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.List;
import java.util.regex.Pattern;
import mockit.coverage.CallPoint;
public final class ListOfCallPoints {
@NonNull
private static final String EOL = System.lineSeparator();
private static final Pattern LESS_THAN_CHAR = Pattern.compile("<");
@NonNull
private final StringBuilder content;
public ListOfCallPoints() {
content = new StringBuilder(100);
}
public void insertListOfCallPoints(@Nullable List callPoints) {
if (content.length() == 0) {
content.append(EOL).append(" ");
}
content.append(" ");
content.append(current.getClassName()).append('#');
content.append(LESS_THAN_CHAR.matcher(current.getMethodName()).replaceFirst("<")).append(": ");
content.append(current.getLineNumber());
}
private void appendRepetitionCountIfNeeded(@NonNull CallPoint callPoint) {
int repetitionCount = callPoint.getRepetitionCount();
if (repetitionCount > 0) {
content.append('x').append(1 + repetitionCount);
}
}
@NonNull
public String getContents() {
String result = content.toString();
content.setLength(0);
return result;
}
}
").append(EOL).append(" ");
return;
}
content.append(EOL);
CallPoint currentCP = callPoints.get(0);
appendTestMethod(currentCP.getStackTraceElement());
appendRepetitionCountIfNeeded(currentCP);
for (int i = 1, n = callPoints.size(); i < n; i++) {
CallPoint nextCP = callPoints.get(i);
StackTraceElement ste = nextCP.getStackTraceElement();
if (nextCP.isSameTestMethod(currentCP)) {
content.append(", ").append(ste.getLineNumber());
} else {
content.append("").append(EOL);
appendTestMethod(ste);
}
appendRepetitionCountIfNeeded(nextCP);
currentCP = nextCP;
}
content.append("").append(EOL).append(" ").append(EOL).append(" ");
}
private void appendTestMethod(@NonNull StackTraceElement current) {
content.append("
© 2015 - 2025 Weber Informatics LLC | Privacy Policy