Package org.easymock.internal
Class DefaultClassInstantiator
- java.lang.Object
-
- org.easymock.internal.DefaultClassInstantiator
-
- All Implemented Interfaces:
IClassInstantiator
public class DefaultClassInstantiator extends java.lang.Object implements IClassInstantiator
Default class instantiator that is pretty limited. It just hope that the mocked class has a public empty constructor.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<?>[]EMPTY
-
Constructor Summary
Constructors Constructor Description DefaultClassInstantiator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.LongcallLongMethod(java.lang.Class<?> clazz, java.lang.String methodName)java.lang.Object[]getArgsForTypes(java.lang.Class<?>[] methodTypes)Get some default instances of provided classesjava.lang.reflect.Constructor<?>getConstructorToUse(java.lang.Class<?> clazz)Return the constructor considered the best to use with this class.private static java.lang.LonggetSerializableUID(java.lang.Class<?> clazz)private static byte[]getSerializedBytes(java.lang.Class<?> clazz)private booleanisSerializable(java.lang.Class<?> clazz)Tells if the provided class is serializablejava.lang.ObjectnewInstance(java.lang.Class<?> c)Try to instantiate a class without using a special constructor.private static java.lang.ObjectreadObject(byte[] bytes)
-
-
-
Method Detail
-
newInstance
public java.lang.Object newInstance(java.lang.Class<?> c) throws java.lang.InstantiationExceptionTry to instantiate a class without using a special constructor. See documentation for the algorithm.- Specified by:
newInstancein interfaceIClassInstantiator- Parameters:
c- Class to instantiate- Returns:
- new instance of clazz
- Throws:
java.lang.InstantiationException- when an error occured during instantiation
-
isSerializable
private boolean isSerializable(java.lang.Class<?> clazz)
Tells if the provided class is serializable- Parameters:
clazz- Class to check- Returns:
- If the class is serializable
-
getConstructorToUse
public java.lang.reflect.Constructor<?> getConstructorToUse(java.lang.Class<?> clazz)
Return the constructor considered the best to use with this class. Algorithm is: No args constructor and then first constructor defined in the class- Parameters:
clazz- Class in which constructor is searched- Returns:
- Constructor to use
-
getArgsForTypes
public java.lang.Object[] getArgsForTypes(java.lang.Class<?>[] methodTypes) throws java.lang.InstantiationExceptionGet some default instances of provided classes- Parameters:
methodTypes- Classes to instantiate- Returns:
- Instances of methodTypes in order
- Throws:
java.lang.InstantiationException- Thrown if the class instantiation fails
-
getSerializedBytes
private static byte[] getSerializedBytes(java.lang.Class<?> clazz) throws java.io.IOException- Throws:
java.io.IOException
-
getSerializableUID
private static java.lang.Long getSerializableUID(java.lang.Class<?> clazz)
-
callLongMethod
private static java.lang.Long callLongMethod(java.lang.Class<?> clazz, java.lang.String methodName)
-
readObject
private static java.lang.Object readObject(byte[] bytes) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-