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_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 ReturnsTest method should_allow_correct_type_of_return_value.
@Test
public void should_allow_correct_type_of_return_value() {
new Returns("one").validateFor(new InvocationBuilder().simpleMethod().toInvocation());
new Returns(false).validateFor(new InvocationBuilder().method("booleanReturningMethod").toInvocation());
new Returns(TRUE).validateFor(new InvocationBuilder().method("booleanObjectReturningMethod").toInvocation());
new Returns(1).validateFor(new InvocationBuilder().method("integerReturningMethod").toInvocation());
new Returns(1L).validateFor(new InvocationBuilder().method("longReturningMethod").toInvocation());
new Returns(1L).validateFor(new InvocationBuilder().method("longObjectReturningMethod").toInvocation());
new Returns(null).validateFor(new InvocationBuilder().method("objectReturningMethodNoArgs").toInvocation());
new Returns(1).validateFor(new InvocationBuilder().method("objectReturningMethodNoArgs").toInvocation());
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class AnswersWithDelayTest method should_delay.
@Test
public void should_delay() throws Throwable {
final long sleepyTime = 500L;
final AnswersWithDelay testSubject = new AnswersWithDelay(sleepyTime, new Returns("value"));
final Date before = new Date();
testSubject.answer(new InvocationBuilder().method("oneArg").arg("A").toInvocation());
final Date after = new Date();
final long timePassed = after.getTime() - before.getTime();
assertThat(timePassed).isCloseTo(sleepyTime, within(15L));
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class StubbingArgMismatchesTest method multiple_matching_invocations_per_stub_plus_some_other_invocation.
@Test
public void multiple_matching_invocations_per_stub_plus_some_other_invocation() throws Exception {
// given
Invocation stubbing = new InvocationBuilder().args("a").location("-> at A.java").toInvocation();
mismatches.add(new InvocationBuilder().args("x").location("-> at X.java").toInvocation(), stubbing);
mismatches.add(new InvocationBuilder().args("y").location("-> at Y.java").toInvocation(), stubbing);
mismatches.add(new InvocationBuilder().method("differentMethod").args("n").location("-> at N.java").toInvocation(), new InvocationBuilder().method("differentMethod").args("m").location("-> at M.java").toInvocation());
// when
mismatches.format("MyTest.myTestMethod", logger);
// then
assertEquals("[MockitoHint] MyTest.myTestMethod (see javadoc for MockitoHint):\n" + "[MockitoHint] 1. Unused... -> at A.java\n" + "[MockitoHint] ...args ok? -> at X.java\n" + "[MockitoHint] ...args ok? -> at Y.java\n" + "[MockitoHint] 2. Unused... -> at M.java\n" + "[MockitoHint] ...args ok? -> at N.java\n", logger.getLoggedInfo());
}
Aggregations