Class ReturnDefaultValueAction
java.lang.Object
org.jmock.internal.ReturnDefaultValueAction
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 -
Constructor Summary
ConstructorsConstructorDescriptionReturnDefaultValueAction(Imposteriser imposteriser) ReturnDefaultValueAction(Imposteriser imposteriser, Map<Class<?>, Object> typeToResultValue) -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate static booleancannotCreateNewInstance(Class<?> returnType) private static ObjectcollectionOrMapInstanceFor(Class<?> returnType) voiddescribeTo(org.hamcrest.Description description) private static ObjectinstanceForCollectionType(Class<?> type) invoke(Invocation invocation) Performs an action in response to an invocation.private static booleanisCollectionOrMap(Class<?> type) voidsetImposteriser(Imposteriser newImposteriser)
-
Field Details
-
CONCRETE_COLLECTION_TYPES
-
resultValuesByType
-
imposteriser
-
-
Constructor Details
-
ReturnDefaultValueAction
-
ReturnDefaultValueAction
-
ReturnDefaultValueAction
public ReturnDefaultValueAction()
-
-
Method Details
-
setImposteriser
-
describeTo
public void describeTo(org.hamcrest.Description description) - Specified by:
describeToin interfaceorg.hamcrest.SelfDescribing
-
addResult
-
invoke
Description copied from interface:InvokablePerforms an action in response to an invocation.- Specified by:
invokein interfaceInvokable- Parameters:
invocation- The invocation to perform.- Returns:
- The result of the invocation, if not throwing an exception.
Must return
nullif the invoked method has a void return type. - Throws:
Throwable- An exception to be thrown to the caller, if not returning a value. Any checked exception thrown must be in thethrowslist of the invoked method.
-
collectionOrMapInstanceFor
-
instanceForCollectionType
-
isCollectionOrMap
-
cannotCreateNewInstance
-
createDefaultResults
-