Package org.mockito.stubbing
Interface Answer1<T,A0>
- Type Parameters:
T
- return typeA0
- type of the single argument
public interface Answer1<T,A0>
Generic interface to be used for configuring mock's answer for a single argument invocation.
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 this custom answer:
import static org.mockito.AdditionalAnswers.answer;
when(mock.someMethod(anyString())).then(answer(
new Answer1<Integer, String>() {
public Integer answer(String arg) {
return arg.length();
}
}));
//Following will print "3"
System.out.println(mock.someMethod("foo"));
- See Also:
-
Method Summary
-
Method Details
-
answer
- Parameters:
argument0
- the single argument.- Returns:
- the value to be returned.
- Throws:
Throwable
- the throwable to be thrown
-