use of org.mockito.invocation.Invocation 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.Invocation 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.Invocation in project mockito by mockito.
the class NoMoreInteractions method verifyInOrder.
public void verifyInOrder(VerificationDataInOrder data) {
List<Invocation> invocations = data.getAllInvocations();
Invocation unverified = findFirstUnverifiedInOrder(data.getOrderingContext(), invocations);
if (unverified != null) {
throw noMoreInteractionsWantedInOrder(unverified);
}
}
use of org.mockito.invocation.Invocation 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.Invocation in project mockito by mockito.
the class MockitoDebuggerImpl method printInvocations.
/**
* TODO: when MockitoDebugger is deleted, delete this implementation, too
*/
@Deprecated
public String printInvocations(Object... mocks) {
String out = "";
List<Invocation> invocations = AllInvocationsFinder.find(asList(mocks));
out += line("********************************");
out += line("*** Mockito interactions log ***");
out += line("********************************");
for (Invocation i : invocations) {
out += line(i.toString());
out += line(" invoked: " + i.getLocation());
if (i.stubInfo() != null) {
out += line(" stubbed: " + i.stubInfo().stubbedAt().toString());
}
}
invocations = unusedStubsFinder.find(asList(mocks));
if (invocations.isEmpty()) {
return print(out);
}
out += line("********************************");
out += line("*** Unused stubs ***");
out += line("********************************");
for (Invocation i : invocations) {
out += line(i.toString());
out += line(" stubbed: " + i.getLocation());
}
return print(out);
}
Aggregations