Search in sources :

Example 16 with Invocation

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());
}
Also used : Invocation(org.mockito.invocation.Invocation) List(java.util.List) Test(org.junit.Test)

Example 17 with Invocation

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) {
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 18 with Invocation

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);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 19 with Invocation

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);
}
Also used : Invocation(org.mockito.invocation.Invocation)

Example 20 with Invocation

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);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Aggregations

Invocation (org.mockito.invocation.Invocation)106 Test (org.junit.Test)71 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)28 MatchableInvocation (org.mockito.invocation.MatchableInvocation)19 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)11 Location (org.mockito.invocation.Location)7 InvocationsFinder.getLastLocation (org.mockito.internal.invocation.InvocationsFinder.getLastLocation)6 Returns (org.mockito.internal.stubbing.answers.Returns)6 VerificationDataInOrderImpl (org.mockito.internal.verification.api.VerificationDataInOrderImpl)6 Method (java.lang.reflect.Method)5 Discrepancy (org.mockito.internal.reporting.Discrepancy)4 MissingInvocationChecker.checkMissingInvocation (org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation)4 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)3 InvocationsFinder.findFirstMatchingUnverifiedInvocation (org.mockito.internal.invocation.InvocationsFinder.findFirstMatchingUnverifiedInvocation)3 InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)3 IMethods (org.mockitousage.IMethods)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LinkedList (java.util.LinkedList)2 TestCase.assertEquals (junit.framework.TestCase.assertEquals)2 MockingDetails (org.mockito.MockingDetails)2