Interface Answer<T>

Type Parameters:
T - the type to return.
All Known Implementing Classes:
AnswerReturnValuesAdapter, CallsRealMethods, ClonesArguments, DoesNothing, ForwardsInvocations, GloballyConfiguredAnswer, Returns, ReturnsArgumentAt, ReturnsDeepStubs, ReturnsElementsOf, ReturnsElementsOf, ReturnsEmptyValues, ReturnsMocks, ReturnsMoreEmptyValues, ReturnsSmartNulls, StubbedInvocationMatcher, ThrowsException, ThrowsExceptionClass

public interface Answer<T>

Generic interface to be used for configuring mock's answer. Answer specifies an action that is executed and a return value that is returned when you interact with the mock.

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"

Method Summary
 T answer(InvocationOnMock invocation)

Method Detail


T answer(InvocationOnMock invocation)
         throws java.lang.Throwable
invocation - the invocation on the mock.
the value to be returned
java.lang.Throwable - the throwable to be thrown