use of org.mockito.internal.stubbing.InvocationContainerImpl in project mockito by mockito.
the class ReturnsDeepStubs method deepStub.
private Object deepStub(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata) throws Throwable {
InternalMockHandler<Object> handler = MockUtil.getMockHandler(invocation.getMock());
InvocationContainerImpl container = (InvocationContainerImpl) handler.getInvocationContainer();
// matches invocation for verification
for (StubbedInvocationMatcher stubbedInvocationMatcher : container.getStubbedInvocations()) {
if (container.getInvocationForStubbing().matches(stubbedInvocationMatcher.getInvocation())) {
return stubbedInvocationMatcher.answer(invocation);
}
}
// record deep stub answer
StubbedInvocationMatcher stubbing = recordDeepStubAnswer(newDeepStubMock(returnTypeGenericMetadata, invocation.getMock()), container);
// deep stubbing creates a stubbing and immediately uses it
// so the stubbing is actually used by the same invocation
stubbing.markStubUsed(stubbing.getInvocation());
return stubbing.answer(invocation);
}
use of org.mockito.internal.stubbing.InvocationContainerImpl 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());
}
}
Aggregations