ResultCaptor implements Answer { @Override public T answer(final InvocationOnMock invocationOnMock) throws Throwable { T capturedResult = (T) invocationOnMock.callRealMethod(); capturedResults.add(capturedResult); return capturedResult; }  static ResultCaptor<T> resultCaptor(); T result(); Collection<T> results(); @Override T answer(final InvocationOnMock invocationOnMock);  }
@Test public void answer() throws Throwable { String expectedResult = "Hello all!"; when(invocationOnMock.callRealMethod()).thenReturn(expectedResult); String givenResult =resultCaptor.answer(invocationOnMock); verify(invocationOnMock).callRealMethod(); assertThat(givenResult, is(expectedResult)); }