• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.NotExtensible;
9 
10 /**
11  * Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
12  * <p>
13  * Example:
14  * <pre class="code"><code class="java">
15  *   doThrow(new RuntimeException()).when(mockedList).clear();
16  *
17  *   //following throws RuntimeException:
18  *   mockedList.clear();
19  * </code></pre>
20  *
21  * Also useful when stubbing consecutive calls:
22  *
23  * <pre class="code"><code class="java">
24  *   doThrow(new RuntimeException("one")).
25  *   doThrow(new RuntimeException("two"))
26  *   .when(mock).someVoidMethod();
27  * </code></pre>
28  *
29  * Read more about those methods:
30  * <p>
31  * {@link Mockito#doThrow(Throwable[])}
32  * <p>
33  * {@link Mockito#doAnswer(Answer)}
34  * <p>
35  * {@link Mockito#doNothing()}
36  * <p>
37  * {@link Mockito#doReturn(Object)}
38  * <p>
39  *
40  * See examples in javadoc for {@link Mockito}
41  */
42 @SuppressWarnings("unchecked")
43 @NotExtensible
44 public interface Stubber extends BaseStubber {
45 
46     /**
47      * Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
48      * <p>
49      * Example:
50      * <pre class="code"><code class="java">
51      *   doThrow(new RuntimeException())
52      *   .when(mockedList).clear();
53      *
54      *   //following throws RuntimeException:
55      *   mockedList.clear();
56      * </code></pre>
57      *
58      * Read more about those methods:
59      * <p>
60      * {@link Mockito#doThrow(Throwable[])}
61      * <p>
62      * {@link Mockito#doAnswer(Answer)}
63      * <p>
64      * {@link Mockito#doNothing()}
65      * <p>
66      * {@link Mockito#doReturn(Object)}
67      * <p>
68      *
69      * See examples in javadoc for {@link Mockito}
70      *
71      * @param mock The mock
72      * @return select method for stubbing
73      */
when(T mock)74     <T> T when(T mock);
75 }
76