org.mockito.stubbing
Interface Answer<T>
- Type Parameters:
T - the type to return.
- All Known Implementing Classes:
- DoesNothing, Returns, StubbedInvocationMatcher, ThrowsException
public interface Answer<T>
Generic interface for stubbing methods with callbacks.
Example:
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"));
answer
T answer(InvocationOnMock invocation)
throws java.lang.Throwable
- Parameters:
invocation - the invocation on the mock.
- Returns:
- the value to be returned
- Throws:
java.lang.Throwable - the throwable to be thrown