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