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);
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations