Class Log4jMockPolicy
- java.lang.Object
-
- org.powermock.api.easymock.mockpolicies.AbstractEasyMockLogPolicyBase
-
- org.powermock.api.easymock.mockpolicies.Log4jMockPolicy
-
- All Implemented Interfaces:
PowerMockPolicy
public class Log4jMockPolicy extends AbstractEasyMockLogPolicyBase
A log4j mock policy. This mock policy deals with solving log4j related mocking issues. It takes care of loading all concerned log4j classes through the correct class-loader and automatically prepares and injects logger instances. This policy does the following:- Prepares all log4j classes and interfaces for testing.
- All calls to the org.apache.log4j.Logger#getLogger(..) methods are intercepted and returns a nice mock of type org.apache.log4j.Logger.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
LOGGER_CLASS
-
Constructor Summary
Constructors Constructor Description Log4jMockPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String[]
getFullyQualifiedNamesOfClassesToLoadByMockClassloader()
Loads all log4j classes with the mock classloader.protected java.lang.String
getLogFrameworkName()
protected java.lang.String
getLoggerClassToMock()
protected java.lang.String
getLoggerFactoryClassName()
protected java.lang.String
getLoggerMethodName()
-
Methods inherited from class org.powermock.api.easymock.mockpolicies.AbstractEasyMockLogPolicyBase
applyClassLoadingPolicy, applyInterceptionPolicy
-
-
-
-
Field Detail
-
LOGGER_CLASS
private static final java.lang.String LOGGER_CLASS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getFullyQualifiedNamesOfClassesToLoadByMockClassloader
protected java.lang.String[] getFullyQualifiedNamesOfClassesToLoadByMockClassloader()
Loads all log4j classes with the mock classloader.- Specified by:
getFullyQualifiedNamesOfClassesToLoadByMockClassloader
in classAbstractEasyMockLogPolicyBase
- Returns:
- The fully-qualified names of the classes that should be loaded by the mock classloader.
-
getLogFrameworkName
protected java.lang.String getLogFrameworkName()
- Specified by:
getLogFrameworkName
in classAbstractEasyMockLogPolicyBase
- Returns:
- The name of the log framework. Used in error messages, for
example if the
AbstractEasyMockLogPolicyBase.getLoggerFactoryClassName()
cannot be found in the classpath.
-
getLoggerClassToMock
protected java.lang.String getLoggerClassToMock()
- Specified by:
getLoggerClassToMock
in classAbstractEasyMockLogPolicyBase
- Returns:
- The fully-qualified class name of the class that should be mocked. The mock instance of this class will then be returned each time a specified method in the Logger Factory is invoked.
-
getLoggerFactoryClassName
protected java.lang.String getLoggerFactoryClassName()
- Specified by:
getLoggerFactoryClassName
in classAbstractEasyMockLogPolicyBase
- Returns:
- The fully-qualified class name of the Logger Factory that contains the methods that should return a mock upon invocation.
-
getLoggerMethodName
protected java.lang.String getLoggerMethodName()
- Specified by:
getLoggerMethodName
in classAbstractEasyMockLogPolicyBase
- Returns:
- The name of the methods in the Logger Factory that should return a mock upon invocation.
-
-