use of org.mockito.invocation.Location in project mockito by mockito.
the class AtLeastXNumberOfInvocationsChecker method checkAtLeastNumberOfInvocations.
public static void checkAtLeastNumberOfInvocations(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount, InOrderContext orderingContext) {
List<Invocation> chunk = findAllMatchingUnverifiedChunks(invocations, wanted, orderingContext);
int actualCount = chunk.size();
if (wantedCount > actualCount) {
Location lastLocation = getLastLocation(chunk);
throw tooLittleActualInvocationsInOrder(new AtLeastDiscrepancy(wantedCount, actualCount), wanted, lastLocation);
}
markVerifiedInOrder(chunk, wanted, orderingContext);
}
use of org.mockito.invocation.Location in project mockito by mockito.
the class NumberOfInvocationsChecker method checkNumberOfInvocations.
public static void checkNumberOfInvocations(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount) {
List<Invocation> actualInvocations = findInvocations(invocations, wanted);
int actualCount = actualInvocations.size();
if (wantedCount > actualCount) {
Location lastInvocation = getLastLocation(actualInvocations);
throw tooLittleActualInvocations(new Discrepancy(wantedCount, actualCount), wanted, lastInvocation);
}
if (wantedCount == 0 && actualCount > 0) {
Location firstUndesired = actualInvocations.get(wantedCount).getLocation();
throw neverWantedButInvoked(wanted, firstUndesired);
}
if (wantedCount < actualCount) {
Location firstUndesired = actualInvocations.get(wantedCount).getLocation();
throw tooManyActualInvocations(wantedCount, actualCount, wanted, firstUndesired);
}
markVerified(actualInvocations, wanted);
}
use of org.mockito.invocation.Location in project mockito by mockito.
the class NumberOfInvocationsChecker method checkNumberOfInvocationsNonGreedy.
public static void checkNumberOfInvocationsNonGreedy(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount, InOrderContext context) {
int actualCount = 0;
Location lastLocation = null;
while (actualCount < wantedCount) {
Invocation next = findFirstMatchingUnverifiedInvocation(invocations, wanted, context);
if (next == null) {
throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastLocation);
}
markVerified(next, wanted);
context.markVerified(next);
lastLocation = next.getLocation();
actualCount++;
}
}
use of org.mockito.invocation.Location in project mockito by mockito.
the class NumberOfInvocationsChecker method checkNumberOfInvocations.
public static void checkNumberOfInvocations(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount, InOrderContext context) {
List<Invocation> chunk = findMatchingChunk(invocations, wanted, wantedCount, context);
int actualCount = chunk.size();
if (wantedCount > actualCount) {
Location lastInvocation = getLastLocation(chunk);
throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastInvocation);
}
if (wantedCount < actualCount) {
Location firstUndesired = chunk.get(wantedCount).getLocation();
throw tooManyActualInvocationsInOrder(wantedCount, actualCount, wanted, firstUndesired);
}
markVerifiedInOrder(chunk, wanted, context);
}
use of org.mockito.invocation.Location in project mockito by mockito.
the class MockingProgressImpl method validateState.
public void validateState() {
validateMostStuff();
//validate stubbing:
if (stubbingInProgress != null) {
Location temp = stubbingInProgress;
stubbingInProgress = null;
throw unfinishedStubbing(temp);
}
}
Aggregations