use of org.mockito.invocation.Invocation in project mockito by mockito.
the class UnusedStubsFinder method find.
/**
* Finds all unused stubs for given mocks
*
* @param mocks full list of mocks
*/
public List<Invocation> find(List<?> mocks) {
List<Invocation> unused = new LinkedList<Invocation>();
for (Object mock : mocks) {
InternalMockHandler<Object> handler = MockUtil.getMockHandler(mock);
List<StubbedInvocationMatcher> fromSingleMock = handler.getInvocationContainer().getStubbedInvocations();
for (StubbedInvocationMatcher s : fromSingleMock) {
if (!s.wasUsed()) {
unused.add(s.getInvocation());
}
}
}
return unused;
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class DefaultStubbingLookupListener method potentialArgMismatches.
private static List<Invocation> potentialArgMismatches(Invocation invocation) {
List<Invocation> matchingStubbings = new LinkedList<Invocation>();
Collection<Stubbing> stubbings = mockingDetails(invocation.getMock()).getStubbings();
for (Stubbing s : stubbings) {
if (!s.wasUsed() && s.getInvocation().getMethod().getName().equals(invocation.getMethod().getName())) {
matchingStubbings.add(s.getInvocation());
}
}
return matchingStubbings;
}
use of org.mockito.invocation.Invocation 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.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 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