• 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 import org.mockito.Incubating;
8 import org.mockito.MockingDetails;
9 import org.mockito.Mockito;
10 import org.mockito.NotExtensible;
11 import org.mockito.invocation.Invocation;
12 import org.mockito.quality.Strictness;
13 
14 /**
15  * Stubbing declared on the mock object.
16  * See detailed description including sample code and use cases see javadoc for {@link MockingDetails#getStubbings()}.
17  * <p>
18  * Since 2.10.0 this interface extends {@link Answer}.
19  * Extending Answer is backwards compatible because Stubbing interface is not extensible (see {@link NotExtensible}).
20  * Extending Answer was needed to improve Mockito domain model and simplify the code.
21  *
22  * @since 2.2.3
23  */
24 @NotExtensible
25 public interface Stubbing extends Answer {
26 
27     /**
28      * Returns the method invocation that is stubbed.
29      * E.g. in the example stubbing <code>when(mock.foo()).thenReturn(true)</code>
30      * the invocation is <code>mock.foo()</code>.
31      * <p>
32      * The invocation instance is mutable.
33      * It is not recommended to modify the state of invocation because it will influence mock behavior.
34      * <p>
35      * To understand how this method is useful, see the description at {@link MockingDetails#getStubbings()}.
36      *
37      * @since 2.2.3
38      */
getInvocation()39     Invocation getInvocation();
40 
41     /**
42      * Informs if the stubbing was used
43      * <p>
44      * What does it mean 'used stubbing'?
45      * Stubbing like <code>when(mock.foo()).thenReturn(true)</code> is considered used
46      * when the method <code>mock.foo()</code> is actually invoked during the execution of code under test.
47      * <p>
48      * This method is used internally by Mockito to report and detect unused stubbings.
49      * Unused stubbings are dead code and should be deleted to increase clarity of tests (see {@link org.mockito.quality.MockitoHint}.
50      * <p>
51      * To understand how this method is useful, see the description at {@link MockingDetails#getStubbings()}.
52      *
53      * @since 2.2.3
54      */
wasUsed()55     boolean wasUsed();
56 
57     /**
58      * Informs about the {@link Strictness} level of this stubbing.
59      * For more information about setting strictness for stubbings see {@link Mockito#lenient()}.
60      *
61      * @since 2.20.0
62      */
63     @Incubating
getStrictness()64     Strictness getStrictness();
65 }
66