Search in sources :

Example 11 with VerificationInOrderFailure

use of org.mockito.exceptions.verification.VerificationInOrderFailure in project mockito by mockito.

the class NoMoreInteractionsTest method shouldVerifyInOrder.

@Test
public void shouldVerifyInOrder() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    Invocation i = new InvocationBuilder().toInvocation();
    assertFalse(context.isVerified(i));
    try {
        //when
        n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
        //then
        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 12 with VerificationInOrderFailure

use of org.mockito.exceptions.verification.VerificationInOrderFailure in project mockito by mockito.

the class BDDMockitoTest method should_fail_for_interactions_that_were_in_wrong_order.

@Test
public void should_fail_for_interactions_that_were_in_wrong_order() {
    InOrder inOrder = inOrder(mock);
    mock.arrayReturningMethod();
    mock.booleanObjectReturningMethod();
    then(mock).should(inOrder).booleanObjectReturningMethod();
    try {
        then(mock).should(inOrder).arrayReturningMethod();
        fail("should have raise in order verification failure on second verify call");
    } catch (VerificationInOrderFailure expected) {
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 13 with VerificationInOrderFailure

use of org.mockito.exceptions.verification.VerificationInOrderFailure in project mockito by mockito.

the class SpyingOnRealObjectsTest method shouldVerifyInOrderAndFail.

@Test
public void shouldVerifyInOrderAndFail() {
    spy.add("one");
    spy.add("two");
    InOrder inOrder = inOrder(spy);
    inOrder.verify(spy).add("two");
    try {
        inOrder.verify(spy).add("one");
        fail();
    } catch (VerificationInOrderFailure f) {
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 14 with VerificationInOrderFailure

use of org.mockito.exceptions.verification.VerificationInOrderFailure in project mockito by mockito.

the class FindingRedundantInvocationsInOrderTest method shouldSayNoInteractionsWanted.

@Test
public void shouldSayNoInteractionsWanted() throws Exception {
    //when
    mock.simpleMethod();
    //then
    InOrder inOrder = inOrder(mock);
    try {
        inOrder.verifyNoMoreInteractions();
        fail();
    } catch (VerificationInOrderFailure e) {
        assertThat(e).hasMessageContaining("No interactions wanted");
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 15 with VerificationInOrderFailure

use of org.mockito.exceptions.verification.VerificationInOrderFailure in project mockito by mockito.

the class SelectedMocksInOrderVerificationTest method shouldFailVerificationForMockTwo.

@Test
public void shouldFailVerificationForMockTwo() {
    InOrder inOrder = inOrder(mockTwo);
    try {
        inOrder.verify(mockTwo).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)15 InOrder (org.mockito.InOrder)12 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)3 VerificationDataInOrderImpl (org.mockito.internal.verification.api.VerificationDataInOrderImpl)3 Invocation (org.mockito.invocation.Invocation)3 IMethods (org.mockitousage.IMethods)1