-
Packages Package Description org.mockito.runners
-
Interfaces Interface Description org.mockito.configuration.AnnotationEngine Please useAnnotationEngine
instead, this interface will probably be removed in mockito 4.org.mockito.internal.creation.instance.Instantiator since 2.15.4 because this internal class was leaking from the public API. For more information why deprecated, seeInstantiatorProvider2
. UseInstantiator
instead.Provides instances of classes.
org.mockito.internal.InternalMockHandler org.mockito.MockitoDebugger - please useMockingDetails.printInvocations()
instead. An instance ofMockingDetails
can be retrieved viaMockito.mockingDetails(Object)
.org.mockito.plugins.InstantiatorProvider since 2.15.4 because this internal class was leaking from the public API. For more information why deprecated, seeInstantiatorProvider2
and 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-INF
directory, Mockito will look inmockito-extensions
directory. The reason for that is that Android SDK strips jar from theMETA-INF
directory when creating an APK.- The implementation itself, for example
org.awesome.mockito.AwesomeInstantiatorProvider
that implements theInstantiatorProvider
. - A file "
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.InstantiatorProvider
files 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
InstantiatorProvider
and 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.InstantiatorProvider
andmockito-extensions/org.mockito.plugins.InstantiatorProvider2
the second one takes preference. - The implementation itself, for example
-
Classes Class Description org.mockito.internal.debugging.WarningsCollector org.mockito.internal.invocation.UnusedStubsFinder org.mockito.internal.junit.util.JUnitFailureHacker org.mockito.Matchers UseArgumentMatchers
. This class is now deprecated in order to avoid a name clash with Hamcrestorg.hamcrest.Matchers
class. This class will likely be removed in version 4.0.org.mockito.runners.ConsoleSpammingMockitoJUnitRunner as of 2.1.0. Use theMockitoJUnitRunner
runner instead which contains support for detecting unused stubs.If you still prefer using this runner, tell us why (create ticket in our issue tracker).
org.mockito.runners.MockitoJUnitRunner Moved toMockitoJUnitRunner
, this class will be removed with Mockito 4org.mockito.runners.MockitoJUnitRunner.Silent Moved toMockitoJUnitRunner.Silent
, this class will be removed with Mockito 4org.mockito.runners.MockitoJUnitRunner.Strict Moved toMockitoJUnitRunner.Strict
, this class will be removed with Mockito 4org.mockito.runners.VerboseMockitoJUnitRunner as of 2.1.0. Use theMockitoJUnitRunner
runner instead which contains support for detecting unused stubs.If you still prefer using this runner, tell us why (create ticket in our issue tracker).
-
Exceptions Exceptions Description org.mockito.internal.creation.instance.InstantiationException since 2.15.4 because this internal class was leaking from the public API. For information why deprecated, seeInstantiatorProvider2
. UseInstantiator
andInstantiationException
types instead.Exception generated when
Instantiator.newInstance(Class)
failed.
-
Errors Errors Description org.mockito.exceptions.verification.TooLittleActualInvocations as of 2.27.5. Please useTooFewActualInvocations
instead.
-
Methods Method Description org.mockito.Answers.get() as of 2.1.0 Use the enum-constant directly, instead of this getter. This method will be removed in a future release
E.g. instead ofAnswers.CALLS_REAL_METHODS.get()
useAnswers.CALLS_REAL_METHODS
.org.mockito.ArgumentMatchers.anyCollectionOf(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.anyIterableOf(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.anyListOf(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.anyMapOf(Class<K>, Class<V>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.anyObject() This will be removed in Mockito 4.0 This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.anySetOf(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.anyVararg() as of 2.1.0 useArgumentMatchers.any()
org.mockito.ArgumentMatchers.isNotNull(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.isNull(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.ArgumentMatchers.notNull(Class<T>) With Java 8 this method will be removed in Mockito 4.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8.org.mockito.BDDMockito.BDDStubber.willNothing() as of 2.1.0 please useBDDMockito.BDDStubber.willDoNothing()
insteadorg.mockito.BDDMockito.BDDStubberImpl.willNothing() please useBDDMockito.BDDStubberImpl.willDoNothing()
insteadorg.mockito.BDDMockito.Then.shouldHaveZeroInteractions() Since 3.0.1. Please migrate your code toBDDMockito.Then.shouldHaveNoInteractions()
org.mockito.configuration.IMockitoConfiguration.getAnnotationEngine() Please use the extension mechanismAnnotationEngine
instead, this method will probably be removed in mockito 4.org.mockito.internal.configuration.InjectingAnnotationEngine.injectMocks(Object) org.mockito.internal.debugging.MockitoDebuggerImpl.printInvocations(Object...) org.mockito.internal.invocation.InterceptedInvocation.getMockitoMethod() Not used by Mockito but by mockito-scalaorg.mockito.internal.invocation.InterceptedInvocation.getMockRef() Not used by Mockito but by mockito-scalaorg.mockito.internal.invocation.InterceptedInvocation.getRealMethod() Not used by Mockito but by mockito-scalaorg.mockito.internal.verification.api.VerificationData.getWanted() - This internal method leaks internal classInvocationMatcher
. Please useVerificationData.getTarget()
instead. Deprecated since 2.2.12org.mockito.invocation.InvocationFactory.createInvocation(Object, MockCreationSettings, Method, Callable, Object...) UseInvocationFactory.createInvocation(Object, MockCreationSettings, Method, RealMethodBehavior, Object...)
instead. Why deprecated? We found use cases where we need to handle Throwable and ensure correct stack trace filtering (removing Mockito internals from the stack trace). Hence the introduction ofInvocationFactory.RealMethodBehavior
. Creates instance of anInvocation
object. This method is useful for framework integrators to programmatically simulate method calls on mocks usingMockHandler
. It enables advanced framework integrations.org.mockito.MockedStatic.verify(VerificationMode, MockedStatic.Verification) Please useinstead
org.mockito.Mockito.debug() - please useMockingDetails.printInvocations()
instead. An instance ofMockingDetails
can be retrieved viaMockito.mockingDetails(Object)
.org.mockito.Mockito.verifyZeroInteractions(Object...) Since 3.0.1. Please migrate your code toMockito.verifyNoInteractions(Object...)
org.mockito.MockitoAnnotations.initMocks(Object) UseMockitoAnnotations.openMocks(Object)
instead. This method is equivalent toopenMocks(testClass).close()
. The close method should however only be called after completed usage oftestClass
. If using static-mocks or customMockMaker
s, using this method might cause misbehavior of mocks injected into the test class.org.mockito.MockitoDebugger.printInvocations(Object...) - please useMockingDetails.printInvocations()
instead. An instance ofMockingDetails
can be retrieved viaMockito.mockingDetails(Object)
.org.mockito.plugins.InstantiatorProvider.getInstantiator(MockCreationSettings<?>) , seeInstantiatorProvider
. Returns an instantiator, used to create new class instances.org.mockito.runners.MockitoJUnitRunner.filter(Filter) org.mockito.runners.MockitoJUnitRunner.getDescription() org.mockito.runners.MockitoJUnitRunner.run(RunNotifier)