T
- the type to return.public interface Answer<T>
Example of stubbing a mock with custom answer:
when(mock.someMethod(anyString())).thenAnswer(new Answer() { Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); Object mock = invocation.getMock(); return "called with arguments: " + args; } }); //Following prints "called with arguments: foo" System.out.println(mock.someMethod("foo"));
Modifier and Type | Method and Description |
---|---|
T |
answer(InvocationOnMock invocation) |
T answer(InvocationOnMock invocation) throws Throwable
invocation
- the invocation on the mock.Throwable
- the throwable to be thrownCopyright © 2016. All rights reserved.