Top Description Fields Constructors Methods
org.easymock.internal

public Class DefaultClassInstantiator

extends Object
implements IClassInstantiator
Class Inheritance
All Implemented Interfaces
org.easymock.internal.IClassInstantiator
Imports
org.easymock.EasyMock, .EasyMockSupport, java.io.*, java.lang.reflect.*

Default class instantiator that is pretty limited. It just hope that the mocked class has a public empty constructor.
Author
Henri Tremblay

Field Summary

Modifier and TypeField and Description
private static final Class<?>[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static Long
callLongMethod(Class<?> clazz, String methodName)

private Class<?>
classToPrint(Class<?> clazz)

public Object[]

Returns:

Instances of methodTypes in order
getArgsForTypes
(Class<?>[]
Classes to instantiate
methodTypes
)

Get some default instances of provided classes

public Constructor<?>

Returns:

Constructor to use
getConstructorToUse
(Class<?>
Class in which constructor is searched
clazz
)

Return the constructor considered the best to use with this class.

private static Long
private static byte[]
private boolean

Returns:

If the class is serializable
isSerializable
(Class<?>
Class to check
clazz
)

Tells if the provided class is serializable

public Object
newInstance(Class<?>
Class to instantiate
c
)

Implements org.easymock.internal.IClassInstantiator.newInstance.

Try to instantiate a class without using a special constructor.
private static Object
readObject(byte[] bytes)

private RuntimeException
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTYback to summary
private static final Class<?>[] EMPTY

Constructor Detail

DefaultClassInstantiatorback to summary
public DefaultClassInstantiator()

Method Detail

callLongMethodback to summary
private static Long callLongMethod(Class<?> clazz, String methodName)
classToPrintback to summary
private Class<?> classToPrint(Class<?> clazz)
getArgsForTypesback to summary
public Object[] getArgsForTypes(Class<?>[] methodTypes) throws InstantiationException

Get some default instances of provided classes

Parameters
methodTypes:Class<?>[]

Classes to instantiate

Returns:Object[]

Instances of methodTypes in order

Exceptions
InstantiationException:
Thrown if the class instantiation fails
getConstructorToUseback to summary
public Constructor<?> getConstructorToUse(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<?>

Class in which constructor is searched

Returns:Constructor<?>

Constructor to use

getSerializableUIDback to summary
private static Long getSerializableUID(Class<?> clazz)
getSerializedBytesback to summary
private static byte[] getSerializedBytes(Class<?> clazz) throws IOException
isSerializableback to summary
private boolean isSerializable(Class<?> clazz)

Tells if the provided class is serializable

Parameters
clazz:Class<?>

Class to check

Returns:boolean

If the class is serializable

newInstanceback to summary
public Object newInstance(Class<?> c) throws InstantiationException

Implements org.easymock.internal.IClassInstantiator.newInstance.

Try to instantiate a class without using a special constructor. See documentation for the algorithm.

Parameters
c:Class<?>

Class to instantiate

Returns:Object

Doc from org.easymock.internal.IClassInstantiator.newInstance.

new instance of clazz

Exceptions
InstantiationException:

Doc from org.easymock.internal.IClassInstantiator.newInstance.

when an error occured during instantiation

readObjectback to summary
private static Object readObject(byte[] bytes) throws IOException, ClassNotFoundException
runtimeExceptionback to summary
private RuntimeException runtimeException(Class<?> c, Exception e)