Search in sources :

Example 21 with MockitoSession

use of org.mockito.MockitoSession in project dexmaker by linkedin.

the class Stress method stressFinalStaticMethod.

@Test
public void stressFinalStaticMethod() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(SuperClass.class).startMocking();
    try {
        assertNull(SuperClass.returnD());
        for (int i = 0; i < 1000; i++) {
            when(SuperClass.returnD()).thenReturn("fakeD");
            assertEquals("fakeD", SuperClass.returnD());
            reset(staticMockMarker(SuperClass.class));
            assertNull(SuperClass.returnD());
            if (i % 100 == 0) {
                Log.i(LOG_TAG, "Ran " + i + " tests");
            }
        }
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) Test(org.junit.Test)

Example 22 with MockitoSession

use of org.mockito.MockitoSession in project dexmaker by linkedin.

the class VerifyStatic method verifySpiedStringMethod.

@Test
public void verifySpiedStringMethod() throws Exception {
    MockitoSession session = mockitoSession().spyStatic(EchoClass.class).startMocking();
    try {
        assertEquals("marco!", EchoClass.echo("marco!"));
        ArgumentCaptor<String> echoCaptor = ArgumentCaptor.forClass(String.class);
        verify(() -> {
            return EchoClass.echo(echoCaptor.capture());
        });
        assertEquals("marco!", echoCaptor.getValue());
        verifyNoMoreInteractions(staticMockMarker(EchoClass.class));
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) Test(org.junit.Test)

Example 23 with MockitoSession

use of org.mockito.MockitoSession in project dexmaker by linkedin.

the class VerifyStatic method zeroInvocationsThrowsIfThereWasAnInvocation.

@Test(expected = NoInteractionsWanted.class)
public void zeroInvocationsThrowsIfThereWasAnInvocation() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(EchoClass.class).startMocking();
    try {
        EchoClass.echo("marco!");
        verifyZeroInteractions(staticMockMarker(EchoClass.class));
        fail();
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) Test(org.junit.Test)

Example 24 with MockitoSession

use of org.mockito.MockitoSession in project dexmaker by linkedin.

the class VerifyStatic method verifyMockedStringMethod.

@Test
public void verifyMockedStringMethod() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(EchoClass.class).startMocking();
    try {
        assertNull(EchoClass.echo("marco!"));
        ArgumentCaptor<String> echoCaptor = ArgumentCaptor.forClass(String.class);
        verify(() -> {
            return EchoClass.echo(echoCaptor.capture());
        });
        assertEquals("marco!", echoCaptor.getValue());
        verifyNoMoreInteractions(staticMockMarker(EchoClass.class));
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) Test(org.junit.Test)

Example 25 with MockitoSession

use of org.mockito.MockitoSession 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)

Aggregations

MockitoSession (org.mockito.MockitoSession)31 Test (org.junit.Test)30 StaticInOrder (com.android.dx.mockito.inline.extended.StaticInOrder)3 ContentResolver (android.content.ContentResolver)2 ArrayList (java.util.ArrayList)1 MockingDetails (org.mockito.MockingDetails)1 MissingMethodInvocationException (org.mockito.exceptions.misusing.MissingMethodInvocationException)1 UnnecessaryStubbingException (org.mockito.exceptions.misusing.UnnecessaryStubbingException)1 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)1 MockitoSessionLoggerAdapter (org.mockito.internal.session.MockitoSessionLoggerAdapter)1 Strictness (org.mockito.quality.Strictness)1 MockitoSessionLogger (org.mockito.session.MockitoSessionLogger)1