• 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 /**
8  * Generic interface to be used for configuring mock's answer for a two argument invocation.
9  *
10  * Answer specifies an action that is executed and a return value that is returned when you interact with the mock.
11  * <p>
12  * Example of stubbing a mock with this custom answer:
13  *
14  * <pre class="code"><code class="java">
15  * import static org.mockito.AdditionalAnswers.answer;
16  *
17  * when(mock.someMethod(anyString(), anyChar())).then(answer(
18  *     new Answer2&lt;String, String, Character&gt;() {
19  *         public String answer(String s, Character c) {
20  *             return s.replace('f', c);
21  *         }
22  * }));
23  *
24  * //Following will print "bar"
25  * System.out.println(mock.someMethod("far", 'b'));
26  * </code></pre>
27  *
28  * @param <T> return type
29  * @param <A0> type of the first argument
30  * @param <A1> type of the second argument
31  * @see Answer
32  */
33 public interface Answer2<T, A0, A1> {
34     /**
35      * @param argument0 the first argument.
36      * @param argument1 the second argument.
37      *
38      * @return the value to be returned.
39      *
40      * @throws Throwable the throwable to be thrown
41      */
answer(A0 argument0, A1 argument1)42     T answer(A0 argument0, A1 argument1) throws Throwable;
43 }
44