Interface MockitoFramework
-
- All Known Implementing Classes:
DefaultMockitoFramework
@Incubating public interface MockitoFramework
Mockito framework settings and lifecycle listeners, for advanced users or for integrating with other frameworks.To get
MockitoFramework
instance useMockito.framework()
.For more info on listeners see
addListener(MockitoListener)
.- Since:
- 2.1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MockitoFramework
addListener(MockitoListener listener)
Adds listener to Mockito.InvocationFactory
getInvocationFactory()
Returns a factory that can create instances ofInvocation
.MockitoPlugins
getPlugins()
Returns an object that has access to Mockito plugins.MockitoFramework
removeListener(MockitoListener listener)
When you add listener usingaddListener(MockitoListener)
make sure to remove it.
-
-
-
Method Detail
-
addListener
@Incubating MockitoFramework addListener(MockitoListener listener) throws RedundantListenerException
Adds listener to Mockito. For a list of supported listeners, see the interfaces that extendMockitoListener
.Listeners can be useful for engs that extend Mockito framework. They are used in the implementation of unused stubbings warnings (
MockitoHint
).Make sure you remove the listener when the job is complete, see
removeListener(MockitoListener)
. Currently the listeners list is thread local so you need to remove listener from the same thread otherwise remove is ineffectual. In typical scenarios, it is not a problem, because adding & removing listeners typically happens in the same thread.If you are trying to add the listener but a listener of the same type was already added (and not removed) this method will throw
RedundantListenerException
. This is a safeguard to ensure users actually remove the listeners viaremoveListener(MockitoListener)
. We do not anticipate the use case where adding the same listener type multiple times is useful. If this safeguard is problematic, please contact us via Mockito issue tracker.For usage examples, see Mockito codebase. If you have ideas and feature requests about Mockito listeners API we are very happy to hear about it via our issue tracker or mailing list.
Mockito.framework().addListener(myListener);
- Parameters:
listener
- to add to Mockito- Returns:
- this instance of mockito framework (fluent builder pattern)
- Throws:
RedundantListenerException
- Since:
- 2.1.0
-
removeListener
@Incubating MockitoFramework removeListener(MockitoListener listener)
When you add listener usingaddListener(MockitoListener)
make sure to remove it. Currently the listeners list is thread local so you need to remove listener from the same thread otherwise remove is ineffectual. In typical scenarios, it is not a problem, because adding & removing listeners typically happens in the same thread.For usage examples, see Mockito codebase. If you have ideas and feature requests about Mockito listeners API we are very happy to hear about it via our issue tracker or mailing list.
- Parameters:
listener
- to remove- Returns:
- this instance of mockito framework (fluent builder pattern)
- Since:
- 2.1.0
-
getPlugins
@Incubating MockitoPlugins getPlugins()
Returns an object that has access to Mockito plugins. An example plugin isMockMaker
. For information why and how to use this method seeMockitoPlugins
.- Returns:
- object that gives access to mockito plugins
- Since:
- 2.10.0
-
getInvocationFactory
@Incubating InvocationFactory getInvocationFactory()
Returns a factory that can create instances ofInvocation
. It is useful for framework integrations, becauseInvocation
isNotExtensible
.- Returns:
- object that can construct invocations
- Since:
- 2.10.0
-
-