Class AbstractMainMockTransformer

    • Constructor Detail

      • AbstractMainMockTransformer

        public AbstractMainMockTransformer​(TransformStrategy strategy)
    • Method Detail

      • 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:
        JVM specification
      • 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