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