use of org.mockito.MockitoFramework in project mockito by mockito.
the class VerificationListenerCallBackTest method should_call_verification_listeners.
@Test
public void should_call_verification_listeners() {
//given
RememberingListener listener = new RememberingListener();
MockitoFramework mockitoFramework = Mockito.framework();
mockitoFramework.addListener(listener);
JUnitCore runner = new JUnitCore();
//when
runner.run(VerificationListenerSample.class);
//then
assertThat(listener.mock).isNotNull();
assertThat(listener.mode).isEqualToComparingFieldByField(times(1));
}
use of org.mockito.MockitoFramework in project mockito by mockito.
the class VerificationListenerCallBackTest method should_notify_when_verification_throws_runtime_exception.
@Test
public void should_notify_when_verification_throws_runtime_exception() {
//given
RememberingListener listener = new RememberingListener();
MockitoFramework mockitoFramework = Mockito.framework();
mockitoFramework.addListener(listener);
Foo foo = mock(Foo.class);
//when
try {
verify(foo, new RuntimeExceptionVerificationMode()).doSomething("");
fail("Exception expected.");
} catch (Throwable e) {
//then
assertThat(listener.cause).isInstanceOf(RuntimeException.class);
}
}
use of org.mockito.MockitoFramework in project mockito by mockito.
the class VerificationListenerCallBackTest method should_notify_when_verification_throws_type_error.
@Test
public void should_notify_when_verification_throws_type_error() {
//given
RememberingListener listener = new RememberingListener();
MockitoFramework mockitoFramework = Mockito.framework();
mockitoFramework.addListener(listener);
Foo foo = mock(Foo.class);
//when
try {
verify(foo).doSomething("");
fail("Exception expected.");
} catch (Throwable e) {
//then
assertThat(listener.cause).isInstanceOf(MockitoAssertionError.class);
}
}
use of org.mockito.MockitoFramework in project mockito by mockito.
the class VerificationListenerCallBackTest method should_call_single_listener_on_verify.
@Test
public void should_call_single_listener_on_verify() throws NoSuchMethodException {
//given
RememberingListener listener = new RememberingListener();
MockitoFramework mockitoFramework = Mockito.framework();
mockitoFramework.addListener(listener);
Method invocationWanted = Foo.class.getDeclaredMethod("doSomething", String.class);
Foo foo = mock(Foo.class);
//when
VerificationMode never = never();
verify(foo, never).doSomething("");
//then
assertThat(listener).is(notifiedFor(foo, never, invocationWanted));
}
Aggregations