Search in sources :

Example 86 with Invocation

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

the class AtLeastXNumberOfInvocationsCheckerTest method shouldMarkActualInvocationsAsVerified.

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

Example 87 with Invocation

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

the class AtLeastXNumberOfInvocationsCheckerTest method shouldReportTooLittleInvocations.

@Test
public void shouldReportTooLittleInvocations() {
    //given
    Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
    Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
    exception.expect(TooLittleActualInvocations.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);
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 88 with Invocation

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

the class NumberOfInvocationsCheckerTest method shouldReportNeverWantedButInvoked.

@Test
public void shouldReportNeverWantedButInvoked() throws Exception {
    Invocation first = buildSimpleMethod().toInvocation();
    invocations = asList(first);
    wanted = buildSimpleMethod().toInvocationMatcher();
    exception.expect(NeverWantedButInvoked.class);
    exception.expectMessage("Never wanted here");
    exception.expectMessage("But invoked here");
    exception.expectMessage("" + first.getLocation());
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 0);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 89 with Invocation

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

the class NumberOfInvocationsCheckerTest method shouldMarkInvocationsAsVerified.

@Test
public void shouldMarkInvocationsAsVerified() throws Exception {
    Invocation invocation = buildSimpleMethod().toInvocation();
    assertThat(invocation.isVerified()).isFalse();
    invocations = asList(invocation);
    wanted = buildSimpleMethod().toInvocationMatcher();
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 1);
    assertThat(invocation.isVerified()).isTrue();
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 90 with Invocation

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

the class NumberOfInvocationsInOrderCheckerTest method shouldMarkAsVerifiedInOrder.

@Test
public void shouldMarkAsVerifiedInOrder() throws Exception {
    Invocation invocation = buildSimpleMethod().toInvocation();
    invocations = asList(invocation);
    wanted = buildSimpleMethod().toInvocationMatcher();
    assertThat(context.isVerified(invocation)).isFalse();
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 1, context);
    assertThat(context.isVerified(invocation)).isTrue();
}
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