Search in sources :

Example 1 with InOrderContextImpl

use of org.mockito.internal.verification.InOrderContextImpl in project mockito by mockito.

the class AtLeastXNumberOfInvocationsCheckerTest method shouldReportTooLittleInvocationsInOrder.

@Test
public void shouldReportTooLittleInvocationsInOrder() {
    InOrderContext context = new InOrderContextImpl();
    //given
    Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
    Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
    exception.expect(VerificationInOrderFailure.class);
    exception.expectMessage("iMethods.simpleMethod()");
    exception.expectMessage("Wanted *at least* 2 times");
    exception.expectMessage("But was 1 time");
    //when
    checkAtLeastNumberOfInvocations(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 2, context);
}
Also used : InOrderContextImpl(org.mockito.internal.verification.InOrderContextImpl) Invocation(org.mockito.invocation.Invocation) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) InOrderContext(org.mockito.internal.verification.api.InOrderContext) Test(org.junit.Test)

Example 2 with InOrderContextImpl

use of org.mockito.internal.verification.InOrderContextImpl in project mockito by mockito.

the class InvocationMarkerTest method shouldMarkInvocationsAsVerifiedInOrder.

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

Example 3 with InOrderContextImpl

use of org.mockito.internal.verification.InOrderContextImpl in project mockito by mockito.

the class InvocationsFinderTest method shouldFindFirstUnverifiedInOrderAndRespectSequenceNumber.

@Test
public void shouldFindFirstUnverifiedInOrderAndRespectSequenceNumber() throws Exception {
    //given
    InOrderContextImpl context = new InOrderContextImpl();
    assertSame(simpleMethodInvocation, InvocationsFinder.findFirstUnverifiedInOrder(context, invocations));
    //when
    //skipping verification of first invocation, then:
    context.markVerified(simpleMethodInvocationTwo);
    context.markVerified(differentMethodInvocation);
    //then
    assertSame(null, InvocationsFinder.findFirstUnverifiedInOrder(context, invocations));
}
Also used : InOrderContextImpl(org.mockito.internal.verification.InOrderContextImpl) Test(org.junit.Test)

Example 4 with InOrderContextImpl

use of org.mockito.internal.verification.InOrderContextImpl in project mockito by mockito.

the class InvocationsFinderTest method shouldFindFirstUnverifiedInOrder.

@Test
public void shouldFindFirstUnverifiedInOrder() throws Exception {
    //given
    InOrderContextImpl context = new InOrderContextImpl();
    assertSame(simpleMethodInvocation, InvocationsFinder.findFirstUnverifiedInOrder(context, invocations));
    //when
    context.markVerified(simpleMethodInvocationTwo);
    context.markVerified(simpleMethodInvocation);
    //then
    assertSame(differentMethodInvocation, InvocationsFinder.findFirstUnverifiedInOrder(context, invocations));
    //when
    context.markVerified(differentMethodInvocation);
    //then
    assertNull(InvocationsFinder.findFirstUnverifiedInOrder(context, invocations));
}
Also used : InOrderContextImpl(org.mockito.internal.verification.InOrderContextImpl) Test(org.junit.Test)

Example 5 with InOrderContextImpl

use of org.mockito.internal.verification.InOrderContextImpl in project mockito by mockito.

the class AtLeastXNumberOfInvocationsCheckerTest method shouldMarkActualInvocationsAsVerifiedInOrder.

@Test
public void shouldMarkActualInvocationsAsVerifiedInOrder() {
    InOrderContext context = new InOrderContextImpl();
    //given
    Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
    Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
    //when
    checkAtLeastNumberOfInvocations(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 1, context);
    //then
    assertThat(invocation.isVerified()).isTrue();
}
Also used : InOrderContextImpl(org.mockito.internal.verification.InOrderContextImpl) Invocation(org.mockito.invocation.Invocation) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) InOrderContext(org.mockito.internal.verification.api.InOrderContext) Test(org.junit.Test)

Aggregations

InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)6 Test (org.junit.Test)5 Invocation (org.mockito.invocation.Invocation)3 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)2 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)2 InOrderContext (org.mockito.internal.verification.api.InOrderContext)2 Before (org.junit.Before)1 MatchableInvocation (org.mockito.invocation.MatchableInvocation)1 IMethods (org.mockitousage.IMethods)1