Search in sources :

Example 1 with Location

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) {
    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);
}
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 2 with Location

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

Example 3 with Location

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

the class MockingProgressImpl method validateMostStuff.

private void validateMostStuff() {
    //State is cool when GlobalConfiguration is already loaded
    //this cannot really be tested functionally because I cannot dynamically mess up org.mockito.configuration.MockitoConfiguration class
    GlobalConfiguration.validate();
    if (verificationMode != null) {
        Location location = verificationMode.getLocation();
        verificationMode = null;
        throw unfinishedVerificationException(location);
    }
    getArgumentMatcherStorage().validateState();
}
Also used : Location(org.mockito.invocation.Location)

Example 4 with Location

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);
    }
}
Also used : Location(org.mockito.invocation.Location)

Example 5 with Location

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

the class InvocationsFinderTest method shouldGetLastStackTrace.

@Test
public void shouldGetLastStackTrace() throws Exception {
    Location last = InvocationsFinder.getLastLocation(invocations);
    assertSame(differentMethodInvocation.getLocation(), last);
    assertNull(InvocationsFinder.getLastLocation(Collections.<Invocation>emptyList()));
}
Also used : Invocation(org.mockito.invocation.Invocation) Location(org.mockito.invocation.Location) Test(org.junit.Test)

Aggregations

Location (org.mockito.invocation.Location)10 Invocation (org.mockito.invocation.Invocation)7 InvocationsFinder.getLastLocation (org.mockito.internal.invocation.InvocationsFinder.getLastLocation)6 MatchableInvocation (org.mockito.invocation.MatchableInvocation)6 Discrepancy (org.mockito.internal.reporting.Discrepancy)4 InvocationsFinder.findFirstMatchingUnverifiedInvocation (org.mockito.internal.invocation.InvocationsFinder.findFirstMatchingUnverifiedInvocation)3 Test (org.junit.Test)1 LocationImpl (org.mockito.internal.debugging.LocationImpl)1