Class TestClassTransformer

  • All Implemented Interfaces:
    MockTransformer

    public abstract class TestClassTransformer
    extends java.lang.Object
    implements MockTransformer
    MockTransformer implementation that will make PowerMock test-class enhancements for four purposes... 1) Make test-class static initializer and constructor send crucial details (for PowerMockTestListener events) to GlobalNotificationBuildSupport so that this information can be forwarded to whichever facility is used for composing the PowerMockTestListener events. 2) Removal of test-method annotations as a mean to achieve test-suite chunking! 3) Restore original test-class constructors` accesses (in case they have all been made public by AbstractMainMockTransformer.setAllConstructorsToPublic(javassist.CtClass)) - to avoid that multiple public test-class constructors cause a delegate runner from JUnit (or 3rd party) to bail out with an error message such as "Test class can only have one constructor". 4) Set test-class defer constructor (if exist) as protected instead of public. Otherwise a delegate runner from JUnit (or 3rd party) might get confused by the presence of more than one test-class constructor and bail out with an error message such as "Test class can only have one constructor". The #3 and #4 enhancements will also be enforced on the constructors of classes that are nested within the test-class.
    • Field Detail

      • testClass

        private final java.lang.Class<?> testClass
      • testMethodAnnotationType

        private final java.lang.Class<? extends java.lang.annotation.Annotation> testMethodAnnotationType
    • Constructor Detail

      • TestClassTransformer

        private TestClassTransformer​(java.lang.Class<?> testClass,
                                     java.lang.Class<? extends java.lang.annotation.Annotation> testMethodAnnotationType)
    • Method Detail

      • isTestClass

        private boolean isTestClass​(javassist.CtClass clazz)
      • isNestedWithinTestClass

        private boolean isNestedWithinTestClass​(javassist.CtClass clazz)
      • asOriginalClass

        private java.lang.Class<?> asOriginalClass​(javassist.CtClass type)
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • asOriginalClassParams

        private java.lang.Class<?>[] asOriginalClassParams​(javassist.CtClass[] parameterTypes)
                                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • mustHaveTestAnnotationRemoved

        abstract boolean mustHaveTestAnnotationRemoved​(javassist.CtMethod method)
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • removeTestMethodAnnotationFrom

        private void removeTestMethodAnnotationFrom​(javassist.CtMethod m)
                                             throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • removeTestAnnotationsForTestMethodsThatRunOnOtherClassLoader

        private void removeTestAnnotationsForTestMethodsThatRunOnOtherClassLoader​(javassist.CtClass clazz)
                                                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • transform

        public javassist.CtClass transform​(javassist.CtClass clazz)
                                    throws java.lang.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:
        java.lang.Exception
      • addLifeCycleNotifications

        private void addLifeCycleNotifications​(javassist.CtClass clazz)
      • addClassInitializerNotification

        private void addClassInitializerNotification​(javassist.CtClass clazz)
                                              throws javassist.CannotCompileException
        Throws:
        javassist.CannotCompileException
      • hasSuperClass

        private static boolean hasSuperClass​(javassist.CtClass clazz)
      • addConstructorNotification

        private void addConstructorNotification​(javassist.CtClass clazz)
                                         throws javassist.CannotCompileException
        Throws:
        javassist.CannotCompileException
      • restoreOriginalConstructorsAccesses

        private void restoreOriginalConstructorsAccesses​(javassist.CtClass clazz)
                                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • makeDeferConstructorNonPublic

        private void makeDeferConstructorNonPublic​(javassist.CtClass clazz)
      • signatureOf

        private static java.lang.String signatureOf​(java.lang.reflect.Method m)
      • signatureOf

        private static java.lang.String signatureOf​(javassist.CtMethod m)
                                             throws javassist.NotFoundException
        Throws:
        javassist.NotFoundException
      • createSignature

        private static java.lang.String createSignature​(java.lang.String testClass,
                                                        java.lang.String returnType,
                                                        java.lang.String methodName,
                                                        java.lang.String[] paramTypes)