public class DefaultMockitoSession extends java.lang.Object implements MockitoSession
Modifier and Type | Field and Description |
---|---|
private UniversalTestListener |
listener |
private java.lang.String |
name |
Constructor and Description |
---|
DefaultMockitoSession(java.util.List<java.lang.Object> testClassInstances,
java.lang.String name,
Strictness strictness,
MockitoLogger logger) |
Modifier and Type | Method and Description |
---|---|
void |
finishMocking()
Must be invoked when the user is done with mocking for given session (test method).
|
void |
finishMocking(java.lang.Throwable failure)
Must be invoked when the user is done with mocking for given session (test method).
|
void |
setStrictness(Strictness strictness)
Changes the strictness of this
MockitoSession . |
private final java.lang.String name
private final UniversalTestListener listener
public DefaultMockitoSession(java.util.List<java.lang.Object> testClassInstances, java.lang.String name, Strictness strictness, MockitoLogger logger)
public void setStrictness(Strictness strictness)
MockitoSession
MockitoSession
.
The new strictness will be applied to operations on mocks and checks performed by MockitoSession.finishMocking()
.
This method is used behind the hood by MockitoRule.strictness(Strictness)
method.
In most healthy tests, this method is not needed.
We keep it for edge cases and when you really need to change strictness in given test method.
For use cases see Javadoc for PotentialStubbingProblem
class.setStrictness
in interface MockitoSession
strictness
- new strictness for this session.public void finishMocking()
MockitoSession
UnnecessaryStubbingException
or emit warnings (MockitoHint
) depending on the Strictness
level.
The method also detects incorrect Mockito usage via Mockito.validateMockitoUsage()
.
In order to implement Strictness
Mockito session keeps track of mocking using MockitoListener
.
This method cleans up the listeners and ensures there is no leftover state after the session finishes.
It is necessary to invoke this method to conclude mocking session.
For more information about session lifecycle see MockitoSessionBuilder.startMocking()
.
This method is intended to be used in your test framework's 'tear down' method. In the case of JUnit it is the "@After" method.
For example, see javadoc for MockitoSession
.
finishMocking
in interface MockitoSession
MockitoSession.finishMocking(Throwable)
public void finishMocking(java.lang.Throwable failure)
MockitoSession
MockitoSession.finishMocking()
.
This method is intended to be used by framework integrations. When using MockitoSession
directly, most users should rather use MockitoSession.finishMocking()
.
MockitoRule
uses this method behind the hood.
finishMocking
in interface MockitoSession
failure
- the exception that caused the test to fail; passing null
is permittedMockitoSession.finishMocking()