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(); } } }
Verification(Object target) { MockUtil mockUtil = new MockUtil(); InternalMockHandler<?> handler = mockUtil.getMockHandler(target); InvocationContainer container = handler.getInvocationContainer(); Field field = ReflectionUtils.findField(container.getClass(), "mockingProgress"); ReflectionUtils.makeAccessible(field); this.progress = (MockingProgress) ReflectionUtils.getField(field, container); }
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; }
public InvocationContainer getInvocationContainer() { return null; }
public InvocationContainer getInvocationContainer() { return invocationContainerImpl; }
public VerificationDataImpl(InvocationContainer invocations, InvocationMatcher wanted) { this.invocations = invocations; this.wanted = wanted; this.assertWantedIsVerifiable(); }
/** * Ignores stubbed methods of given mocks for the sake of verification. * <p> * Other words: all *stubbed* methods of given mocks are made *verfied* so that they don't get in a way during verifyNoMoreInteractions(). * <p> * This method changes the input mocks! This method returns input mocks for convenience. * <p> * Example: * <pre> * //mocking lists for the sake of the example (if you mock List in real you will burn in hell) * List mock1 = mock(List.class), mock2 = mock(List.class); * * //stubbing mocks: * when(mock1.get(0)).thenReturn(10); * when(mock2.get(0)).thenReturn(20); * * //using mocks by calling stubbed get(0) methods: * System.out.println(mock1.get(0)); //prints 10 * System.out.println(mock2.get(0)); //prints 20 * * //using mocks by calling clear() methods: * mock1.clear(); * mock2.clear(); * * //verification: * verify(mock1).clear(); * verify(mock2).clear(); * * //verifyNoMoreInteractions() fails because get() methods were not accounted for. * try { verifyNoMoreInteractions(mock1, mock2); } catch (NoInteractionsWanted e); * * //However, if ignore stubbed methods then we can verifyNoMoreInteractions() * verifyNoMoreInteractions(ignoreStubs(mock1, mock2)); * * //Remember that ignoreStubs() *changes* the input mocks and returns them for convenience. * <pre> * * @param mocks input mocks that will be changed * @return the same mocks that were passed in as parameters */ public static Object[] ignoreStubs(Object... mocks) { for (Object m : mocks) { InvocationContainer invocationContainer = new MockUtil().getMockHandler(m).getInvocationContainer(); List<Invocation> ins = invocationContainer.getInvocations(); for (Invocation in : ins) { InvocationMarker invocationMarker = new InvocationMarker(); if (in.stubInfo() != null) { invocationMarker.markVerified(in, new CapturesArgumensFromInvocation() { public void captureArgumentsFrom(Invocation i) { //don't capture } }); } } } return mocks; }
public InvocationContainer getInvocationContainer() { return mockHandler.getInvocationContainer(); }
public InvocationContainer getInvocationContainer() { return delegate.getInvocationContainer(); }
InvocationContainer getInvocationContainer();