Search in sources :

Example 31 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class InvocationMatcherTest method should_not_be_similar_if_is_overloaded_but_used_with_the_same_arg.

@Test
public void should_not_be_similar_if_is_overloaded_but_used_with_the_same_arg() throws Exception {
    Method method = IMethods.class.getMethod("simpleMethod", String.class);
    Method overloadedMethod = IMethods.class.getMethod("simpleMethod", Object.class);
    String sameArg = "test";
    InvocationMatcher invocation = new InvocationBuilder().method(method).arg(sameArg).toInvocationMatcher();
    Invocation overloadedInvocation = new InvocationBuilder().method(overloadedMethod).arg(sameArg).toInvocation();
    assertFalse(invocation.hasSimilarMethod(overloadedInvocation));
}
Also used : Invocation(org.mockito.invocation.Invocation) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 32 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class InvocationMatcherTest method should_capture_varargs_as_vararg.

@Test
public void should_capture_varargs_as_vararg() throws Exception {
    //given
    mock.mixedVarargs(1, "a", "b");
    Invocation invocation = getLastInvocation();
    CapturingMatcher m = new CapturingMatcher();
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, Arrays.<ArgumentMatcher>asList(new Equals(1), m));
    //when
    invocationMatcher.captureArgumentsFrom(invocation);
    //then
    Assertions.assertThat(m.getAllValues()).containsExactly("a", "b");
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Invocation(org.mockito.invocation.Invocation) CapturingMatcher(org.mockito.internal.matchers.CapturingMatcher) Test(org.junit.Test)

Example 33 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class InvocationMatcherTest method should_not_be_similar_if_mocks_are_different.

@Test
public void should_not_be_similar_if_mocks_are_different() throws Exception {
    Invocation onDifferentMock = new InvocationBuilder().simpleMethod().mock("different mock").toInvocation();
    assertFalse(simpleMethod.hasSimilarMethod(onDifferentMock));
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 34 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class InvocationMatcherTest method should_create_from_invocations.

@Test
public void should_create_from_invocations() throws Exception {
    //given
    Invocation i = new InvocationBuilder().toInvocation();
    //when
    List<InvocationMatcher> out = InvocationMatcher.createFrom(asList(i));
    //then
    assertEquals(1, out.size());
    assertEquals(i, out.get(0).getInvocation());
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 35 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class InvocationsFinderTest method shouldReturnAllChunksWhenWantedCountDoesntMatch.

@Test
public void shouldReturnAllChunksWhenWantedCountDoesntMatch() throws Exception {
    Invocation simpleMethodInvocationThree = new InvocationBuilder().mock(mock).toInvocation();
    invocations.add(simpleMethodInvocationThree);
    List<Invocation> chunk = InvocationsFinder.findMatchingChunk(invocations, new InvocationMatcher(simpleMethodInvocation), 1, context);
    Assertions.assertThat(chunk).containsSequence(simpleMethodInvocation, simpleMethodInvocationTwo, simpleMethodInvocationThree);
}
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