Search in sources :

Example 56 with Invocation

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

the class ScenarioPrinterTest method shouldPrintInvocations.

@Test
public void shouldPrintInvocations() {
    //given
    Invocation verified = new InvocationBuilder().simpleMethod().verified().toInvocation();
    Invocation unverified = new InvocationBuilder().differentMethod().toInvocation();
    //when
    String out = sp.print((List) asList(verified, unverified));
    //then
    assertThat(out).contains("1. -> at").contains("2. [?]-> at");
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 57 with Invocation

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

the class InvocationsFinderTest method shouldGetLastStackTrace.

@Test
public void shouldGetLastStackTrace() throws Exception {
    Location last = InvocationsFinder.getLastLocation(invocations);
    assertSame(differentMethodInvocation.getLocation(), last);
    assertNull(InvocationsFinder.getLastLocation(Collections.<Invocation>emptyList()));
}
Also used : Invocation(org.mockito.invocation.Invocation) Location(org.mockito.invocation.Location) Test(org.junit.Test)

Example 58 with Invocation

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

the class InvocationsFinderTest method shouldFindFirstSimilarInvocationByName.

@Test
public void shouldFindFirstSimilarInvocationByName() throws Exception {
    Invocation overloadedSimpleMethod = new InvocationBuilder().mock(mock).simpleMethod().arg("test").toInvocation();
    Invocation found = InvocationsFinder.findSimilarInvocation(invocations, new InvocationMatcher(overloadedSimpleMethod));
    assertSame(found, simpleMethodInvocation);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 59 with Invocation

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

the class InvocationsFinderTest method shouldReturnAllChunksWhenModeIsAtLeastOnce.

@Test
public void shouldReturnAllChunksWhenModeIsAtLeastOnce() 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)

Example 60 with Invocation

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

the class InvocationsFinderTest method shouldFindPreviousInOrder.

@Test
public void shouldFindPreviousInOrder() throws Exception {
    Invocation previous = InvocationsFinder.findPreviousVerifiedInOrder(invocations, context);
    assertNull(previous);
    context.markVerified(simpleMethodInvocation);
    context.markVerified(simpleMethodInvocationTwo);
    previous = InvocationsFinder.findPreviousVerifiedInOrder(invocations, context);
    assertSame(simpleMethodInvocationTwo, previous);
}
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