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