Search in sources :

Example 66 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class Times method verifyInOrder.

@Override
public void verifyInOrder(VerificationDataInOrder data) {
    List<Invocation> allInvocations = data.getAllInvocations();
    MatchableInvocation wanted = data.getWanted();
    if (wantedCount > 0) {
        checkMissingInvocation(allInvocations, wanted, data.getOrderingContext());
    }
    checkNumberOfInvocations(allInvocations, wanted, wantedCount, data.getOrderingContext());
}
Also used : MatchableInvocation(org.mockito.invocation.MatchableInvocation) Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) MissingInvocationChecker.checkMissingInvocation(org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation)

Example 67 with Invocation

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, 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);
}
Also used : Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) InvocationsFinder.getLastLocation(org.mockito.internal.invocation.InvocationsFinder.getLastLocation) Location(org.mockito.invocation.Location)

Example 68 with Invocation

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, InOrderContext context) {
    List<Invocation> chunk = findAllMatchingUnverifiedChunks(invocations, wanted, context);
    if (!chunk.isEmpty()) {
        return;
    }
    Invocation previousInOrder = findPreviousVerifiedInOrder(invocations, context);
    if (previousInOrder != null) {
        throw wantedButNotInvokedInOrder(wanted, previousInOrder);
    }
    checkMissingInvocation(invocations, wanted);
}
Also used : Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) InvocationsFinder.findSimilarInvocation(org.mockito.internal.invocation.InvocationsFinder.findSimilarInvocation)

Example 69 with Invocation

use of org.mockito.invocation.Invocation 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);
}
Also used : Discrepancy(org.mockito.internal.reporting.Discrepancy) Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) InvocationsFinder.findFirstMatchingUnverifiedInvocation(org.mockito.internal.invocation.InvocationsFinder.findFirstMatchingUnverifiedInvocation) Location(org.mockito.invocation.Location) InvocationsFinder.getLastLocation(org.mockito.internal.invocation.InvocationsFinder.getLastLocation)

Example 70 with Invocation

use of org.mockito.invocation.Invocation 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++;
    }
}
Also used : Discrepancy(org.mockito.internal.reporting.Discrepancy) Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) InvocationsFinder.findFirstMatchingUnverifiedInvocation(org.mockito.internal.invocation.InvocationsFinder.findFirstMatchingUnverifiedInvocation) Location(org.mockito.invocation.Location) InvocationsFinder.getLastLocation(org.mockito.internal.invocation.InvocationsFinder.getLastLocation)

Aggregations

Invocation (org.mockito.invocation.Invocation)106 Test (org.junit.Test)71 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)28 MatchableInvocation (org.mockito.invocation.MatchableInvocation)19 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)11 Location (org.mockito.invocation.Location)7 InvocationsFinder.getLastLocation (org.mockito.internal.invocation.InvocationsFinder.getLastLocation)6 Returns (org.mockito.internal.stubbing.answers.Returns)6 VerificationDataInOrderImpl (org.mockito.internal.verification.api.VerificationDataInOrderImpl)6 Method (java.lang.reflect.Method)5 Discrepancy (org.mockito.internal.reporting.Discrepancy)4 MissingInvocationChecker.checkMissingInvocation (org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation)4 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)3 InvocationsFinder.findFirstMatchingUnverifiedInvocation (org.mockito.internal.invocation.InvocationsFinder.findFirstMatchingUnverifiedInvocation)3 InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)3 IMethods (org.mockitousage.IMethods)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LinkedList (java.util.LinkedList)2 TestCase.assertEquals (junit.framework.TestCase.assertEquals)2 MockingDetails (org.mockito.MockingDetails)2