public class DefaultMockitoSession extends Object implements MockitoSession
| Constructor and Description |
|---|
DefaultMockitoSession(List<Object> testClassInstances,
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(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. |
public DefaultMockitoSession(List<Object> testClassInstances, String name, Strictness strictness, MockitoLogger logger)
public void setStrictness(Strictness strictness)
MockitoSessionMockitoSession.
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 MockitoSessionstrictness - new strictness for this session.public void finishMocking()
MockitoSessionUnnecessaryStubbingException
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 MockitoSessionMockitoSession.finishMocking(Throwable)public void finishMocking(Throwable failure)
MockitoSessionMockitoSession.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 MockitoSessionfailure - the exception that caused the test to fail; passing null is permittedMockitoSession.finishMocking()Copyright © 2024. All rights reserved.