use of org.mockito.invocation.Invocation in project mockito by mockito.
the class NumberOfInvocationsInOrderCheckerTest method shouldReportWithFirstUndesiredInvocationStackTrace.
@Test
public void shouldReportWithFirstUndesiredInvocationStackTrace() throws Exception {
Invocation first = buildSimpleMethod().toInvocation();
Invocation second = buildSimpleMethod().toInvocation();
Invocation third = buildSimpleMethod().toInvocation();
invocations = asList(first, second, third);
wanted = buildSimpleMethod().toInvocationMatcher();
exception.expect(VerificationInOrderFailure.class);
exception.expectMessage("" + third.getLocation());
NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 2, context);
}
use of org.mockito.invocation.Invocation 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.invocation.Invocation in project mockito by mockito.
the class CallsRealMethodsTest method should_be_OK_when_calling_real_method_on_concrete_class.
@Test
public void should_be_OK_when_calling_real_method_on_concrete_class() throws Throwable {
//given
ArrayList<?> mock = mock(ArrayList.class);
mock.clear();
Invocation invocationOnClass = new MockitoCore().getLastInvocation();
//when
new CallsRealMethods().validateFor(invocationOnClass);
//then no exception is thrown
}
use of org.mockito.invocation.Invocation 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.invocation.Invocation 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