Search in sources :

Example 41 with Invocation

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

the class NumberOfInvocationsInOrderCheckerTest 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, context);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 42 with Invocation

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

the class NumberOfInvocationsInOrderCheckerTest method shouldReportNeverWantedButInvoked.

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

Example 43 with Invocation

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

the class NumberOfInvocationsInOrderCheckerTest method shouldMarkInvocationsAsVerified.

@Test
public void shouldMarkInvocationsAsVerified() throws Exception {
    Invocation invocation = buildSimpleMethod().toInvocation();
    assertThat(invocation.isVerified()).isFalse();
    invocations = asList(invocation);
    wanted = buildSimpleMethod().toInvocationMatcher();
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 1, context);
    assertThat(invocation.isVerified()).isTrue();
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 44 with Invocation

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

the class NoMoreInteractionsTest method shouldVerifyInOrderMultipleInvoctionsAndThrow.

@Test
public void shouldVerifyInOrderMultipleInvoctionsAndThrow() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    Invocation i = new InvocationBuilder().seq(1).toInvocation();
    Invocation i2 = new InvocationBuilder().seq(2).toInvocation();
    try {
        //when
        n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i, i2), null));
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 45 with Invocation

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

the class OnlyTest method shouldNotMarkAsVerifiedWhenAssertionFailed.

@Test
public void shouldNotMarkAsVerifiedWhenAssertionFailed() {
    //given
    Invocation invocation = new InvocationBuilder().toInvocation();
    assertFalse(invocation.isVerified());
    //when
    try {
        only.verify(new VerificationDataStub(new InvocationBuilder().toInvocationMatcher(), invocation));
        fail();
    } catch (MockitoAssertionError e) {
    }
    //then
    assertFalse(invocation.isVerified());
}
Also used : MockitoAssertionError(org.mockito.exceptions.base.MockitoAssertionError) Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) 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