Search in sources :

Example 16 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.

the class NoMoreInteractionsTest method shouldVerifyInOrderMultipleInvoctions.

@Test
public void shouldVerifyInOrderMultipleInvoctions() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    Invocation i = new InvocationBuilder().seq(1).toInvocation();
    Invocation i2 = new InvocationBuilder().seq(2).toInvocation();
    //when
    context.markVerified(i2);
    //then no exception is thrown
    n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i, i2), null));
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl) Test(org.junit.Test)

Example 17 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.

the class NoMoreInteractionsTest method shouldVerifyInOrderAndPass.

@Test
public void shouldVerifyInOrderAndPass() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    Invocation i = new InvocationBuilder().toInvocation();
    context.markVerified(i);
    assertTrue(context.isVerified(i));
    //when
    n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
//then no exception is thrown
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl) Test(org.junit.Test)

Example 18 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder 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 19 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder 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 20 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder 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

InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)46 Test (org.junit.Test)45 Invocation (org.mockito.invocation.Invocation)28 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)12 Returns (org.mockito.internal.stubbing.answers.Returns)5 VerificationDataInOrderImpl (org.mockito.internal.verification.api.VerificationDataInOrderImpl)5 MockitoException (org.mockito.exceptions.base.MockitoException)4 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)4 IMethods (org.mockitousage.IMethods)4 WrongTypeOfReturnValue (org.mockito.exceptions.misusing.WrongTypeOfReturnValue)3 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)3 CharacterCodingException (java.nio.charset.CharacterCodingException)2 StubbedInvocationMatcher (org.mockito.internal.stubbing.StubbedInvocationMatcher)2 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)2 ReturnsEmptyValues (org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues)2 InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)2 InOrderContext (org.mockito.internal.verification.api.InOrderContext)2 MatchableInvocation (org.mockito.invocation.MatchableInvocation)2 IOException (java.io.IOException)1 Before (org.junit.Before)1