org.unitils.mock.mockbehavior.impl
Class DefaultValueReturningMockBehavior

java.lang.Object
  extended by org.unitils.mock.mockbehavior.impl.DefaultValueReturningMockBehavior
All Implemented Interfaces:
MockBehavior, ValidatableMockBehavior
Direct Known Subclasses:
DummyValueReturningMockBehavior, StubMockBehavior

public class DefaultValueReturningMockBehavior
extends Object
implements ValidatableMockBehavior

Mock behavior that returns a default value.

Following defaults are used:

Author:
Filip Neven, Tim Ducheyne, Kenny Claes

Constructor Summary
DefaultValueReturningMockBehavior()
           
 
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  Number resolveNumber(Class<?> numberType)
          Checking for the default java implementations of Number, this avoids class cast exceptions when using them
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultValueReturningMockBehavior

public DefaultValueReturningMockBehavior()
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.

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 default value

resolveNumber

protected Number resolveNumber(Class<?> numberType)
Checking for the default java implementations of Number, this avoids class cast exceptions when using them

Parameters:
numberType - The number type, not null
Returns:
The default value for that number type, e.g. 0F for floats


Copyright © 2011. All Rights Reserved.