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