Class Slf4jMockPolicy
- java.lang.Object
-
- org.powermock.api.mockito.mockpolicies.Slf4jMockPolicy
-
- All Implemented Interfaces:
PowerMockPolicy
public class Slf4jMockPolicy extends java.lang.Object implements 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:org.slf4j.LoggerFactory.getLogger(Class). However, it is critical that the mocked logger is reset after each test in order to avoid crosstalk between test cases.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringFRAMEWORK_NAMEprivate static java.lang.StringLOGGER_CLASS_NAMEprivate static java.lang.StringLOGGER_FACTORY_CLASS_NAMEprivate static java.lang.StringLOGGER_FACTORY_METHOD_NAMEprivate static java.lang.ThreadLocal<java.lang.Object>threadLogger
-
Constructor Summary
Constructors Constructor Description Slf4jMockPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyClassLoadingPolicy(MockPolicyClassLoadingSettings mockPolicyClassLoadingSettings)Apply all class-loading related policies that must be present before the interception policies can take place.voidapplyInterceptionPolicy(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 java.lang.Class<?>getLoggerClass(LogPolicySupport logPolicySupport)private voidinitializeMockForThread(LogPolicySupport logPolicySupport)
-
-
-
Field Detail
-
LOGGER_FACTORY_CLASS_NAME
private static final java.lang.String LOGGER_FACTORY_CLASS_NAME
- See Also:
- Constant Field Values
-
LOGGER_FACTORY_METHOD_NAME
private static final java.lang.String LOGGER_FACTORY_METHOD_NAME
- See Also:
- Constant Field Values
-
FRAMEWORK_NAME
private static final java.lang.String FRAMEWORK_NAME
- See Also:
- Constant Field Values
-
LOGGER_CLASS_NAME
private static final java.lang.String LOGGER_CLASS_NAME
- See Also:
- Constant Field Values
-
threadLogger
private static java.lang.ThreadLocal<java.lang.Object> threadLogger
-
-
Method Detail
-
applyClassLoadingPolicy
public void applyClassLoadingPolicy(MockPolicyClassLoadingSettings mockPolicyClassLoadingSettings)
Description copied from interface:PowerMockPolicyApply all class-loading related policies that must be present before the interception policies can take place.- Specified by:
applyClassLoadingPolicyin interfacePowerMockPolicy- Parameters:
mockPolicyClassLoadingSettings- The settings objects where the class-loading policies can be applied.
-
applyInterceptionPolicy
public void applyInterceptionPolicy(MockPolicyInterceptionSettings mockPolicyInterceptionSettings)
Description copied from interface:PowerMockPolicyApply 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:
applyInterceptionPolicyin interfacePowerMockPolicy- Parameters:
mockPolicyInterceptionSettings- The settings objects where the interception policies can be applied.
-
initializeMockForThread
private void initializeMockForThread(LogPolicySupport logPolicySupport)
-
getLoggerClass
private java.lang.Class<?> getLoggerClass(LogPolicySupport logPolicySupport)
-
-