use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_has_wrong_return_type.
@Test
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_has_wrong_return_type() {
Invocation dumb_invocation = new InvocationBuilder().toInvocation();
IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
assertThatThrownBy(() -> {
throw Reporter.delegatedMethodHasWrongReturnType(dumb_invocation.getMethod(), dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}).isInstanceOf(MockitoException.class).hasMessageContainingAll("Methods called on delegated instance must have compatible return types with the mock.", "When calling: public abstract java.lang.String org.mockitousage.IMethods.simpleMethod() on mock: iMethods", "return type should be: String, but was: String", "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods", "(delegate instance had type: Class)");
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_invalid_argument_position.
@Test
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_invalid_argument_position() {
Invocation invocation_with_bogus_default_answer = new InvocationBuilder().mock(mock(IMethods.class, new Returns(false))).toInvocation();
assertThatThrownBy(() -> {
throw Reporter.invalidArgumentPositionRangeAtInvocationTime(invocation_with_bogus_default_answer, true, 0);
}).isInstanceOf(MockitoException.class).hasMessageContainingAll("Invalid argument index for the current invocation of method :", " -> iMethods.simpleMethod()", "Last parameter wanted but the method has no arguments.");
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists.
@Test
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists() {
Invocation dumb_invocation = new InvocationBuilder().toInvocation();
IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
assertThatThrownBy(() -> {
throw Reporter.delegatedMethodDoesNotExistOnDelegate(dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}).isInstanceOf(MockitoException.class).hasMessageContainingAll("Methods called on mock must exist in delegated instance.", "When calling: public abstract java.lang.String org.mockitousage.IMethods.simpleMethod() on mock: iMethods", "no such method was found.", "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods", "(delegate instance had type: Class)");
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class InvocationInfoExceptionTest method should_know_valid_throwables.
@Test
public void should_know_valid_throwables() throws Exception {
// when
final Invocation invocation = new InvocationBuilder().method(methodName).mockClass(CurrentClass.class).toInvocation();
final 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_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