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 forMockingDetails.getStubbings()
.Since 2.10.0 this interface extends
Answer
. Extending Answer is backwards compatible because Stubbing interface is not extensible (seeNotExtensible
). Extending Answer was needed to improve Mockito domain model and simplify the code.- Since:
- 2.2.3
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Invocation
getInvocation()
Returns the method invocation that is stubbed.Strictness
getStrictness()
Informs about theStrictness
level of this stubbing.boolean
wasUsed()
Informs if the stubbing was used
-
-
-
Method Detail
-
getInvocation
Invocation getInvocation()
Returns the method invocation that is stubbed. E.g. in the example stubbingwhen(mock.foo()).thenReturn(true)
the invocation ismock.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 usedWhat does it mean 'used stubbing'? Stubbing like
when(mock.foo()).thenReturn(true)
is considered used when the methodmock.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 theStrictness
level of this stubbing. For more information about setting strictness for stubbings seeMockito.lenient()
.- Since:
- 2.20.0
-
-