Search in sources :

Example 61 with Invocation

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

the class StubbingArgMismatchesTest method multiple_matching_invocations_per_stub_plus_some_other_invocation.

@Test
public void multiple_matching_invocations_per_stub_plus_some_other_invocation() throws Exception {
    //given
    Invocation stubbing = new InvocationBuilder().args("a").location("-> at A.java").toInvocation();
    mismatches.add(new InvocationBuilder().args("x").location("-> at X.java").toInvocation(), stubbing);
    mismatches.add(new InvocationBuilder().args("y").location("-> at Y.java").toInvocation(), stubbing);
    mismatches.add(new InvocationBuilder().method("differentMethod").args("n").location("-> at N.java").toInvocation(), new InvocationBuilder().method("differentMethod").args("m").location("-> at M.java").toInvocation());
    //when
    mismatches.format("MyTest.myTestMethod", logger);
    //then
    assertEquals("[MockitoHint] MyTest.myTestMethod (see javadoc for MockitoHint):\n" + "[MockitoHint] 1. Unused... -> at A.java\n" + "[MockitoHint]  ...args ok? -> at X.java\n" + "[MockitoHint]  ...args ok? -> at Y.java\n" + "[MockitoHint] 2. Unused... -> at M.java\n" + "[MockitoHint]  ...args ok? -> at N.java\n", logger.getLoggedInfo());
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 62 with Invocation

use of org.mockito.invocation.Invocation 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);
}
Also used : MatchableInvocation(org.mockito.invocation.MatchableInvocation) Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation)

Example 63 with Invocation

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

the class Calls method verifyInOrder.

@Override
public void verifyInOrder(VerificationDataInOrder data) {
    List<Invocation> allInvocations = data.getAllInvocations();
    MatchableInvocation wanted = data.getWanted();
    checkMissingInvocation(allInvocations, wanted, data.getOrderingContext());
    checkNumberOfInvocationsNonGreedy(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 64 with Invocation

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

the class InOrderWrapper method verify.

public void verify(VerificationData data) {
    List<Invocation> invocations = VerifiableInvocationsFinder.find(inOrder.getMocksToBeVerifiedInOrder());
    VerificationDataInOrderImpl dataInOrder = new VerificationDataInOrderImpl(inOrder, invocations, data.getTarget());
    mode.verifyInOrder(dataInOrder);
}
Also used : Invocation(org.mockito.invocation.Invocation) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl)

Example 65 with Invocation

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

the class Times method verify.

@Override
public void verify(VerificationData data) {
    List<Invocation> invocations = data.getAllInvocations();
    MatchableInvocation wanted = data.getTarget();
    if (wantedCount > 0) {
        checkMissingInvocation(data.getAllInvocations(), data.getTarget());
    }
    checkNumberOfInvocations(invocations, wanted, wantedCount);
}
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)

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