Interface Stubbing

All Superinterfaces:
Answer

@NotExtensible public interface Stubbing extends Answer
Stubbing declared on the mock object. See detailed description including sample code and use cases see javadoc for MockingDetails.getStubbings().

Since 2.10.0 this interface extends Answer. Extending Answer is backwards compatible because Stubbing interface is not extensible (see NotExtensible). Extending Answer was needed to improve Mockito domain model and simplify the code.

Since:
2.2.3
  • Method Details

    • getInvocation

      Invocation getInvocation()
      Returns the method invocation that is stubbed. E.g. in the example stubbing when(mock.foo()).thenReturn(true) the invocation is mock.foo().

      The invocation instance is mutable. It is not recommended to modify the state of invocation because it will influence mock behavior.

      To understand how this method is useful, see the description at MockingDetails.getStubbings().

      Since:
      2.2.3
    • wasUsed

      boolean wasUsed()
      Informs if the stubbing was used

      What does it mean 'used stubbing'? Stubbing like when(mock.foo()).thenReturn(true) is considered used when the method mock.foo() is actually invoked during the execution of code under test.

      This method is used internally by Mockito to report and detect unused stubbings. Unused stubbings are dead code and should be deleted to increase clarity of tests (see MockitoHint.

      To understand how this method is useful, see the description at MockingDetails.getStubbings().

      Since:
      2.2.3
    • getStrictness

      Strictness getStrictness()
      Informs about the Strictness level of this stubbing. For more information about setting strictness for stubbings see Mockito.lenient().
      Since:
      2.20.0