Search in sources :

Example 16 with InvocationMatcher

use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.

the class NoMoreInteractionsTest method noMoreInteractionsExceptionMessageShouldDescribeMock.

@Test
public void noMoreInteractionsExceptionMessageShouldDescribeMock() {
    // given
    NoMoreInteractions n = new NoMoreInteractions();
    IMethods mock = mock(IMethods.class, "a mock");
    InvocationMatcher i = new InvocationBuilder().mock(mock).toInvocationMatcher();
    InvocationContainerImpl invocations = new InvocationContainerImpl(new MockSettingsImpl());
    invocations.setInvocationForPotentialStubbing(i);
    try {
        // when
        n.verify(new VerificationDataImpl(invocations, null));
        // then
        fail();
    } catch (NoInteractionsWanted e) {
        Assertions.assertThat(e.toString()).contains(mock.toString());
    }
}
Also used : InvocationContainerImpl(org.mockito.internal.stubbing.InvocationContainerImpl) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) NoInteractionsWanted(org.mockito.exceptions.verification.NoInteractionsWanted) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) IMethods(org.mockitousage.IMethods) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 17 with InvocationMatcher

use of org.mockito.internal.invocation.InvocationMatcher 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)

Example 18 with InvocationMatcher

use of org.mockito.internal.invocation.InvocationMatcher 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 19 with InvocationMatcher

use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.

the class AtLeastXNumberOfInvocationsCheckerTest method shouldReportTooFewInvocationsInOrder.

@Test
public void shouldReportTooFewInvocationsInOrder() {
    InOrderContext context = new InOrderContextImpl();
    // given
    Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
    Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
    // when
    assertThatThrownBy(() -> checkAtLeastNumberOfInvocations(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 2, context)).isInstanceOf(VerificationInOrderFailure.class).hasMessageContainingAll("iMethods.simpleMethod();", "Wanted *at least* 2 times", "But was 1 time");
}
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) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 20 with InvocationMatcher

use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.

the class WarningsFinderTest method shouldPrintStubWasUsedWithDifferentArgs.

@Test
public void shouldPrintStubWasUsedWithDifferentArgs() {
    // given
    Invocation stub = new InvocationBuilder().arg("foo").mock(mock).toInvocation();
    InvocationMatcher wrongArg = new InvocationBuilder().arg("bar").mock(mock).toInvocationMatcher();
    // when
    WarningsFinder finder = new WarningsFinder(Arrays.<Invocation>asList(stub), Arrays.<InvocationMatcher>asList(wrongArg));
    finder.find(listener);
    // then
    verify(listener, only()).foundStubCalledWithDifferentArgs(stub, wrongArg);
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Aggregations

InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)25 Test (org.junit.Test)19 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)15 Invocation (org.mockito.invocation.Invocation)13 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)4 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)3 Returns (org.mockito.internal.stubbing.answers.Returns)3 InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)3 InOrderContext (org.mockito.internal.verification.api.InOrderContext)3 MockitoException (org.mockito.exceptions.base.MockitoException)2 NoInteractionsWanted (org.mockito.exceptions.verification.NoInteractionsWanted)2 InvocationContainerImpl (org.mockito.internal.stubbing.InvocationContainerImpl)2 IMethods (org.mockitousage.IMethods)2 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 InvalidUseOfMatchersException (org.mockito.exceptions.misusing.InvalidUseOfMatchersException)1 TooFewActualInvocations (org.mockito.exceptions.verification.TooFewActualInvocations)1 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)1