Class JclMockPolicy

  • All Implemented Interfaces:
    PowerMockPolicy

    public class JclMockPolicy
    extends Object
    A Jakarta Commons-Logging (JCL) mock policy. This mock policy deals with solving JCL related mocking issues. It takes care of loading all concerned JCL classes through the correct class-loader and automatically prepares and injects logger instances. This policy does the following:
    1. Prepares all classes in the org.apache.commons.logging for test as well as org.apache.log4j.Appender and org.apache.log4j.xml.DOMConfigurator.
    2. All calls to the org.apache.commons.logging.LogFactory#getLog(..) methods are intercepted and returns a nice mock of type org.apache.commons.logging.Log.
    • Constructor Detail

      • JclMockPolicy

        public JclMockPolicy()
    • Method Detail

      • getFullyQualifiedNamesOfClassesToLoadByMockClassloader

        protected String[] getFullyQualifiedNamesOfClassesToLoadByMockClassloader()
        Loads all log4j classes with the mock classloader.
        Returns:
        The fully-qualified names of the classes that should be loaded by the mock classloader.
      • getLogFrameworkName

        protected String getLogFrameworkName()
        Returns:
        The name of the log framework. Used in error messages, for example if the getLoggerFactoryClassName() cannot be found in the classpath.
      • getLoggerClassToMock

        protected String getLoggerClassToMock()
        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 String getLoggerFactoryClassName()
        Returns:
        The fully-qualified class name of the Logger Factory that contains the methods that should return a mock upon invocation.
      • getLoggerMethodName

        protected String getLoggerMethodName()
        Returns:
        The name of the methods in the Logger Factory that should return a mock upon invocation.
      • applyClassLoadingPolicy

        public void applyClassLoadingPolicy​(MockPolicyClassLoadingSettings settings)
        Apply all class-loading related policies that must be present before the interception policies can take place.
        Specified by:
        applyClassLoadingPolicy in interface PowerMockPolicy
        Parameters:
        settings - The settings objects where the class-loading policies can be applied.
      • applyInterceptionPolicy

        public void applyInterceptionPolicy​(MockPolicyInterceptionSettings settings)
        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 interface PowerMockPolicy
        Parameters:
        settings - The settings objects where the interception policies can be applied.