All Classes and Interfaces
Class
Description
Additional answers provides factory methods for answers.
See
ArgumentMatchers
for general info about matchers.See the javadoc for
VerificationAfterDelay
Configures test via annotations.
Generic interface to be used for configuring mock's answer.
Generic interface to be used for configuring mock's answer for a single argument invocation.
Generic interface to be used for configuring mock's answer for a two argument invocation.
Generic interface to be used for configuring mock's answer for a three argument invocation.
Generic interface to be used for configuring mock's answer for a four argument invocation.
Generic interface to be used for configuring mock's answer for a five argument invocation.
Generic interface to be used for configuring mock's answer for a six argument invocation.
Functional interfaces to make it easy to implement answers in Java 8
Enumeration of pre-configured mock answers
Returns as the provided answer would return, after delaying the specified amount.
Use it to capture argument values for further assertions.
Allows creating customized argument matchers.
Allow flexible verification or stubbing.
by Szczepan Faber, created at: 3/31/12
Listener that is automatically cleaned up (removed from the the global list of subscribers).
Base interface for stubbing consecutive method calls with
Mockito.doReturn(Object)
syntax.Behavior Driven Development style of writing tests uses //given //when //then comments as fundamental parts of your test methods.
See original
OngoingStubbing
See original
Stubber
Provides fluent way of mock verification.
This utility class will call the setter of the property to inject a new value.
ByteBuddy MockMaker.
Optional Answer that adds partial mocking support
Allows shorthand
ArgumentCaptor
creation on fields.Instantiate
ArgumentCaptor
a field annotated by @Captor.This annotation is not supposed to be used by Mockito end-users.
Pre-made preconditions
Loads configuration or extension points available in the classpath.
Injection strategy based on constructor.
Intended to use in certain ArgumentMatchers.
Inject mock/spies dependencies for fields annotated with @InjectMocks
Class to inspect any object, and identify whether a particular object is either a mock or a spy.
DefaultConfiguration of Mockito framework
This predicate is used to filter "good"
StackTraceElement
.by Szczepan Faber, created at: 7/29/12
Provides information about the invocation, specifically a human readable description and the location.
Description verification mode wraps an existing verification mode and prepends
a custom message to the assertion error if verification fails.
A detached local that allows for explicit control of setting and removing values from a thread-local
context.
Determines the cleaning format.
Thrown when a mock is accessed after it has been disabled by
MockitoFramework.clearInlineMocks()
.Throws
DisabledMockException
when a mock is accessed after it has been disabled by
MockitoFramework.clearInlineMocks()
.Annotation representing a type that should not be mocked.
Enforcer that is applied to every type in the type hierarchy of the class-to-be-mocked.
Static cache for types that are known to be mockable and
thus may be skipped while traversing the class hierarchy.
Enforcer that checks if a mock can be created given its type and other settings used in its creation.
Thrown when attempting to mock a class that is annotated with
DoNotMock
.Implementation of JUnit run listener that knows when any of the tests failed
Simple annotation processor interface.
Report on field initialization
Initialize a field with type instance if a default constructor can be found.
Represents the strategy used to resolve actual instances
to be given to a constructor given the argument types.
Internal answer to forward invocations on a real instance.
This class can retrieve generic meta-data that the compiler stores on classes
and accessible members.
Type representing bounds of a type
Type representing bounds of a type variable, allows to keep all bounds information.
Type representing bounds of a wildcard, allows to keep all bounds information.
Attempts to extract generic type of given target base class or target interface
Thread-safe wrapper on user-defined org.mockito.configuration.MockitoConfiguration implementation
Globally configured Answer.
hashCode and equals safe mock wrapper.
hashCode and equals safe hash based set.
Use it to configure Mockito.
The annotation conveys following information:
The API is fairly new and we would appreciate your feedback.
This class is required to resolve a method handle lookup for the
org.mockito.codegen
package what requires a preexisting class for the package.Mark a field on which injection should be performed.
Thrown when creation of test subject annotated with InjectMocks fails.
Scan field for injection.
Extension to
MockMaker
for mock makers that changes inline method implementations
and need keep track of created mock objects.Allows verification in order.
Allows verifying in order.
Represents an accessible instance field.
Exception generated when
Instantiator.newInstance(Class)
failed.Provides instances of classes.
Mockito will invoke this interface in order to fetch an instance instantiator provider.
I'm using this surrogate interface to hide internal Runner implementations.
A method call on a mock object.
Compares invocations based on the sequence number
Although this class is a part of public API, please don't provide your own implementations.
Available via
MockitoFramework.getInvocationFactory()
.Behavior of the real method.
This listener can be notified of method invocations on a mock.
In addition to all content of the invocation, the invocation matcher contains the argument matchers.
An invocation on a mock.
Prints invocations in human-readable, printable way
IO utils.
Utilities for Iterables
Internal implementation.
Used for declaring optional stubbings with
Mockito.lenient()
Describes the location of something in the source code.
MatchableInvocation
wraps Invocation
instance
and holds argument matchers associated with that invocation.Extracts generic type of matcher
A member accessor is responsible for invoking methods, constructors and for setting
and reading field values.
Represent a method call on a mock.
Reports stubbing argument mismatches to the supplied logger
Mark a field as a mock.
Instantiates a mock on a field annotated by
Mock
Notified when mock object is created.
Informs about the mock settings.
Represents a mock of any object construction of the represented type.
The context for a construction mock.
Functional interface that consumes a newly created mock and the mock context.
Represents an active mock of a type's static methods.
Functional interface for a verification operation on a static mock.
Mockito handler of an invocation on a mock.
by Szczepan Faber, created at: 5/21/12
Invocation handler set on mock objects.
Provides mocking information.
Internal injection configuration utility.
Ongoing configuration of the mock injector.
Injector strategy contract
MockitoAnnotations.openMocks(this); initializes fields annotated with Mockito annotations.
Base class for verification errors emitted by Mockito.
Raised by mockito to emit an error either due to Mockito, or due to the User.
Mockito framework settings and lifecycle listeners, for advanced users or for integrating with other frameworks.
Allows matching arguments with hamcrest matchers.
Stubbing hints were introduced in Mockito 2 in order to improve debuggability while keeping backwards compatibility.
Mockito supports JUnit via:
JUnit Rules - see
MockitoRule
JUnit runners - see MockitoJUnitRunner
JUnit Jupiter extension
Mockito JUnit Runner keeps tests clean and improves debugging experience.
This Mockito JUnit Runner implementation *ignores*
stubbing argument mismatches (
MockitoJUnitRunner.StrictStubs
)
and *does not detect* unused stubbings.Detects unused stubs and reports them as failures.
Improves debugging tests, helps keeping the tests clean.
Marker interface for all types of Mockito listeners.
Mockito logger.
Instance of this interface is available via
MockitoFramework.getPlugins()
.Mockito JUnit Rule helps keeping tests clean.
Raised by mockito to emit an error either due to Mockito, or due to the User.
MockitoSession
is an optional, highly recommended feature
that drives writing cleaner tests by eliminating boilerplate code and adding extra validation.Fluent builder interface for
MockitoSession
objects.Logger for hints emitted when
finishing mocking for a
MockitoSession
.Internal test listener that helps decoupling JUnit internals from Mockito "business" logic.
Equivalent to
MockitoRule
, but inherits a different JUnit4 base interface TestRule
.The facility to create mocks.
Carries the mockability information
Constants for built-in implementations of
MockMaker
.Represents the name of the mock as shown in the verification failure reports, etc.
To avoid memory leaks for certain implementations of MockMaker,
we need to use weak mock references internally.
A mock resolver offers an opportunity to resolve a mock from any instance that is
provided to the
Mockito
-DSL.Scan mocks, and prepare them if needed.
Allows mock creation with additional mock settings.
The type of mock being created
A weak reference that is converted into a strong reference when serialized.
Thrown when atMost(x) verification fails.
No interactions wanted.
Indicates to the user that she should not provide custom implementations of given type.
Report on a method call
Allow the ongoing injection of a mock candidate.
Simply put: "When the x method is called then return y".
Access to Mockito behavior that can be reconfigured by plugins
Allows switching off the plugins that are discovered on classpath.
PotentialStubbingProblem
improves productivity by failing the test early when the user
misconfigures mock's stubbing.Allows users to specify Mockito as a Java agent where the
Instrumentation
instance is stored for use by the inline mock maker.Inject mocks using first setters then fields, if no setters available.
A mock maker that is using the
Proxy
utility and is therefore only capable of mocking interfaces but
does not rely on manual byte code generation but only uses official and public Java API.Interface that wraps a 'real' method of the mock object.
Reported when instance of
MockitoListener
is being added to Mockito (see MockitoFramework
)
and there is already a listener with this implementation type registered.Reports verification and misusing errors.
Returns the passed parameter identity at specified index.
Returning deep stub implementation.
Returns elements of the collection.
Default answer of every Mockito mock.
It's likely this implementation will be used by default by every Mockito 4.0.0 mock.
Optional Answer that can be used with
Mockito.mock(Class, Answer)
Creates instances of Mockito JUnit Runner in a safe way, e.g.
Represents a mock with a thread-local explicit scope.
Mock serializable style.
Makes sure both wanted and actual are printed consistently (single line or multiline)
Allows shorthand wrapping of field instances in a spy object.
Process fields annotated with @Spy.
Handler for field annotated with @InjectMocks and @Spy.
Decides if particular StackTraceElement is excluded from the human-readable stack trace output.
Very similar to the StackFrame class declared on the StackWalker api.
An extension point to register custom
StackTraceCleaner
.Configures the "strictness" of Mockito, affecting the behavior of stubbings and verification.
Helps determining the actual strictness given that it can be configured in multiple ways (at mock, at stubbing, in rule)
Fails early when mismatched arguments used for stubbing
Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
Stubbing declared on the mock object.
Compares stubbings based on
InvocationComparator
Represent an information about the looked up stubbing
When a method is called on a mock object Mockito looks up any stubbings recorded on that mock.
The information about stubbing, for example the location of stubbing.
Subclass based mock maker.
A subclass loader is responsible for resolving a class loading strategy for a mock that is implemented as a subclass.
Sort fields in an order suitable for injection, by name with superclasses
moved after their subclasses.
Abstract provider that can supply (provide/create) objects of given type.
Utilities for Kotlin Continuation-Passing-Style suspending function, detecting and trimming last hidden parameter.
This node returns an actual injecter which will be either :
an
OngoingInjector
that do nothing if a candidate couldn't be found
an OngoingInjector
that will try to inject the candidate trying first the property setter then if not possible try the field access
Provides access to the
MockingProgress
of a corresponding Thread
.An answer that always throws the same throwable.
See the javadoc for
VerificationWithTimeout
This exception prevents the user from forgetting to use
MockitoSession.finishMocking()
.Universal test listener that behaves accordingly to current setting of strictness.
This exception indicates presence of unused stubbings.
Reports unnecessary stubbings
Helps determining if stubbing should be reported as unused
Contains unused stubbings, knows how to format them
Finds unused stubbings
Allow to validate this answer is correct for the given invocation.
Prints a Java object value in a way humans can read it neatly.
Logs all invocations to standard output.
Author: Szczepan Faber, created at: 4/3/11
VerificationAfterDelay is a
VerificationMode
that allows combining existing verification modes with an initial delay, e.g.Use this rule in order to collect multiple verification failures and report at once.
Mockito implementation of VerificationCollector.
Data needed to perform verification of interactions.
Contains all information about a verification that has happened.
This listener can be notified of verify invocations on a mock.
Allows verifying that certain behavior happened at least once / exact number
of times / never.
Verifies that another verification mode (the delegate) is satisfied within a certain timeframe
(before timeoutMillis has passed, measured from the call to verify()), and either returns immediately
once it does, or waits until it is definitely satisfied once the full time has passed.
The instance of this class is passed to
VerificationStartedListener
.This listener gets notified when the user starts verification.
Strategy to possibly lazily perform verifications.
VerificationWithTimeout is a
VerificationMode
that allows combining existing verification modes with 'timeout'.Generic interface to be used for configuring mock's answer for a single argument invocation that returns nothing.
Generic interface to be used for configuring mock's answer for a two argument invocation that returns nothing.
Generic interface to be used for configuring mock's answer for a three argument invocation that returns nothing.
Generic interface to be used for configuring mock's answer for a four argument invocation that returns nothing.
Generic interface to be used for configuring mock's answer for a five argument invocation that returns nothing.
Generic interface to be used for configuring mock's answer for a six argument invocation that returns nothing.
A thread-safe map with weak keys.
A
WeakConcurrentMap
where stale entries are removed as a side effect of interacting with this map.
A thread-safe set with weak values.
Determines the cleaning format.