org.jmock.expectation
Class ReturnValue

java.lang.Object
  extended by org.jmock.expectation.ReturnValue

public class ReturnValue
extends 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(); }

Version:
$Revision: 1.5 $

Constructor Summary
ReturnValue(String name)
           
 
Method Summary
 boolean getBooleanValue()
           
 int getIntValue()
           
 long getLongValue()
           
 Object getValue()
           
 void setValue(boolean value)
           
 void setValue(int value)
           
 void setValue(long value)
           
 void setValue(Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReturnValue

public ReturnValue(String name)
Parameters:
name - the name used to identify the ReturnValue when an error is raised
Method Detail

getValue

public Object getValue()
Returns:
the value set using setValue
Throws:
AssertionFailedError - throw if setValue has not been called

setValue

public void setValue(Object value)
Parameters:
value - value to be returned by getValue. null can be use to force getValue to return null.

setValue

public void setValue(boolean value)
Parameters:
value - value to be returned by getBooleanValue. Calling getValue after this invokedMethod will return a Boolean wrapper around the value.

getBooleanValue

public boolean getBooleanValue()
Returns:
the current value converted to a boolean

getIntValue

public int getIntValue()
Returns:
the current value converted to an int

setValue

public void setValue(int value)
Parameters:
value - value to be returned by getIntValue. Calling getValue after this invokedMethod will return a Integer wrapper around the value.

setValue

public void setValue(long value)
Parameters:
value - value to be returned by getLongValue. Calling getValue after this invokedMethod will return a Long wrapper around the value.

getLongValue

public long getLongValue()
Returns:
the current value converted to an long