mockit.coverage.lines.LineSegmentData 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 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.coverage.lines;
import java.io.*;
import java.util.*;
import javax.annotation.*;
import mockit.coverage.*;
public class LineSegmentData implements Serializable
{
private static final long serialVersionUID = -6233980722802474992L;
private static final int MAX_CALL_POINTS = Integer.parseInt(Configuration.getProperty("maxCallPoints", "10"));
// Constant data:
private boolean unreachable;
private boolean empty;
// Runtime data:
int executionCount;
@Nullable private List callPoints;
public final void markAsUnreachable() { unreachable = true; }
public final boolean isEmpty() { return empty; }
final void markAsEmpty() { empty = true; }
final boolean acceptsAdditionalCallPoints()
{
return callPoints == null || callPoints.size() < MAX_CALL_POINTS;
}
final int registerExecution(@Nullable CallPoint callPoint)
{
int previousExecutionCount = executionCount++;
if (callPoint != null) {
addCallPoint(callPoint);
}
return previousExecutionCount;
}
private void addCallPoint(@Nonnull CallPoint callPoint)
{
if (callPoints == null) {
callPoints = new ArrayList(MAX_CALL_POINTS);
}
for (int i = callPoints.size() - 1; i >= 0; i--) {
CallPoint previousCallPoint = callPoints.get(i);
if (callPoint.isSameLineInTestCode(previousCallPoint)) {
previousCallPoint.incrementRepetitionCount();
return;
}
}
callPoints.add(callPoint);
}
public final boolean containsCallPoints() { return callPoints != null; }
@Nullable public final List getCallPoints() { return callPoints; }
public final int getExecutionCount() { return executionCount; }
final void setExecutionCount(int executionCount) { this.executionCount = executionCount; }
public final boolean isCovered() { return unreachable || !empty && executionCount > 0; }
final void addExecutionCountAndCallPointsFromPreviousTestRun(@Nonnull LineSegmentData previousData)
{
executionCount += previousData.executionCount;
if (previousData.callPoints != null) {
if (callPoints != null) {
callPoints.addAll(0, previousData.callPoints);
}
else {
callPoints = previousData.callPoints;
}
}
}
}