1 /*
2  * Copyright (c) 2007 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.Mockito;
8 import org.mockito.internal.progress.IOngoingStubbing;
9 
10 /**
11  * Stubs a method call with return value or an exception. E.g:
12  *
13  * <pre class="code"><code class="java">
14  * stub(mock.someMethod()).toReturn(10);
15  *
16  * //you can use flexible argument matchers, e.g:
17  * stub(mock.someMethod(<b>anyString()</b>)).toReturn(10);
18  *
19  * //setting exception to be thrown:
20  * stub(mock.someMethod("some arg")).toThrow(new RuntimeException());
21  *
22  * //you can stub with different behavior for consecutive method calls.
23  * //Last stubbing (e.g: toReturn("foo")) determines the behavior for further consecutive calls.
24  * stub(mock.someMethod("some arg"))
25  *  .toThrow(new RuntimeException())
26  *  .toReturn("foo");
27  *
28  * </code></pre>
29  *
30  * See examples in javadoc for {@link Mockito#stub}
31  */
32 public interface DeprecatedOngoingStubbing<T> extends IOngoingStubbing {
33 
34     /**
35      * Set a return value for the stubbed method. E.g:
36      * <pre class="code"><code class="java">
37      * stub(mock.someMethod()).toReturn(10);
38      * </code></pre>
39      *
40      * See examples in javadoc for {@link Mockito#stub}
41      *
42      * @param value return value
43      *
44      * @return iOngoingStubbing object that allows stubbing consecutive calls
45      */
toReturn(T value)46     DeprecatedOngoingStubbing<T> toReturn(T value);
47 
48     /**
49      * Set a Throwable to be thrown when the stubbed method is called. E.g:
50      * <pre class="code"><code class="java">
51      * stub(mock.someMethod()).toThrow(new RuntimeException());
52      * </code></pre>
53      *
54      * If throwable is a checked exception then it has to
55      * match one of the checked exceptions of method signature.
56      *
57      * See examples in javadoc for {@link Mockito#stub}
58      *
59      * @param throwable to be thrown on method invocation
60      *
61      * @return iOngoingStubbing object that allows stubbing consecutive calls
62      */
toThrow(Throwable throwable)63     DeprecatedOngoingStubbing<T> toThrow(Throwable throwable);
64 
65     /**
66      * Set a generic Answer for the stubbed method. E.g:
67      * <pre class="code"><code class="java">
68      * stub(mock.someMethod(10)).toAnswer(new Answer&lt;Integer&gt;() {
69      *     public Integer answer(InvocationOnMock invocation) throws Throwable {
70      *         return (Integer) invocation.getArguments()[0];
71      *     }
72      * }
73      * </code></pre>
74      *
75      * @param answer the custom answer to execute.
76      *
77      * @return iOngoingStubbing object that allows stubbing consecutive calls
78      */
toAnswer(Answer<?> answer)79     DeprecatedOngoingStubbing<T> toAnswer(Answer<?> answer);
80 }