Class AbstractMainMockTransformer

java.lang.Object
org.powermock.core.transformers.impl.AbstractMainMockTransformer
All Implemented Interfaces:
MockTransformer
Direct Known Subclasses:
ClassMockTransformer, InterfaceMockTransformer

public abstract class AbstractMainMockTransformer extends Object implements MockTransformer
  • Field Details

  • Constructor Details

    • AbstractMainMockTransformer

      public AbstractMainMockTransformer(TransformStrategy strategy)
  • Method Details

    • allowMockingOfPackagePrivateClasses

      protected String allowMockingOfPackagePrivateClasses(javassist.CtClass clazz)
    • suppressStaticInitializerIfRequested

      protected void suppressStaticInitializerIfRequested(javassist.CtClass clazz, String name) throws javassist.CannotCompileException
      Throws:
      javassist.CannotCompileException
    • removeFinalModifierFromClass

      protected void removeFinalModifierFromClass(javassist.CtClass clazz)
    • allowMockingOfStaticAndFinalAndNativeMethods

      protected void allowMockingOfStaticAndFinalAndNativeMethods(javassist.CtClass clazz) throws javassist.NotFoundException, javassist.CannotCompileException
      Throws:
      javassist.NotFoundException
      javassist.CannotCompileException
    • removeFinalModifierFromAllStaticFinalFields

      protected void removeFinalModifierFromAllStaticFinalFields(javassist.CtClass clazz)
    • setAllConstructorsToPublic

      protected void setAllConstructorsToPublic(javassist.CtClass clazz)
    • ensureJvmMethodSizeLimit

      protected javassist.CtClass ensureJvmMethodSizeLimit(javassist.CtClass clazz) throws javassist.CannotCompileException, javassist.NotFoundException
      According to JVM specification method size must be lower than 65536 bytes. When that limit is exceeded class loader will fail to load the class. Since instrumentation can increase method size significantly it must be ensured that JVM limit is not exceeded.

      When the limit is exceeded method's body is replaced by exception throw. Method is then instrumented again to allow mocking and suppression.

      Throws:
      javassist.CannotCompileException
      javassist.NotFoundException
      See Also:
    • isMethodSizeExceeded

      private boolean isMethodSizeExceeded(javassist.CtMethod method)
    • modifyMethod

      private void modifyMethod(javassist.CtMethod method) throws javassist.NotFoundException, javassist.CannotCompileException
      Throws:
      javassist.NotFoundException
      javassist.CannotCompileException
    • getReturnTypeAsString

      private String getReturnTypeAsString(javassist.CtMethod method) throws javassist.NotFoundException
      Throws:
      javassist.NotFoundException
    • getCorrectReturnValueType

      private String getCorrectReturnValueType(javassist.CtClass returnTypeAsCtClass)
      Returns:
      The correct return type, i.e. takes care of casting the a wrapper type to primitive type if needed.
    • transform

      public javassist.CtClass transform(javassist.CtClass clazz) throws Exception
      Description copied from interface: MockTransformer
      Transforms the clazz.
      Specified by:
      transform in interface MockTransformer
      Parameters:
      clazz - The class to be transform into a mock enabled class.
      Returns:
      A CtClass representation of the mocked class.
      Throws:
      Exception
    • transformMockClass

      protected abstract javassist.CtClass transformMockClass(javassist.CtClass clazz) throws javassist.CannotCompileException, javassist.NotFoundException
      Throws:
      javassist.CannotCompileException
      javassist.NotFoundException