• 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 that returns nothing.
9  *
10  * Answer specifies an action that is executed 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.answerVoid;
16  *
17  * doAnswer(answerVoid(
18  *     new VoidAnswer2&lt;String, Integer&gt;() {
19  *         public void answer(String msg, Integer count) throws Exception {
20  *             throw new Exception(String.format(msg, count));
21  *         }
22  * })).when(mock).someMethod(anyString(), anyInt());
23  *
24  * //Following will raise an exception with the message "boom 3"
25  * mock.someMethod("boom %d", 3);
26  * </code></pre>
27  *
28  * @param <A0> type of the first argument
29  * @param <A1> type of the second argument
30  * @see Answer
31  */
32 public interface VoidAnswer2<A0, A1> {
33     /**
34      * @param argument0 the first argument.
35      * @param argument1 the second argument.
36      *
37      * @throws Throwable the throwable to be thrown
38      */
answer(A0 argument0, A1 argument1)39     void answer(A0 argument0, A1 argument1) throws Throwable;
40 }
41