Search in sources :

Example 1 with MethodsImpl

use of org.mockitousage.MethodsImpl in project mockito by mockito.

the class StubbingWithDelegateTest method null_wrapper_dont_throw_exception_from_org_mockito_package.

@Test
public void null_wrapper_dont_throw_exception_from_org_mockito_package() throws Exception {
    IMethods methods = mock(IMethods.class, delegatesTo(new MethodsImpl()));
    try {
        // real method returns null
        byte b = methods.byteObjectReturningMethod();
        fail();
    } catch (Exception e) {
        assertThat(e.toString()).doesNotContain("org.mockito");
    }
}
Also used : IMethods(org.mockitousage.IMethods) MethodsImpl(org.mockitousage.MethodsImpl) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 2 with MethodsImpl

use of org.mockitousage.MethodsImpl in project mockito by mockito.

the class BDDMockitoTest method should_stub_consecutively_with_call_real_method.

@Test
public void should_stub_consecutively_with_call_real_method() throws Exception {
    MethodsImpl mock = mock(MethodsImpl.class);
    willReturn("foo").willCallRealMethod().given(mock).simpleMethod();
    Assertions.assertThat(mock.simpleMethod()).isEqualTo("foo");
    Assertions.assertThat(mock.simpleMethod()).isEqualTo(null);
}
Also used : MethodsImpl(org.mockitousage.MethodsImpl) Test(org.junit.Test)

Example 3 with MethodsImpl

use of org.mockitousage.MethodsImpl in project mockito by mockito.

the class StubbingUsingDoReturnTest method should_allow_do_call_real_method_in_chained_stubbing.

@Test
public void should_allow_do_call_real_method_in_chained_stubbing() throws Exception {
    MethodsImpl methods = mock(MethodsImpl.class);
    doReturn("A").doCallRealMethod().when(methods).simpleMethod();
    Assertions.assertThat(methods.simpleMethod()).isEqualTo("A");
    Assertions.assertThat(methods.simpleMethod()).isEqualTo(null);
}
Also used : MethodsImpl(org.mockitousage.MethodsImpl) Test(org.junit.Test)

Example 4 with MethodsImpl

use of org.mockitousage.MethodsImpl in project mockito by mockito.

the class StubbingWithDelegateTest method exception_should_be_propagated_from_delegate.

@Test
public void exception_should_be_propagated_from_delegate() throws Exception {
    final RuntimeException failure = new RuntimeException("angry-method");
    IMethods methods = mock(IMethods.class, delegatesTo(new MethodsImpl() {

        @Override
        public String simpleMethod() {
            throw failure;
        }
    }));
    try {
        // delegate throws an exception
        methods.simpleMethod();
        fail();
    } catch (RuntimeException e) {
        assertThat(e).isEqualTo(failure);
    }
}
Also used : IMethods(org.mockitousage.IMethods) MethodsImpl(org.mockitousage.MethodsImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 MethodsImpl (org.mockitousage.MethodsImpl)4 IMethods (org.mockitousage.IMethods)2 MockitoException (org.mockito.exceptions.base.MockitoException)1