Search in sources :

Example 6 with MockitoSession

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

the class MockStatic method atLeastOneMethodCallDuringStubbing.

@Test
public void atLeastOneMethodCallDuringStubbing() throws Exception {
    Exception atLeastOneMethodCallException = null;
    try {
        MockitoSession session = mockitoSession().spyStatic(SuperClass.class).startMocking();
        try {
            try {
                doReturn("").when(() -> {
                });
                fail();
            } catch (IllegalArgumentException expected) {
                atLeastOneMethodCallException = expected;
            }
        } finally {
            session.finishMocking();
        }
    } catch (Throwable ignored) {
    // We don't want to test exceptions form MockitoSession
    }
    assertNotNull(atLeastOneMethodCallException);
}
Also used : MockitoSession(org.mockito.MockitoSession) MissingMethodInvocationException(org.mockito.exceptions.misusing.MissingMethodInvocationException) Test(org.junit.Test)

Example 7 with MockitoSession

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

the class MockStatic method clearInvocationsRemovedInvocations.

@Test
public void clearInvocationsRemovedInvocations() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(SuperClass.class).startMocking();
    try {
        SuperClass.returnB();
        clearInvocations(staticMockMarker(SuperClass.class));
        verifyZeroInteractions(staticMockMarker(SuperClass.class));
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) Test(org.junit.Test)

Example 8 with MockitoSession

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

the class Stress method stressStaticMethod.

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

Example 9 with MockitoSession

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

the class VerifyStatic method verifyWithTwoMocks.

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

Example 10 with MockitoSession

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

the class VerifyStatic method verifyMockedVoidMethod.

@Test
public void verifyMockedVoidMethod() throws Exception {
    MockitoSession session = mockitoSession().mockStatic(ConsumeClass.class).startMocking();
    try {
        ConsumeClass.consume("donut");
        ArgumentCaptor<String> yumCaptor = ArgumentCaptor.forClass(String.class);
        verify(() -> ConsumeClass.consume(yumCaptor.capture()));
        verifyNoMoreInteractions(staticMockMarker(ConsumeClass.class));
    } finally {
        session.finishMocking();
    }
}
Also used : MockitoSession(org.mockito.MockitoSession) 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