Interface Answer2<T,A0,A1>

Type Parameters:
T - return type
A0 - type of the first argument
A1 - type of the second argument

public interface Answer2<T,A0,A1>
Generic interface to be used for configuring mock's answer for a two 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(), anyChar())).then(answer(
     new Answer2<String, String, Character>() {
         public String answer(String s, Character c) {
             return s.replace('f', c);
         }
 }));

 //Following will print "bar"
 System.out.println(mock.someMethod("far", 'b'));
 
See Also:
  • Method Summary

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

    • answer

      T answer(A0 argument0, A1 argument1) throws Throwable
      Parameters:
      argument0 - the first argument.
      argument1 - the second argument.
      Returns:
      the value to be returned.
      Throws:
      Throwable - the throwable to be thrown