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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractMainMockTransformer.PowerMockExpressionEditor
-
Field Summary
Fields Modifier and Type Field Description protected TransformStrategy
strategy
-
Constructor Summary
Constructors Constructor Description AbstractMainMockTransformer(TransformStrategy strategy)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
allowMockingOfPackagePrivateClasses(javassist.CtClass clazz)
protected void
allowMockingOfStaticAndFinalAndNativeMethods(javassist.CtClass clazz)
protected javassist.CtClass
ensureJvmMethodSizeLimit(javassist.CtClass clazz)
According to JVM specification method size must be lower than 65536 bytes.protected void
removeFinalModifierFromAllStaticFinalFields(javassist.CtClass clazz)
protected void
removeFinalModifierFromClass(javassist.CtClass clazz)
protected void
setAllConstructorsToPublic(javassist.CtClass clazz)
protected void
suppressStaticInitializerIfRequested(javassist.CtClass clazz, String name)
javassist.CtClass
transform(javassist.CtClass clazz)
Transforms theclazz
.protected abstract javassist.CtClass
transformMockClass(javassist.CtClass clazz)
-
-
-
Field Detail
-
strategy
protected final TransformStrategy strategy
-
-
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 theclazz
.- Specified by:
transform
in interfaceMockTransformer
- 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
-
-