use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_validate_throwable_for_void_method.
@Test
public void should_validate_throwable_for_void_method() throws Throwable {
invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new Exception()));
try {
invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
fail();
} catch (MockitoException e) {
}
}
use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_add_throwable_for_void_method.
@Test
public void should_add_throwable_for_void_method() throws Throwable {
invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new MyException()));
invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
try {
invocationContainerImpl.answerTo(simpleMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.internal.invocation.InvocationMatcher 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);
}
use of org.mockito.internal.invocation.InvocationMatcher in project powermock by powermock.
the class PowerMockMatchersBinder method bindMatchers.
public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, final Invocation invocation) {
List<LocalizedMatcher> lastMatchers = argumentMatcherStorage.pullLocalizedMatchers();
validateMatchers(invocation, lastMatchers);
// In Mockito 2.0 LocalizedMatcher no more extend ArgumentMatcher, so new list should be created.
final List<ArgumentMatcher> argumentMatchers = extractArgumentMatchers(lastMatchers);
final InvocationMatcher invocationWithMatchers = new InvocationMatcher(invocation, argumentMatchers) {
@Override
public String toString() {
return invocation.toString();
}
};
return invocationWithMatchers;
}
use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class WarningsFinder method find.
public void find(FindingsListener findingsListener) {
List<Invocation> unusedStubs = new LinkedList<>(this.baseUnusedStubs);
List<InvocationMatcher> allInvocations = new LinkedList<>(this.baseAllInvocations);
Iterator<Invocation> unusedIterator = unusedStubs.iterator();
while (unusedIterator.hasNext()) {
Invocation unused = unusedIterator.next();
Iterator<InvocationMatcher> unstubbedIterator = allInvocations.iterator();
while (unstubbedIterator.hasNext()) {
InvocationMatcher unstubbed = unstubbedIterator.next();
if (unstubbed.hasSimilarMethod(unused)) {
findingsListener.foundStubCalledWithDifferentArgs(unused, unstubbed);
unusedIterator.remove();
unstubbedIterator.remove();
}
}
}
for (Invocation i : unusedStubs) {
findingsListener.foundUnusedStub(i);
}
for (InvocationMatcher i : allInvocations) {
findingsListener.foundUnstubbed(i);
}
}
Aggregations