Search in sources :

Example 26 with Invocation

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

the class NoMoreInteractionsTest method shouldVerifyInOrderAndPass.

@Test
public void shouldVerifyInOrderAndPass() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    Invocation i = new InvocationBuilder().toInvocation();
    context.markVerified(i);
    assertTrue(context.isVerified(i));
    //when
    n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
//then no exception is thrown
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl) Test(org.junit.Test)

Example 27 with Invocation

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

the class InvocationMarkerTest method shouldMarkInvocationAsVerified.

@Test
public void shouldMarkInvocationAsVerified() {
    //given
    Invocation i = new InvocationBuilder().toInvocation();
    InvocationMatcher im = new InvocationBuilder().toInvocationMatcher();
    assertFalse(i.isVerified());
    //when
    InvocationMarker.markVerified(Arrays.asList(i), im);
    //then
    assertTrue(i.isVerified());
}
Also used : Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) Test(org.junit.Test)

Example 28 with Invocation

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

the class InvocationMatcherTest method should_not_be_similar_to_verified_invocation.

@Test
public void should_not_be_similar_to_verified_invocation() throws Exception {
    Invocation verified = new InvocationBuilder().simpleMethod().verified().toInvocation();
    assertFalse(simpleMethod.hasSimilarMethod(verified));
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 29 with Invocation

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

the class InvocationMatcherTest method should_be_similar_if_is_overloaded_but_used_with_different_arg.

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

Example 30 with Invocation

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

the class InvocationMatcherTest method should_be_a_citizen_of_hashes.

@Test
public void should_be_a_citizen_of_hashes() throws Exception {
    Invocation invocation = new InvocationBuilder().toInvocation();
    Invocation invocationTwo = new InvocationBuilder().args("blah").toInvocation();
    Map<InvocationMatcher, String> map = new HashMap<InvocationMatcher, String>();
    map.put(new InvocationMatcher(invocation), "one");
    map.put(new InvocationMatcher(invocationTwo), "two");
    assertEquals(2, map.size());
}
Also used : Invocation(org.mockito.invocation.Invocation) HashMap(java.util.HashMap) 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