use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationImplTest method shouldTransformArgumentsToMatchers.
@Test
public void shouldTransformArgumentsToMatchers() throws Exception {
Invocation i = new InvocationBuilder().args("foo", new String[] { "bar" }).toInvocation();
List matchers = ArgumentsProcessor.argumentsToMatchers(i.getArguments());
assertEquals(2, matchers.size());
assertEquals(Equals.class, matchers.get(0).getClass());
assertEquals(ArrayEquals.class, matchers.get(1).getClass());
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationImplTest method shouldScreamWhenCallingRealMethodOnInterface.
@Test
public void shouldScreamWhenCallingRealMethodOnInterface() throws Throwable {
//given
Invocation invocationOnInterface = new InvocationBuilder().toInvocation();
try {
//when
invocationOnInterface.callRealMethod();
//then
fail();
} catch (MockitoException e) {
}
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationImplTest method shouldReturnCastedArgumentAt.
@Test
public void shouldReturnCastedArgumentAt() {
//given
int argument = 42;
Invocation invocationOnInterface = new InvocationBuilder().method("twoArgumentMethod").argTypes(int.class, int.class).args(1, argument).toInvocation();
//when
int secondArgument = (Integer) invocationOnInterface.getArgument(1);
//then
assertTrue(secondArgument == argument);
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class ReturnsEmptyValuesTest method verify_empty_Optional_is_returned.
private void verify_empty_Optional_is_returned(String streamFqcn, String optionalFqcn) throws Exception {
Class<?> streamType = getClassOrSkipTest(streamFqcn);
//given
Object stream = mock(streamType);
Object optional = streamType.getMethod("findAny").invoke(stream);
assertNotNull(optional);
assertFalse((Boolean) Class.forName(optionalFqcn).getMethod("isPresent").invoke(optional));
Invocation findAny = this.getLastInvocation();
//when
Object result = values.answer(findAny);
//then
assertEquals(optional, result);
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class ReturnsEmptyValuesTest method should_return_zero_if_mock_is_compared_to_itself.
@Test
public void should_return_zero_if_mock_is_compared_to_itself() {
//given
Date d = mock(Date.class);
d.compareTo(d);
Invocation compareTo = this.getLastInvocation();
//when
Object result = values.answer(compareTo);
//then
assertEquals(0, result);
}
Aggregations