public class ReturnValue
extends java.lang.Object
The ReturnValue class allows a value to be setup which will then be returned upon a specific
invokedMethod call. If value.getValue() is called before value.setValue(value)
the ReturnValue will raise an error warning that this value has not been set. If the required
return value is null
the return value can be set like this
value.setValue(null)
in this case calling value.getValue()
will return null.
The advantage of this is provide better information to the user of a mock when interacting with third party code which may expect certain values to have been set.
e.g.private final ReturnValue value = new ReturnValue("value"); public void setupValue(Integer value){ value.setValue(value); } public Integer getValue(){ return (Integer)value.getValue(); }
Constructor and Description |
---|
ReturnValue(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
boolean |
getBooleanValue() |
int |
getIntValue() |
long |
getLongValue() |
java.lang.Object |
getValue() |
void |
setValue(boolean value) |
void |
setValue(int value) |
void |
setValue(long value) |
void |
setValue(java.lang.Object value) |
public ReturnValue(java.lang.String name)
name
- the name used to identify the ReturnValue when an error is raisedpublic java.lang.Object getValue()
junit.framework.AssertionFailedError
- throw if setValue has not been calledpublic void setValue(java.lang.Object value)
value
- value to be returned by getValue. null can be use to force getValue to return null.public void setValue(boolean value)
value
- value to be returned by getBooleanValue. Calling getValue after this invokedMethod will return
a Boolean wrapper around the value.public boolean getBooleanValue()
public int getIntValue()
public void setValue(int value)
value
- value to be returned by getIntValue. Calling getValue after this invokedMethod will return
a Integer wrapper around the value.public void setValue(long value)
value
- value to be returned by getLongValue. Calling getValue after this invokedMethod will return
a Long wrapper around the value.public long getLongValue()