org.unitils.easymock.util
Class LenientMocksControl

java.lang.Object
  extended by org.easymock.internal.MocksControl
      extended by org.easymock.classextension.internal.MocksClassControl
          extended by org.unitils.easymock.util.LenientMocksControl
All Implemented Interfaces:
org.easymock.IExpectationSetters, org.easymock.IMocksControl

public class LenientMocksControl
extends org.easymock.classextension.internal.MocksClassControl

An EasyMock mock control that uses the reflection argument matcher for all arguments of a method invocation.

No explicit argument matcher setting is needed (or allowed). This control will automatically report lenient reflection argument matchers. These matchers can apply some leniency when comparing expected and actual argument values.

Setting the ReflectionComparatorMode.IGNORE_DEFAULTS mode will for example ignore all fields that have default values as expected values. E.g. if a null value is recorded as argument it will not be checked when the actual invocation occurs. The same applies for inner-fields of object arguments that contain default java values.

Setting the ReflectionComparatorMode.LENIENT_DATES mode will ignore the actual date values of arguments and inner fields of arguments. It will only check whether both dates are null or both dates are not null. The actual date and hour do not matter.

Setting the ReflectionComparatorMode.LENIENT_ORDER mode will ignore the actual order of collections and arrays arguments and inner fields of arguments. It will only check whether they both contain the same elements.

Author:
Tim Ducheyne, Filip Neven
See Also:
ReflectionComparatorMode, ReflectionComparator

Nested Class Summary
 
Nested classes/interfaces inherited from class org.easymock.internal.MocksControl
org.easymock.internal.MocksControl.MockType
 
Field Summary
 
Fields inherited from class org.easymock.internal.MocksControl
AT_LEAST_ONCE, ONCE, ZERO_OR_MORE
 
Constructor Summary
LenientMocksControl(org.easymock.internal.MocksControl.MockType type, ReflectionComparatorMode... modes)
          Creates a mock control.
LenientMocksControl(ReflectionComparatorMode... modes)
          Creates a default (no default returns and no order checking) mock control.
 
Method Summary
 org.easymock.internal.IMocksControlState getState()
          Overriden to be able to replace the record behavior that going to record all method invocations.
 
Methods inherited from class org.easymock.classextension.internal.MocksClassControl
createMock, createMock, createMock, createMock, createProxyFactory
 
Methods inherited from class org.easymock.internal.MocksControl
andAnswer, andReturn, andStubAnswer, andStubReturn, andStubThrow, andThrow, anyTimes, asStub, atLeastOnce, checkOrder, createMock, createMock, once, replay, reset, setLegacyDefaultMatcher, setLegacyDefaultReturnValue, setLegacyDefaultThrowable, setLegacyDefaultVoidCallable, setLegacyMatcher, times, times, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.easymock.IMocksControl
checkOrder, createMock, createMock, replay, reset, verify
 
Methods inherited from interface org.easymock.IExpectationSetters
andAnswer, andReturn, andStubAnswer, andStubReturn, andStubThrow, andThrow, anyTimes, asStub, atLeastOnce, once, times, times
 

Constructor Detail

LenientMocksControl

public LenientMocksControl(ReflectionComparatorMode... modes)
Creates a default (no default returns and no order checking) mock control.

Parameters:
modes - the modes for the reflection argument matcher

LenientMocksControl

public LenientMocksControl(org.easymock.internal.MocksControl.MockType type,
                           ReflectionComparatorMode... modes)
Creates a mock control.

Parameters:
type - the EasyMock mock type
modes - the modes for the reflection argument matcher
Method Detail

getState

public org.easymock.internal.IMocksControlState getState()
Overriden to be able to replace the record behavior that going to record all method invocations. The interceptor will make sure that reflection argument matchers will be reported for the arguments of all recorded method invocations.

Overrides:
getState in class org.easymock.internal.MocksControl
Returns:
the state, wrapped in case of a RecordState


Copyright © 2011. All Rights Reserved.