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