Interface MockHandler<T>
-
- All Superinterfaces:
Serializable
public interface MockHandler<T> extends Serializable
Mockito handler of an invocation on a mock. This is a core part of the API, the heart of Mockito. See also theMockMaker
. Handler can be used to programmatically simulate invocations on the mock object.Mockito will provide you with the implementation of this interface via
MockMaker
methods:MockMaker.createMock(MockCreationSettings, MockHandler)
andMockMaker.resetMock(Object, MockHandler, MockCreationSettings)
.You can provide your own implementation of MockHandler but make sure that the right instance is returned by
MockMaker.getHandler(Object)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description InvocationContainer
getInvocationContainer()
Returns the object that holds all invocations on the mock object, including stubbings with declared answers.MockCreationSettings<T>
getMockSettings()
Read-only settings the mock object was created with.Object
handle(Invocation invocation)
Takes an invocation object and handles it.
-
-
-
Method Detail
-
handle
Object handle(Invocation invocation) throws Throwable
Takes an invocation object and handles it.The default implementation provided by Mockito handles invocations by recording method calls on mocks for further verification, captures the stubbing information when mock is stubbed, returns the stubbed values for invocations that have been stubbed, and much more.
- Parameters:
invocation
- The invocation to handle- Returns:
- Result
- Throws:
Throwable
- Throwable
-
getMockSettings
MockCreationSettings<T> getMockSettings()
Read-only settings the mock object was created with. SeeMockito.mock(Class, MockSettings)
- Returns:
- read-only settings of the mock
- Since:
- 2.10.0
-
getInvocationContainer
InvocationContainer getInvocationContainer()
Returns the object that holds all invocations on the mock object, including stubbings with declared answers. Do not provide your own implementation. Returned object is an internal implementation, hidden beneath a public marker interface.Please do not provide your own implementation of
InvocationContainer
interface at this point. If you have a use case that requires your own implementation ofInvocationContainer
please reach out to us. You can open a ticket in our issue tracker to start a discussion.- Returns:
- container of invocations, stubbings, and answers of the mock. The container is not part of the public API, please do not cast it or provide custom implementations.
- Since:
- 2.10.0
-
-