Search in sources :

Example 1 with MockitoFramework

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));
}
Also used : JUnitCore(org.junit.runner.JUnitCore) MockitoFramework(org.mockito.MockitoFramework) Test(org.junit.Test)

Example 2 with MockitoFramework

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);
    }
}
Also used : MockitoFramework(org.mockito.MockitoFramework) Test(org.junit.Test)

Example 3 with MockitoFramework

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);
    }
}
Also used : MockitoAssertionError(org.mockito.exceptions.base.MockitoAssertionError) MockitoFramework(org.mockito.MockitoFramework) Test(org.junit.Test)

Example 4 with MockitoFramework

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));
}
Also used : MockitoFramework(org.mockito.MockitoFramework) Method(java.lang.reflect.Method) VerificationMode(org.mockito.verification.VerificationMode) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 MockitoFramework (org.mockito.MockitoFramework)4 Method (java.lang.reflect.Method)1 JUnitCore (org.junit.runner.JUnitCore)1 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)1 VerificationMode (org.mockito.verification.VerificationMode)1