Search in sources :

Example 1 with VerificationInOrderFailure

use of org.mockito.exceptions.verification.VerificationInOrderFailure 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 2 with VerificationInOrderFailure

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

the class StackTraceFilteringTest method shouldFilterStacktraceWhenVerifyingInOrder.

@Test
public void shouldFilterStacktraceWhenVerifyingInOrder() {
    InOrder inOrder = inOrder(mock);
    mock.oneArg(true);
    mock.oneArg(false);
    inOrder.verify(mock).oneArg(false);
    try {
        inOrder.verify(mock).oneArg(true);
        fail();
    } catch (VerificationInOrderFailure e) {
        Assertions.assertThat(e).has(firstMethodInStackTrace("shouldFilterStacktraceWhenVerifyingInOrder"));
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 3 with VerificationInOrderFailure

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

the class FindingRedundantInvocationsInOrderTest method shouldFailToVerifyNoMoreInteractionsInOrder.

@Test
public void shouldFailToVerifyNoMoreInteractionsInOrder() throws Exception {
    //when
    mock.simpleMethod();
    mock.simpleMethod(10);
    mock.otherMethod();
    //then
    InOrder inOrder = inOrder(mock);
    inOrder.verify(mock).simpleMethod(10);
    try {
        inOrder.verifyNoMoreInteractions();
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 4 with VerificationInOrderFailure

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

the class FindingRedundantInvocationsInOrderTest method shouldFailToVerifyNoMoreInteractionsInOrderWithMultipleMocks.

@Test
public void shouldFailToVerifyNoMoreInteractionsInOrderWithMultipleMocks() throws Exception {
    //when
    mock.simpleMethod();
    mock2.simpleMethod();
    mock.otherMethod();
    //then
    InOrder inOrder = inOrder(mock, mock2);
    inOrder.verify(mock2).simpleMethod();
    try {
        inOrder.verifyNoMoreInteractions();
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
Also used : InOrder(org.mockito.InOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 5 with VerificationInOrderFailure

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

the class SelectedMocksInOrderVerificationTest method shouldThrowTooLittleInvocationsForMockTwo.

@Test
public void shouldThrowTooLittleInvocationsForMockTwo() {
    InOrder inOrder = inOrder(mockTwo);
    try {
        inOrder.verify(mockTwo, times(4)).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