Search in sources :

Example 1 with StaticInOrder

use of com.android.dx.mockito.inline.extended.StaticInOrder in project dexmaker by linkedin.

the class MockInstanceUsingExtendedMockito method verifyInOrder.

@Test
public void verifyInOrder() throws Exception {
    TestClass t = mock(TestClass.class);
    assertNull(t.echo("mocked"));
    when(t.echo(eq("stubbed"))).thenReturn("B");
    assertEquals("B", t.echo("stubbed"));
    StaticInOrder inOrder = ExtendedMockito.inOrder(t);
    inOrder.verify(t).echo("mocked");
    inOrder.verify(t).echo("stubbed");
}
Also used : StaticInOrder(com.android.dx.mockito.inline.extended.StaticInOrder) Test(org.junit.Test)

Example 2 with StaticInOrder

use of com.android.dx.mockito.inline.extended.StaticInOrder in project dexmaker by linkedin.

the class VerifyStatic method verifyBadOrder.

@Test(expected = VerificationInOrderFailure.class)
public void verifyBadOrder() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(EchoClass.class).startMocking();
    try {
        EchoClass.echo("marco!");
        EchoClass.echo("polo");
        StaticInOrder echoInOrder = inOrder(staticMockMarker(EchoClass.class));
        echoInOrder.verify(() -> EchoClass.echo(eq("polo")));
        echoInOrder.verify(() -> EchoClass.echo(eq("marco!")));
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) StaticInOrder(com.android.dx.mockito.inline.extended.StaticInOrder) Test(org.junit.Test)

Example 3 with StaticInOrder

use of com.android.dx.mockito.inline.extended.StaticInOrder in project dexmaker by linkedin.

the class VerifyStatic method verifyBadMatcher.

@Test
public void verifyBadMatcher() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(EchoClass.class).startMocking();
    try {
        EchoClass.echo("marco!");
        EchoClass.echo("polo");
        StaticInOrder echoInOrder = inOrder(staticMockMarker(EchoClass.class));
        echoInOrder.verify(() -> EchoClass.echo(eq("marco!")));
        try {
            echoInOrder.verify(() -> EchoClass.echo(eq("badMarker")));
            fail();
        } catch (VerificationInOrderFailure e) {
            assertTrue(e.getMessage(), e.getMessage().contains("badMarker"));
        }
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) StaticInOrder(com.android.dx.mockito.inline.extended.StaticInOrder) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 4 with StaticInOrder

use of com.android.dx.mockito.inline.extended.StaticInOrder in project dexmaker by linkedin.

the class VerifyStatic method verifyInOrder.

@Test
public void verifyInOrder() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(EchoClass.class).mockStatic(ConsumeClass.class).startMocking();
    try {
        EchoClass.echo("marco!");
        ConsumeClass.consume("donuts");
        ConsumeClass.consume("nougat");
        EchoClass.echo("polo");
        StaticInOrder echoInOrder = inOrder(staticMockMarker(EchoClass.class));
        echoInOrder.verify(() -> EchoClass.echo(eq("marco!")));
        echoInOrder.verify(() -> EchoClass.echo(eq("polo")));
        echoInOrder.verifyNoMoreInteractions();
        StaticInOrder consumeInOrder = inOrder(staticMockMarker(ConsumeClass.class));
        consumeInOrder.verify(() -> ConsumeClass.consume(eq("donuts")));
        consumeInOrder.verify(() -> ConsumeClass.consume(eq("nougat")));
        consumeInOrder.verifyNoMoreInteractions();
        StaticInOrder combinedInOrder = inOrder(staticMockMarker(EchoClass.class, ConsumeClass.class));
        combinedInOrder.verify(() -> EchoClass.echo(eq("marco!")));
        combinedInOrder.verify(() -> ConsumeClass.consume(eq("donuts")));
        combinedInOrder.verify(() -> ConsumeClass.consume(eq("nougat")));
        combinedInOrder.verify(() -> EchoClass.echo(eq("polo")));
        combinedInOrder.verifyNoMoreInteractions();
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) StaticInOrder(com.android.dx.mockito.inline.extended.StaticInOrder) Test(org.junit.Test)

Aggregations

StaticInOrder (com.android.dx.mockito.inline.extended.StaticInOrder)4 Test (org.junit.Test)4 MockitoSession (org.mockito.MockitoSession)3 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)1