ResultCaptor implements Answer { public Collection<T> results() { Preconditions.checkState(!capturedResults.isEmpty(), "No result captured, invocation on results() is misleading. Instead, consider to use verify() with never()."); return ImmutableList.copyOf(capturedResults); }  static ResultCaptor<T> resultCaptor(); T result(); Collection<T> results(); @Override T answer(final InvocationOnMock invocationOnMock);  }
@Test public void testGivenNoCapturedValueWhenResultsIsCalledThenIllegalStateExceptionIsThrown() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("No result captured, invocation on results() is misleading. Instead, consider to use verify() with never()."); resultCaptor.results(); }
@Test public void testGivenACapturedValueWhenResultsIsCalledThenReturnAllCapturedValue() throws Exception { returnA.returnSomething(); returnB.returnSomething(); returnA.returnSomething(); assertThat(resultCaptor.results(), IsIterableContainingInOrder.containsInOrder(ImmutableList.of( returnA.returnSomething(), returnB.returnSomething(), returnA.returnSomething() ))); }