Annotation Type MockPolicy


  • @Target(TYPE)
    @Retention(RUNTIME)
    @Documented
    @Inherited
    public @interface MockPolicy
    A Mock Policy can be used to make it easier to unit test some code with PowerMock in isolation from a certain framework. 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) for a certain framework or set of classes or interfaces.

    A mock policy can for example be implemented to avoid writing repetitive setup code for your tests. Say that you're using a framework X that in order for you to test it requires that certain methods should always return a mock implementation. Perhaps some static initializers must be suppressed as well. Instead of copying this code between tests it would be a good idea to write a reusable mock policy.

    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.Class<? extends PowerMockPolicy>[] value  
    • Element Detail

      • value

        java.lang.Class<? extends PowerMockPolicy>[] value
        Returns:
        A list of mock policies that should be used in the test class.