org.powermock.api.easymock.mockpolicies
Class Log4jMockPolicy

java.lang.Object
  extended by org.powermock.api.easymock.mockpolicies.Log4jMockPolicy
All Implemented Interfaces:
PowerMockPolicy

public class Log4jMockPolicy
extends Object

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:

  1. Prepares all log4j classes and interfaces for testing.
  2. All calls to the org.apache.log4j.Logger#getLogger(..) methods are intercepted and returns a nice mock of type org.apache.log4j.Logger.


Constructor Summary
Log4jMockPolicy()
           
 
Method Summary
 void applyClassLoadingPolicy(MockPolicyClassLoadingSettings settings)
          
 void applyInterceptionPolicy(MockPolicyInterceptionSettings settings)
          
protected  String[] getFullyQualifiedNamesOfClassesToLoadByMockClassloader()
          Loads all log4j classes with the mock classloader.
protected  String getLogFrameworkName()
           
protected  String getLoggerClassToMock()
           
protected  String getLoggerFactoryClassName()
           
protected  String getLoggerMethodName()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4jMockPolicy

public Log4jMockPolicy()
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)

Specified by:
applyClassLoadingPolicy in interface PowerMockPolicy

applyInterceptionPolicy

public void applyInterceptionPolicy(MockPolicyInterceptionSettings settings)

Specified by:
applyInterceptionPolicy in interface PowerMockPolicy


Copyright © 2007-2012. All Rights Reserved.