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 single 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())).then(answer( 20 * new Answer1<Integer, String>() { 21 * public Integer answer(String arg) { 22 * return arg.length(); 23 * } 24 * })); 25 * 26 * //Following will print "3" 27 * System.out.println(mock.someMethod("foo")); 28 * </code></pre> 29 * 30 * @param <T> return type 31 * @param <A0> type of the single argument 32 * @see Answer 33 */ 34 @Incubating 35 public interface Answer1<T, A0> { 36 /** 37 * @param argument0 the single argument. 38 * 39 * @return the value to be returned. 40 * 41 * @throws Throwable the throwable to be thrown 42 */ answer(A0 argument0)43 T answer(A0 argument0) throws Throwable; 44 } 45