org.unitils.mock.mockbehavior.impl
Class ValueReturningMockBehavior

java.lang.Object
  extended by org.unitils.mock.mockbehavior.impl.ValueReturningMockBehavior
All Implemented Interfaces:
MockBehavior, ValidatableMockBehavior

public class ValueReturningMockBehavior
extends Object
implements ValidatableMockBehavior

Mock behavior that returns a given value.

Author:
Filip Neven, Tim Ducheyne, Kenny Claes

Constructor Summary
ValueReturningMockBehavior(Object valueToReturn)
          Creates the returning behavior for the given value.
 
Method Summary
 void assertCanExecute(ProxyInvocation proxyInvocation)
          Checks whether the mock behavior can be executed for the given invocation.
 Object execute(ProxyInvocation proxyInvocation)
          Executes the mock behavior.
protected  Object unwrapValueToReturnIfNeeded(Object valueToReturn)
          If the value to return is an wrapper object, e.g. a mock, this will return the wrapped instance instead of the wrapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValueReturningMockBehavior

public ValueReturningMockBehavior(Object valueToReturn)
Creates the returning behavior for the given value.

Parameters:
valueToReturn - The value
Method Detail

assertCanExecute

public void assertCanExecute(ProxyInvocation proxyInvocation)
                      throws UnitilsException
Checks whether the mock behavior can be executed for the given invocation. An exception is raised if the method is a void method or has a non-assignable return type.

Specified by:
assertCanExecute in interface ValidatableMockBehavior
Parameters:
proxyInvocation - The proxy method invocation, not null
Throws:
UnitilsException

execute

public Object execute(ProxyInvocation proxyInvocation)
Executes the mock behavior.

Specified by:
execute in interface MockBehavior
Parameters:
proxyInvocation - The proxy method invocation, not null
Returns:
The value

unwrapValueToReturnIfNeeded

protected Object unwrapValueToReturnIfNeeded(Object valueToReturn)
If the value to return is an wrapper object, e.g. a mock, this will return the wrapped instance instead of the wrapper.

Parameters:
valueToReturn - The return value
Returns:
The return value or the wrapped object if unwrapped


Copyright © 2011. All Rights Reserved.