public InvocationContainer getInvocationContainer() { return delegate.getInvocationContainer(); } }
public InvocationContainer getInvocationContainer() { return mockHandler.getInvocationContainer(); }
/** * gets all invocations from mocks. Invocations are ordered earlier first. * * @param mocks mocks * @return invocations */ public List<Invocation> find(List<?> mocks) { Set<Invocation> invocationsInOrder = new TreeSet<Invocation>(new SequenceNumberComparator()); for (Object mock : mocks) { InternalMockHandler<Object> handler = new MockUtil().getMockHandler(mock); List<Invocation> fromSingleMock = handler.getInvocationContainer().getInvocations(); invocationsInOrder.addAll(fromSingleMock); } return new LinkedList<Invocation>(invocationsInOrder); }
/** * Finds all unused stubs for given mocks * * @param mocks */ public List<Invocation> find(List<?> mocks) { List<Invocation> unused = new LinkedList<Invocation>(); for (Object mock : mocks) { InternalMockHandler<Object> handler = new MockUtil().getMockHandler(mock); List<StubbedInvocationMatcher> fromSingleMock = handler.getInvocationContainer().getStubbedInvocations(); for(StubbedInvocationMatcher s : fromSingleMock) { if (!s.wasUsed()) { unused.add(s.getInvocation()); } } } return unused; } }
public Object[] ignoreStubs(Object... mocks) { for (Object m : mocks) { InvocationContainer invocationContainer = new MockUtil().getMockHandler(m).getInvocationContainer(); List<Invocation> ins = invocationContainer.getInvocations(); for (Invocation in : ins) { if (in.stubInfo() != null) { in.ignoreForVerification(); } } } return mocks; }
private Object getMock(InvocationOnMock invocation) throws Throwable { InternalMockHandler<Object> handler = new 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); } } // deep stub return recordDeepStubMock(invocation, container); }
public void verifyNoMoreInteractions(Object... mocks) { assertMocksNotEmpty(mocks); mockingProgress.validateState(); for (Object mock : mocks) { try { if (mock == null) { reporter.nullPassedToVerifyNoMoreInteractions(); } InvocationContainer invocations = mockUtil.getMockHandler(mock).getInvocationContainer(); VerificationDataImpl data = new VerificationDataImpl(invocations, null); VerificationModeFactory.noMoreInteractions().verify(data); } catch (NotAMockException e) { reporter.notAMockPassedToVerifyNoMoreInteractions(); } } }
@Override public void describeMismatch(Object item, final Description description) { description.appendText("had these: "); for (Invocation invocation : new MockUtil().getMockHandler(item).getInvocationContainer().getInvocations()) description.appendText(invocation.toString()); }
@Override public void destroySingletons() { super.destroySingletons(); int mockedBeansWithoutInvocations = 0; int mockedBeansWithInvocations = 0; MockUtil mockUtil = new MockUtil(); for( Map.Entry<Class, Object> entry : mockedBeans.entrySet() ) { Object mock = entry.getValue(); InvocationContainer container = mockUtil.getMockHandler( mock ).getInvocationContainer(); List<Invocation> invocations = container.getInvocations(); if( invocations.isEmpty() ) { mockedBeansWithoutInvocations++; } else { mockedBeansWithInvocations++; } reset( mock ); } LOG.debug( "*** MockedLoader stats: [" + mockedBeans.size() + "] mocked beans of which [" + mockedBeansWithInvocations + "] with invocations and [" + mockedBeansWithoutInvocations + "] without invocations" ); mockedBeans.clear(); }