Class Slf4jMockPolicy
java.lang.Object
org.powermock.api.mockito.mockpolicies.Slf4jMockPolicy
- All Implemented Interfaces:
PowerMockPolicy
Sfl4j mock policy that injects a Mockito-created mock to be returned on calls to getLogger factory methods.
The implementation returns a single mock instance per thread but it doesn't return a different mock instance based
on the actual value passed to getLogger. This limitation is acceptable in most real uses cases.
Tests that want to do verifications on the mocked logger can do so by getting the mocked instance as production code
does:
. However, it is critical that the mocked logger is
reset after each test in order to avoid crosstalk between test cases.
invalid reference
org.slf4j.LoggerFactory#getLogger(Class)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyClassLoadingPolicy
(MockPolicyClassLoadingSettings mockPolicyClassLoadingSettings) Apply all class-loading related policies that must be present before the interception policies can take place.void
applyInterceptionPolicy
(MockPolicyInterceptionSettings mockPolicyInterceptionSettings) Apply the interception policies, for example which methods that should be suppressed or which methods that should be intercepted and return some else than their original value.private Class
<?> getLoggerClass
(LogPolicySupport logPolicySupport) private void
initializeMockForThread
(LogPolicySupport logPolicySupport)
-
Field Details
-
LOGGER_FACTORY_CLASS_NAME
- See Also:
-
LOGGER_FACTORY_METHOD_NAME
- See Also:
-
FRAMEWORK_NAME
- See Also:
-
LOGGER_CLASS_NAME
- See Also:
-
threadLogger
-
-
Constructor Details
-
Slf4jMockPolicy
public Slf4jMockPolicy()
-
-
Method Details
-
applyClassLoadingPolicy
Description copied from interface:PowerMockPolicy
Apply all class-loading related policies that must be present before the interception policies can take place.- Specified by:
applyClassLoadingPolicy
in interfacePowerMockPolicy
- Parameters:
mockPolicyClassLoadingSettings
- The settings objects where the class-loading policies can be applied.
-
applyInterceptionPolicy
Description copied from interface:PowerMockPolicy
Apply the interception policies, for example which methods that should be suppressed or which methods that should be intercepted and return some else than their original value.- Specified by:
applyInterceptionPolicy
in interfacePowerMockPolicy
- Parameters:
mockPolicyInterceptionSettings
- The settings objects where the interception policies can be applied.
-
initializeMockForThread
-
getLoggerClass
-