• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockito.stubbing;
6 
7 import org.mockito.Incubating;
8 
9 /**
10  * Generic interface to be used for configuring mock's answer for a two argument invocation.
11  *
12  * Answer specifies an action that is executed and a return value that is returned when you interact with the mock.
13  * <p>
14  * Example of stubbing a mock with this custom answer:
15  *
16  * <pre class="code"><code class="java">
17  * import static org.mockito.AdditionalAnswers.answer;
18  *
19  * when(mock.someMethod(anyString(), anyChar())).then(answer(
20  *     new Answer2&lt;String, String, Character&gt;() {
21  *         public String answer(String s, Character c) {
22  *             return s.replace('f', c);
23  *         }
24  * }));
25  *
26  * //Following will print "bar"
27  * System.out.println(mock.someMethod("far", 'b'));
28  * </code></pre>
29  *
30  * @param <T> return type
31  * @param <A0> type of the first argument
32  * @param <A1> type of the second argument
33  * @see Answer
34  */
35 @Incubating
36 public interface Answer2<T, A0, A1> {
37     /**
38      * @param argument0 the first argument.
39      * @param argument1 the second argument.
40      *
41      * @return the value to be returned.
42      *
43      * @throws Throwable the throwable to be thrown
44      */
answer(A0 argument0, A1 argument1)45     T answer(A0 argument0, A1 argument1) throws Throwable;
46 }
47