private InvocationContainerImpl getInvocationContainer() { assertGoodMock(); return MockUtil.getInvocationContainer(toInspect); }
/** * Finds all unused stubs for given mocks * * @param mocks full list of mocks */ public List<Invocation> find(List<?> mocks) { List<Invocation> unused = new LinkedList<Invocation>(); for (Object mock : mocks) { List<Stubbing> fromSingleMock = MockUtil.getInvocationContainer(mock).getStubbingsDescending(); for(Stubbing s : fromSingleMock) { if (!s.wasUsed()) { unused.add(s.getInvocation()); } } } return unused; } }
public Object[] ignoreStubs(Object... mocks) { for (Object m : mocks) { InvocationContainerImpl container = getInvocationContainer(m); List<Invocation> ins = container.getInvocations(); for (Invocation in : ins) { if (in.stubInfo() != null) { in.ignoreForVerification(); } } } return mocks; }
@Override public <T> T when(T mock) { if (mock == null) { throw nullPassedToWhenMethod(); } if (!isMock(mock)) { throw notAMockPassedToWhenMethod(); } MockUtil.getInvocationContainer(mock).setAnswersForStubbing(answers, strictness); return mock; }
public <T> void clearInvocations(T... mocks) { MockingProgress mockingProgress = mockingProgress(); mockingProgress.validateState(); mockingProgress.reset(); mockingProgress.resetOngoingStubbing(); for (T m : mocks) { getInvocationContainer(m).clearInvocations(); } }
public void verifyNoMoreInteractions(Object... mocks) { assertMocksNotEmpty(mocks); mockingProgress().validateState(); for (Object mock : mocks) { try { if (mock == null) { throw nullPassedToVerifyNoMoreInteractions(); } InvocationContainerImpl invocations = getInvocationContainer(mock); assertNotStubOnlyMock(mock); VerificationDataImpl data = new VerificationDataImpl(invocations, null); noMoreInteractions().verify(data); } catch (NotAMockException e) { throw notAMockPassedToVerifyNoMoreInteractions(); } } }
private Object deepStub(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata) throws Throwable { InvocationContainerImpl container = MockUtil.getInvocationContainer(invocation.getMock()); // matches invocation for verification // TODO why don't we do container.findAnswer here? for (Stubbing stubbing : container.getStubbingsDescending()) { if (container.getInvocationForStubbing().matches(stubbing.getInvocation())) { return stubbing.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); }