use of org.mockito.invocation.MatchableInvocation in project mockito by mockito.
the class AtLeastXNumberOfInvocationsChecker method checkAtLeastNumberOfInvocations.
public static void checkAtLeastNumberOfInvocations(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount) {
List<Invocation> actualInvocations = findInvocations(invocations, wanted);
int actualCount = actualInvocations.size();
if (wantedCount > actualCount) {
Location lastLocation = getLastLocation(actualInvocations);
throw tooLittleActualInvocations(new AtLeastDiscrepancy(wantedCount, actualCount), wanted, lastLocation);
}
markVerified(actualInvocations, wanted);
}
use of org.mockito.invocation.MatchableInvocation in project mockito by mockito.
the class MissingInvocationChecker method checkMissingInvocation.
public static void checkMissingInvocation(List<Invocation> invocations, MatchableInvocation wanted) {
List<Invocation> actualInvocations = findInvocations(invocations, wanted);
if (!actualInvocations.isEmpty()) {
return;
}
Invocation similar = findSimilarInvocation(invocations, wanted);
if (similar == null) {
throw wantedButNotInvoked(wanted, invocations);
}
Integer[] indexesOfSuspiciousArgs = getSuspiciouslyNotMatchingArgsIndexes(wanted.getMatchers(), similar.getArguments());
SmartPrinter smartPrinter = new SmartPrinter(wanted, similar, indexesOfSuspiciousArgs);
throw argumentsAreDifferent(smartPrinter.getWanted(), smartPrinter.getActual(), similar.getLocation());
}
use of org.mockito.invocation.MatchableInvocation in project mockito by mockito.
the class NumberOfInvocationsInOrderChecker method check.
public void check(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.MatchableInvocation in project mockito by mockito.
the class Only method verify.
@SuppressWarnings("unchecked")
public void verify(VerificationData data) {
MatchableInvocation target = data.getTarget();
List<Invocation> invocations = data.getAllInvocations();
List<Invocation> chunk = findInvocations(invocations, target);
if (invocations.size() != 1 && chunk.size() > 0) {
Invocation unverified = findFirstUnverified(invocations);
throw noMoreInteractionsWanted(unverified, (List) invocations);
}
if (invocations.size() != 1 || chunk.size() == 0) {
throw wantedButNotInvoked(target);
}
markVerified(chunk.get(0), target);
}
use of org.mockito.invocation.MatchableInvocation in project mockito by mockito.
the class AtMost method verify.
public void verify(VerificationData data) {
List<Invocation> invocations = data.getAllInvocations();
MatchableInvocation wanted = data.getTarget();
List<Invocation> found = findInvocations(invocations, wanted);
int foundSize = found.size();
if (foundSize > maxNumberOfInvocations) {
throw wantedAtMostX(maxNumberOfInvocations, foundSize);
}
removeAlreadyVerified(found);
markVerified(found, wanted);
}
Aggregations