use of org.mockito.MockitoSession in project dexmaker by linkedin.
the class VerifyStatic method verifyWithIgnoreStubs.
@Test
public void verifyWithIgnoreStubs() throws Exception {
MockitoSession session = mockitoSession().spyStatic(EchoClass.class).startMocking();
try {
// 'ignoreStubs' only ignore stubs
when(EchoClass.echo("marco!")).thenReturn("polo");
assertEquals("polo", EchoClass.echo("marco!"));
assertEquals("echo", EchoClass.echo("echo"));
verify(() -> {
return EchoClass.echo(eq("echo"));
});
verifyNoMoreInteractions(ignoreStubs(staticMockMarker(EchoClass.class)));
} finally {
session.finishMocking();
}
}
use of org.mockito.MockitoSession 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();
}
}
use of org.mockito.MockitoSession in project mockito by mockito.
the class DefaultMockitoSessionBuilderTest method uses_logger_and_strictness.
@Test
public void uses_logger_and_strictness() {
TestClass testClass = new TestClass();
final List<String> hints = new ArrayList<String>();
MockitoSession session = new DefaultMockitoSessionBuilder().initMocks(testClass).strictness(WARN).logger(new MockitoSessionLogger() {
@Override
public void log(String hint) {
hints.add(hint);
}
}).startMocking();
when(testClass.set.add(1)).thenReturn(true);
session.finishMocking();
assertFalse(hints.isEmpty());
}
use of org.mockito.MockitoSession in project mockito by mockito.
the class MockitoExtension method beforeEach.
/**
* Callback that is invoked <em>before</em> each test is invoked.
*
* @param context the current extension context; never {@code null}
*/
@Override
public void beforeEach(final ExtensionContext context) {
List<Object> testInstances = context.getRequiredTestInstances().getAllInstances();
Strictness actualStrictness = this.retrieveAnnotationFromTestClasses(context).map(MockitoSettings::strictness).orElse(strictness);
MockitoSession session = Mockito.mockitoSession().initMocks(testInstances.toArray()).strictness(actualStrictness).logger(new MockitoSessionLoggerAdapter(Plugins.getMockitoLogger())).startMocking();
context.getStore(MOCKITO).put(MOCKS, new HashSet<>());
context.getStore(MOCKITO).put(SESSION, session);
}
use of org.mockito.MockitoSession in project dexmaker by linkedin.
the class MockStatic method doReturnSpyHasNoSideEffect.
@Test
public void doReturnSpyHasNoSideEffect() throws Exception {
MockitoSession session = mockitoSession().spyStatic(SubClass.class).startMocking();
try {
SubClass.recorded = null;
SubClass.record("no sideeffect");
assertEquals("no sideeffect", SubClass.recorded);
doReturn("faceRecord").when(() -> SubClass.record(eq("test")));
// Verify that there was no side effect as the lambda gets intercepted
assertEquals("no sideeffect", SubClass.recorded);
assertEquals("faceRecord", SubClass.record("test"));
// Verify that there was no side effect as the method is stubbed
assertEquals("no sideeffect", SubClass.recorded);
} finally {
session.finishMocking();
}
}
Aggregations