mockit.coverage.reporting.pathCoverage.PathCoverageOutput Maven / Gradle / Ivy
/*
* Copyright (c) 2006 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.coverage.reporting.pathCoverage;
import java.io.*;
import java.util.*;
import javax.annotation.*;
import mockit.coverage.*;
import mockit.coverage.paths.*;
public final class PathCoverageOutput
{
@Nonnull private final PrintWriter output;
@Nonnull private final PathCoverageFormatter pathFormatter;
@Nonnull private final Iterator nextMethod;
// Helper fields:
@Nullable private MethodCoverageData currentMethod;
public PathCoverageOutput(@Nonnull PrintWriter output, @Nonnull Collection methods)
{
this.output = output;
pathFormatter = new PathCoverageFormatter(output);
nextMethod = methods.iterator();
moveToNextMethod();
}
private void moveToNextMethod()
{
currentMethod = nextMethod.hasNext() ? nextMethod.next() : null;
}
public void writePathCoverageInfoIfLineStartsANewMethodOrConstructor(int lineNumber)
{
if (currentMethod != null && lineNumber == currentMethod.getFirstLineInBody()) {
writePathCoverageInformationForMethod(currentMethod);
moveToNextMethod();
}
}
private void writePathCoverageInformationForMethod(@Nonnull MethodCoverageData methodData)
{
List paths = methodData.getPaths();
if (paths.size() > 1) {
writeHeaderForAllPaths(methodData);
pathFormatter.writeInformationForEachPath(paths);
writeFooterForAllPaths();
}
}
private void writeHeaderForAllPaths(@Nonnull MethodCoverageData methodData)
{
int coveredPaths = methodData.getCoveredPaths();
int totalPaths = methodData.getTotalPaths();
output.println(" ");
output.write(" ");
output.print(methodData.getExecutionCount());
output.println(" ");
output.println(" ");
output.write(" Path coverage: ");
output.print(coveredPaths);
output.print('/');
output.print(totalPaths);
output.println("");
}
private void writeFooterForAllPaths()
{
output.println(" ");
output.println(" ");
}
}