Mockito + Spy: How to gather return values
First thing, you should be passing spy in as the constructor argument. That aside, here’s how you could do it. public class ResultCaptor<T> implements Answer { private T result = null; public T getResult() { return result; } @Override public T answer(InvocationOnMock invocationOnMock) throws Throwable { result = (T) invocationOnMock.callRealMethod(); return result; } } Intended … Read more