use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class CallsRealMethodsTest method should_delegate_to_returns_default_when_abstract_method.
@Test
public void should_delegate_to_returns_default_when_abstract_method() throws Throwable {
Invocation abstractMethod = new InvocationBuilder().method("booleanReturningMethod").toInvocation();
assertThat(new CallsRealMethods().answer(abstractMethod)).isEqualTo(RETURNS_DEFAULTS.answer(abstractMethod));
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class InvocationInfoTest method should_know_valid_throwables.
@Test
public void should_know_valid_throwables() throws Exception {
//when
Invocation invocation = new InvocationBuilder().method("canThrowException").toInvocation();
InvocationInfo info = new InvocationInfo(invocation);
//then
assertThat(info.isValidException(new Exception())).isFalse();
assertThat(info.isValidException(new CharacterCodingException())).isTrue();
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReturnsArgumentAtTest method should_fail_if_index_is_not_in_range_for_example_with_no_arg_invocation.
@Test
public void should_fail_if_index_is_not_in_range_for_example_with_no_arg_invocation() throws Throwable {
try {
new ReturnsArgumentAt(ReturnsArgumentAt.LAST_ARGUMENT).validateFor(new InvocationBuilder().simpleMethod().toInvocation());
fail();
} catch (MockitoException e) {
assertThat(e.getMessage()).containsIgnoringCase("invalid argument index").containsIgnoringCase("iMethods.simpleMethod").containsIgnoringCase("no arguments").containsIgnoringCase("last parameter wanted");
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReturnsArgumentAtTest method should_identify_bad_parameter_type_for_invocation.
@Test
public void should_identify_bad_parameter_type_for_invocation() throws Exception {
try {
new ReturnsArgumentAt(1).validateFor(new InvocationBuilder().method("varargsReturningString").argTypes(Object[].class).args(new Object(), new Object(), new Object()).toInvocation());
Assertions.fail("should scream");
} catch (WrongTypeOfReturnValue ignored) {
}
try {
new ReturnsArgumentAt(0).validateFor(new InvocationBuilder().method("oneArray").argTypes(boolean[].class).args(true, false, false).toInvocation());
Assertions.fail("should scream");
} catch (WrongTypeOfReturnValue ignored) {
}
try {
new ReturnsArgumentAt(0).validateFor(new InvocationBuilder().method("mixedVarargsReturningString").argTypes(Object.class, String[].class).args(new Object(), new String[] { "A", "B", "C" }).toInvocation());
Assertions.fail("should scream");
} catch (WrongTypeOfReturnValue ignored) {
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReturnsArgumentAtTest method should_handle_returning_vararg_as_array.
@Test
public void should_handle_returning_vararg_as_array() throws Throwable {
Invocation mixedVarargsReturningStringArray = new InvocationBuilder().method("mixedVarargsReturningStringArray").argTypes(Object.class, String[].class).args(new Object(), new String[] { "A", "B", "C" }).toInvocation();
new ReturnsArgumentAt(1).validateFor(mixedVarargsReturningStringArray);
assertThat(new ReturnsArgumentAt(1).answer(mixedVarargsReturningStringArray)).isEqualTo(new String[] { "A", "B", "C" });
Invocation mixedVarargsReturningObjectArray = new InvocationBuilder().method("mixedVarargsReturningStringArray").argTypes(Object.class, String[].class).args(new Object(), new String[] { "A", "B", "C" }).toInvocation();
new ReturnsArgumentAt(1).validateFor(mixedVarargsReturningObjectArray);
assertThat(new ReturnsArgumentAt(1).answer(mixedVarargsReturningObjectArray)).isEqualTo(new String[] { "A", "B", "C" });
}
Aggregations