Package org.mockito.plugins
Interface InstantiatorProvider
- All Known Implementing Classes:
InstantiatorProvider2Adapter
Deprecated.
- Since:
- 2.0.31
-
Method Summary
Modifier and TypeMethodDescriptiongetInstantiator(MockCreationSettings<?> settings) Deprecated., seeInstantiatorProvider.
-
Method Details
-
getInstantiator
Deprecated., seeInstantiatorProvider. Returns an instantiator, used to create new class instances.
-
InstantiatorProvider2and Issue 1303Mockito will invoke this interface in order to fetch an instance instantiator provider.
By default, an internal byte-buddy/asm/objenesis based implementation is used.
Using the extension point
The plugin mechanism of mockito works in a similar way as the
ServiceLoader, however instead of looking in theMETA-INFdirectory, Mockito will look inmockito-extensionsdirectory. The reason for that is that Android SDK strips jar from theMETA-INFdirectory when creating an APK.org.awesome.mockito.AwesomeInstantiatorProviderthat implements theInstantiatorProvider.mockito-extensions/org.mockito.plugins.InstantiatorProvider". The content of this file is exactly a one line with the qualified name:org.awesome.mockito.AwesomeInstantiatorProvider.Note that if several
mockito-extensions/org.mockito.plugins.InstantiatorProviderfiles exists in the classpath, Mockito will only use the first returned by the standardClassLoader.getResource(java.lang.String)mechanism.So just create a custom implementation of
InstantiatorProviderand place the qualified name in the following filemockito-extensions/org.mockito.plugins.InstantiatorProvider.This class is deprecated and was replaced by
InstantiatorProvider2. Hence if there is both amockito-extensions/org.mockito.plugins.InstantiatorProviderandmockito-extensions/org.mockito.plugins.InstantiatorProvider2the second one takes preference.