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());
}
}
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();
}
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();
}
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");
}
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);
}
Aggregations