mockit.coverage.reporting.lineCoverage.LineCoverageFormatter 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 mocking/faking APIs and a code coverage tool, supporting both JUnit and TestNG.
The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested
in isolation from selected dependencies.
/*
* Copyright (c) 2006 JMockit developers
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.coverage.reporting.lineCoverage;
import java.util.*;
import javax.annotation.*;
import mockit.coverage.*;
import mockit.coverage.lines.*;
import mockit.coverage.reporting.*;
import mockit.coverage.reporting.parsing.*;
final class LineCoverageFormatter
{
@Nonnull private final StringBuilder formattedLine;
@Nonnull private final LineSegmentsFormatter segmentsFormatter;
@Nullable private final ListOfCallPoints listOfCallPoints;
LineCoverageFormatter(boolean withCallPoints) {
formattedLine = new StringBuilder(200);
segmentsFormatter = new LineSegmentsFormatter(withCallPoints, formattedLine);
listOfCallPoints = withCallPoints ? new ListOfCallPoints() : null;
}
String format(@Nonnull LineParser lineParser, @Nonnull PerFileLineCoverage lineCoverageData) {
formattedLine.setLength(0);
formattedLine.append("");
segmentsFormatter.formatSegments(lineParser, lineData);
}
private void formatLineWithSingleSegment(@Nonnull LineParser lineParser, @Nonnull LineCoverageData lineData) {
formattedLine.append(lineData.isCovered() ? " covered" : " uncovered");
List callPoints = lineData.getCallPoints();
if (listOfCallPoints != null && callPoints != null) {
formattedLine.append(" cp' onclick='showHide(this)");
}
formattedLine.append("' id='l").append(lineParser.getNumber()).append("s0'>");
String content = lineParser.getInitialElement().toString();
formattedLine.append(content).append("
");
if (listOfCallPoints != null) {
listOfCallPoints.insertListOfCallPoints(callPoints);
formattedLine.append(listOfCallPoints.getContents());
}
}
}