Class TestClassTransformer
java.lang.Object
org.powermock.core.transformers.impl.TestClassTransformer
- All Implemented Interfaces:
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.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Class<?> private final Class<? extends Annotation> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateTestClassTransformer(Class<?> testClass, Class<? extends Annotation> testMethodAnnotationType) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddClassInitializerNotification(javassist.CtClass clazz) private voidaddConstructorNotification(javassist.CtClass clazz) private voidaddLifeCycleNotifications(javassist.CtClass clazz) private Class<?> asOriginalClass(javassist.CtClass type) private Class<?>[]asOriginalClassParams(javassist.CtClass[] parameterTypes) private static StringcreateSignature(String testClass, String returnType, String methodName, String[] paramTypes) forTestClass(Class<?> testClass) private static booleanhasSuperClass(javassist.CtClass clazz) private booleanisNestedWithinTestClass(javassist.CtClass clazz) private booleanisTestClass(javassist.CtClass clazz) private voidmakeDeferConstructorNonPublic(javassist.CtClass clazz) (package private) abstract booleanmustHaveTestAnnotationRemoved(javassist.CtMethod method) private voidremoveTestAnnotationsForTestMethodsThatRunOnOtherClassLoader(javassist.CtClass clazz) private voidremoveTestMethodAnnotationFrom(javassist.CtMethod m) private voidrestoreOriginalConstructorsAccesses(javassist.CtClass clazz) private static Stringprivate static StringsignatureOf(javassist.CtMethod m) javassist.CtClasstransform(javassist.CtClass clazz) Transforms theclazz.
-
Field Details
-
testClass
-
testMethodAnnotationType
-
-
Constructor Details
-
TestClassTransformer
private TestClassTransformer(Class<?> testClass, Class<? extends Annotation> testMethodAnnotationType)
-
-
Method Details
-
forTestClass
-
isTestClass
private boolean isTestClass(javassist.CtClass clazz) -
isNestedWithinTestClass
private boolean isNestedWithinTestClass(javassist.CtClass clazz) -
asOriginalClass
- Throws:
Exception
-
asOriginalClassParams
- Throws:
Exception
-
mustHaveTestAnnotationRemoved
- Throws:
Exception
-
removeTestMethodAnnotationFrom
- Throws:
ClassNotFoundException
-
removeTestAnnotationsForTestMethodsThatRunOnOtherClassLoader
private void removeTestAnnotationsForTestMethodsThatRunOnOtherClassLoader(javassist.CtClass clazz) throws Exception - Throws:
Exception
-
transform
Description copied from interface:MockTransformerTransforms theclazz.- Specified by:
transformin interfaceMockTransformer- Parameters:
clazz- The class to be transform into a mock enabled class.- Returns:
- A
CtClassrepresentation of the mocked class. - Throws:
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
- Throws:
Exception
-
makeDeferConstructorNonPublic
private void makeDeferConstructorNonPublic(javassist.CtClass clazz) -
signatureOf
-
signatureOf
- Throws:
javassist.NotFoundException
-
createSignature
-