Package org.mockito.internal.framework
Class DefaultMockitoSession
java.lang.Object
org.mockito.internal.framework.DefaultMockitoSession
- All Implemented Interfaces:
MockitoSession
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMockitoSession(List<Object> testClassInstances, String name, Strictness strictness, MockitoLogger logger) -
Method Summary
Modifier and TypeMethodDescriptionvoidMust be invoked when the user is done with mocking for given session (test method).voidfinishMocking(Throwable failure) Must be invoked when the user is done with mocking for given session (test method).voidsetStrictness(Strictness strictness) Changes the strictness of thisMockitoSession.
-
Constructor Details
-
DefaultMockitoSession
public DefaultMockitoSession(List<Object> testClassInstances, String name, Strictness strictness, MockitoLogger logger)
-
-
Method Details
-
setStrictness
Description copied from interface:MockitoSessionChanges the strictness of thisMockitoSession. The new strictness will be applied to operations on mocks and checks performed byMockitoSession.finishMocking(). This method is used behind the hood byMockitoRule.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 forPotentialStubbingProblemclass.- Specified by:
setStrictnessin interfaceMockitoSession- Parameters:
strictness- new strictness for this session.
-
finishMocking
public void finishMocking()Description copied from interface:MockitoSessionMust be invoked when the user is done with mocking for given session (test method). It detects unused stubbings and may throwUnnecessaryStubbingExceptionor emit warnings (MockitoHint) depending on theStrictnesslevel. The method also detects incorrect Mockito usage viaMockito.validateMockitoUsage().In order to implement
StrictnessMockito session keeps track of mocking usingMockitoListener. 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 seeMockitoSessionBuilder.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.- Specified by:
finishMockingin interfaceMockitoSession- See Also:
-
finishMocking
Description copied from interface:MockitoSessionMust be invoked when the user is done with mocking for given session (test method). When a failure is specified, certain checks are disabled to avoid confusion that may arise because there are multiple competing failures. Other than that, this method behaves exactly likeMockitoSession.finishMocking().This method is intended to be used by framework integrations. When using MockitoSession directly, most users should rather use
MockitoSession.finishMocking().MockitoRuleuses this method behind the hood.- Specified by:
finishMockingin interfaceMockitoSession- Parameters:
failure- the exception that caused the test to fail; passingnullis permitted- See Also:
-