Search in sources :

Example 36 with Invocation

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

the class AtLeastXNumberOfInvocationsCheckerTest method shouldReportTooLittleInvocationsInOrder.

@Test
public void shouldReportTooLittleInvocationsInOrder() {
    InOrderContext context = new InOrderContextImpl();
    //given
    Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
    Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
    exception.expect(VerificationInOrderFailure.class);
    exception.expectMessage("iMethods.simpleMethod()");
    exception.expectMessage("Wanted *at least* 2 times");
    exception.expectMessage("But was 1 time");
    //when
    checkAtLeastNumberOfInvocations(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 2, context);
}
Also used : InOrderContextImpl(org.mockito.internal.verification.InOrderContextImpl) Invocation(org.mockito.invocation.Invocation) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) InOrderContext(org.mockito.internal.verification.api.InOrderContext) Test(org.junit.Test)

Example 37 with Invocation

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

the class MissingInvocationInOrderCheckerTest method shouldReportWantedDiffersFromActual.

@Test
public void shouldReportWantedDiffersFromActual() throws Exception {
    Invocation invocation1 = buildIntArgMethod().arg(1111).toInvocation();
    Invocation invocation2 = buildIntArgMethod().arg(2222).toInvocation();
    context.markVerified(invocation2);
    invocations = asList(invocation1, invocation2);
    wanted = buildIntArgMethod().arg(2222).toInvocationMatcher();
    exception.expect(VerificationInOrderFailure.class);
    exception.expectMessage("Verification in order failure");
    exception.expectMessage("Wanted but not invoked:");
    exception.expectMessage("mock.intArgumentMethod(2222);");
    exception.expectMessage("Wanted anywhere AFTER following interaction:");
    exception.expectMessage("mock.intArgumentMethod(2222);");
    checkMissingInvocation(invocations, wanted, context);
}
Also used : Invocation(org.mockito.invocation.Invocation) MissingInvocationChecker.checkMissingInvocation(org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation) Test(org.junit.Test)

Example 38 with Invocation

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

the class NumberOfInvocationsCheckerTest method shouldReportTooManyActual.

@Test
public void shouldReportTooManyActual() throws Exception {
    Invocation first = buildSimpleMethod().toInvocation();
    Invocation second = buildSimpleMethod().toInvocation();
    invocations = asList(first, second);
    wanted = buildSimpleMethod().toInvocationMatcher();
    exception.expectMessage("Wanted 1 time");
    exception.expectMessage("But was 2 times");
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 1);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 39 with Invocation

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

the class NumberOfInvocationsCheckerTest method shouldReportWithFirstUndesiredInvocationStackTrace.

@Test
public void shouldReportWithFirstUndesiredInvocationStackTrace() throws Exception {
    Invocation first = buildSimpleMethod().toInvocation();
    Invocation second = buildSimpleMethod().toInvocation();
    Invocation third = buildSimpleMethod().toInvocation();
    invocations = asList(first, second, third);
    wanted = buildSimpleMethod().toInvocationMatcher();
    exception.expect(TooManyActualInvocations.class);
    exception.expectMessage("" + third.getLocation());
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 2);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 40 with Invocation

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

the class NumberOfInvocationsInOrderCheckerTest method shouldReportTooLittleInvocations.

@Test
public void shouldReportTooLittleInvocations() throws Exception {
    Invocation first = buildSimpleMethod().toInvocation();
    Invocation second = buildSimpleMethod().toInvocation();
    wanted = buildSimpleMethod().toInvocationMatcher();
    invocations = asList(first, second);
    exception.expect(VerificationInOrderFailure.class);
    exception.expectMessage("mock.simpleMethod()");
    exception.expectMessage("Wanted 4 times");
    exception.expectMessage("But was 2 times");
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 4, context);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

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