Package org.jmock.internal
Class ReturnDefaultValueAction
- java.lang.Object
-
- org.jmock.internal.ReturnDefaultValueAction
-
public class ReturnDefaultValueAction extends java.lang.Object implements Action
Returns a default value for the invoked method's result type.- Returns nothing from void methods.
- Returns zero or false results for primitive types.
- Returns zero length instances for arrays and strings.
- Returns empty instances for collections and maps types in
java.util
. - Returns imposterised Null Objects for
types that can be imposterised by the action's
Imposteriser
. - Otherwise returns
null
.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<?>[]
CONCRETE_COLLECTION_TYPES
private Imposteriser
imposteriser
private java.util.Map<java.lang.Class<?>,java.lang.Object>
resultValuesByType
-
Constructor Summary
Constructors Constructor Description ReturnDefaultValueAction()
ReturnDefaultValueAction(Imposteriser imposteriser)
ReturnDefaultValueAction(Imposteriser imposteriser, java.util.Map<java.lang.Class<?>,java.lang.Object> typeToResultValue)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addResult(java.lang.Class<?> resultType, java.lang.Object resultValue)
private static boolean
cannotCreateNewInstance(java.lang.Class<?> returnType)
private static java.lang.Object
collectionOrMapInstanceFor(java.lang.Class<?> returnType)
protected static java.util.Map<java.lang.Class<?>,java.lang.Object>
createDefaultResults()
void
describeTo(org.hamcrest.Description description)
private static java.lang.Object
instanceForCollectionType(java.lang.Class<?> type)
java.lang.Object
invoke(Invocation invocation)
Performs an action in response to an invocation.private static boolean
isCollectionOrMap(java.lang.Class<?> type)
void
setImposteriser(Imposteriser newImposteriser)
-
-
-
Field Detail
-
CONCRETE_COLLECTION_TYPES
private static final java.lang.Class<?>[] CONCRETE_COLLECTION_TYPES
-
resultValuesByType
private final java.util.Map<java.lang.Class<?>,java.lang.Object> resultValuesByType
-
imposteriser
private Imposteriser imposteriser
-
-
Constructor Detail
-
ReturnDefaultValueAction
public ReturnDefaultValueAction(Imposteriser imposteriser, java.util.Map<java.lang.Class<?>,java.lang.Object> typeToResultValue)
-
ReturnDefaultValueAction
public ReturnDefaultValueAction(Imposteriser imposteriser)
-
ReturnDefaultValueAction
public ReturnDefaultValueAction()
-
-
Method Detail
-
setImposteriser
public void setImposteriser(Imposteriser newImposteriser)
-
describeTo
public void describeTo(org.hamcrest.Description description)
- Specified by:
describeTo
in interfaceorg.hamcrest.SelfDescribing
-
addResult
public void addResult(java.lang.Class<?> resultType, java.lang.Object resultValue)
-
invoke
public java.lang.Object invoke(Invocation invocation) throws java.lang.Throwable
Description copied from interface:Invokable
Performs an action in response to an invocation.- Specified by:
invoke
in interfaceInvokable
- Parameters:
invocation
- The invocation to perform.- Returns:
- The result of the invocation, if not throwing an exception.
Must return
null
if the invoked method has a void return type. - Throws:
java.lang.Throwable
- An exception to be thrown to the caller, if not returning a value. Any checked exception thrown must be in thethrows
list of the invoked method.
-
collectionOrMapInstanceFor
private static java.lang.Object collectionOrMapInstanceFor(java.lang.Class<?> returnType) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
instanceForCollectionType
private static java.lang.Object instanceForCollectionType(java.lang.Class<?> type) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
isCollectionOrMap
private static boolean isCollectionOrMap(java.lang.Class<?> type)
-
cannotCreateNewInstance
private static boolean cannotCreateNewInstance(java.lang.Class<?> returnType)
-
createDefaultResults
protected static java.util.Map<java.lang.Class<?>,java.lang.Object> createDefaultResults()
-
-