use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class MockHandlerImplTest method should_remove_verification_mode_even_when_invalid_matchers.
@Test
public void should_remove_verification_mode_even_when_invalid_matchers() throws Throwable {
// given
Invocation invocation = new InvocationBuilder().toInvocation();
@SuppressWarnings("rawtypes") MockHandlerImpl<?> handler = new MockHandlerImpl(new MockSettingsImpl());
mockingProgress().verificationStarted(VerificationModeFactory.atLeastOnce());
handler.matchersBinder = new MatchersBinder() {
public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
throw new InvalidUseOfMatchersException();
}
};
try {
// when
handler.handle(invocation);
// then
fail();
} catch (InvalidUseOfMatchersException ignored) {
}
assertNull(mockingProgress().pullVerificationMode());
}
use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_get_results_for_methods_stub_only.
@Test
public void should_get_results_for_methods_stub_only() throws Throwable {
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImplStubOnly.addAnswer(new Returns("simpleMethod"), null);
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImplStubOnly.addAnswer(new ThrowsException(new MyException()), null);
assertEquals("simpleMethod", invocationContainerImplStubOnly.answerTo(simpleMethod));
try {
invocationContainerImplStubOnly.answerTo(differentMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_get_results_for_methods.
@Test
public void should_get_results_for_methods() throws Throwable {
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImpl.addAnswer(new Returns("simpleMethod"), null);
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImpl.addAnswer(new ThrowsException(new MyException()), null);
assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));
try {
invocationContainerImpl.answerTo(differentMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class InvocationContainerImplTest method doShouldBeThreadSafe.
// works 50% of the time
private void doShouldBeThreadSafe(final InvocationContainerImpl c) throws Throwable {
// given
Thread[] t = new Thread[200];
final CountDownLatch starter = new CountDownLatch(200);
for (int i = 0; i < t.length; i++) {
t[i] = new Thread() {
public void run() {
try {
// NOPMD
starter.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
c.setInvocationForPotentialStubbing(new InvocationMatcher(invocation));
c.addAnswer(new Returns("foo"), null);
c.findAnswerFor(invocation);
}
};
t[i].setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
exceptions.add(e);
}
});
t[i].start();
starter.countDown();
}
// when
for (Thread aT : t) {
aT.join();
}
// then
if (exceptions.size() != 0) {
throw exceptions.getFirst();
}
}
use of org.mockito.internal.invocation.InvocationMatcher in project mockito by mockito.
the class InvocationContainerImplTest method should_return_invoked_mock.
@Test
public void should_return_invoked_mock() throws Exception {
container.setInvocationForPotentialStubbing(new InvocationMatcher(invocation));
assertEquals(invocation.getMock(), container.invokedMock());
}
Aggregations