Interface Answer1<T,A0>

Type Parameters:
T - return type
A0 - 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

    Modifier and Type
    Method
    Description
    answer(A0 argument0)
     
  • Method Details

    • answer

      T answer(A0 argument0) throws Throwable
      Parameters:
      argument0 - the single argument.
      Returns:
      the value to be returned.
      Throws:
      Throwable - the throwable to be thrown