org.powermock.core.spi
Interface PowerMockPolicy

All Known Implementing Classes:
JclMockPolicy, Log4jMockPolicy, MyCustomMockPolicy, Slf4jMockPolicy

public interface PowerMockPolicy

This interface can be implemented to create policies for certain frameworks to make it easier for users to test their code in isolation from these frameworks. A mock policy implementation can for example suppress some methods, suppress static initializers or intercept method calls and change their return value (for example to return a mock object). A mock policy implementation must be stateless. The reason why there are two methods for applying settings is that PowerMock needs to know which classes that should be modified by the mock class loader before these classes have loaded. The applyClassLoadingPolicy(MockPolicyClassLoadingSettings) tells PowerMock which classes that should be loaded and then the applyInterceptionPolicy(MockPolicyInterceptionSettings) is called from the mock class-loader itself. This means you can create mocks for e.g. final and static methods in the applyInterceptionPolicy(MockPolicyInterceptionSettings) which would not have been possible otherwise.

Since mock policies can be chained subsequent policies can override behavior of a previous policy. To avoid accidental overrides it's recommended add behavior instead of setting behavior since the latter overrides all previous configurations.


Method Summary
 void applyClassLoadingPolicy(MockPolicyClassLoadingSettings settings)
          Apply all class-loading related policies that must be present before the interception policies can take place.
 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.
 

Method Detail

applyClassLoadingPolicy

void applyClassLoadingPolicy(MockPolicyClassLoadingSettings settings)
Apply all class-loading related policies that must be present before the interception policies can take place.

Parameters:
settings - The settings objects where the class-loading policies can be applied.

applyInterceptionPolicy

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.

Parameters:
settings - The settings objects where the interception policies can be applied.


Copyright © 2007-2012. All Rights Reserved.