use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReturnsArgumentAtTest method should_fail_if_argument_type_of_signature_is_incompatible_with_return_type.
@Test
public void should_fail_if_argument_type_of_signature_is_incompatible_with_return_type() throws Throwable {
try {
new ReturnsArgumentAt(2).validateFor(new InvocationBuilder().method("varargsReturningString").argTypes(Object[].class).args("anyString", new Object(), "anyString").toInvocation());
fail();
} catch (WrongTypeOfReturnValue e) {
assertThat(e.getMessage()).containsIgnoringCase("argument of type").containsIgnoringCase("Object").containsIgnoringCase("varargsReturningString").containsIgnoringCase("should return").containsIgnoringCase("String").containsIgnoringCase("possible argument indexes");
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ReturnsArgumentAtTest method should_allow_possible_argument_types.
@Test
public void should_allow_possible_argument_types() throws Exception {
new ReturnsArgumentAt(0).validateFor(new InvocationBuilder().method("intArgumentReturningInt").argTypes(int.class).arg(1000).toInvocation());
new ReturnsArgumentAt(0).validateFor(new InvocationBuilder().method("toString").argTypes(String.class).arg("whatever").toInvocation());
new ReturnsArgumentAt(2).validateFor(new InvocationBuilder().method("varargsObject").argTypes(int.class, Object[].class).args(1000, "Object", "Object").toInvocation());
new ReturnsArgumentAt(1).validateFor(new InvocationBuilder().method("threeArgumentMethod").argTypes(int.class, Object.class, String.class).args(1000, "Object", "String").toInvocation());
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ThrowsExceptionTest method should_raise_wanted_throwable.
@Test
public void should_raise_wanted_throwable() throws Throwable {
try {
new ThrowsException(new IllegalStateException("my dear throwable")).answer(new InvocationBuilder().method("canThrowException").toInvocation());
Assertions.fail("should have raised wanted exception");
} catch (Throwable throwable) {
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("my dear throwable");
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ThrowsExceptionTest method should_throw_mock_exception_without_stacktrace.
@Test
public void should_throw_mock_exception_without_stacktrace() throws Exception {
try {
new ThrowsException(mock(Exception.class)).answer(new InvocationBuilder().method("canThrowException").toInvocation());
Assertions.fail("should have raised wanted exception");
} catch (Throwable throwable) {
assertThat(throwable.getStackTrace()).describedAs("no stack trace, it's mock").isNull();
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class DefaultRegisteredInvocationsTest method should_not_return_to_string_method.
@Test
public void should_not_return_to_string_method() throws Exception {
Invocation toString = new InvocationBuilder().method("toString").toInvocation();
Invocation simpleMethod = new InvocationBuilder().simpleMethod().toInvocation();
invocations.add(toString);
invocations.add(simpleMethod);
assertTrue(invocations.getAll().contains(simpleMethod));
assertFalse(invocations.getAll().contains(toString));
}
Aggregations