org.unitils.easymock
Class EasyMockUnitils

java.lang.Object
  extended by org.unitils.easymock.EasyMockUnitils

public class EasyMockUnitils
extends Object

Utility facade for handling EasyMock things such as replay or manually creating a mock.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
EasyMockUnitils()
           
 
Method Summary
static
<T> T
createMock(Class<T> mockType)
          Creates a lenient mock object of the given type.
static
<T> T
createMock(Class<T> mockType, InvocationOrder invocationOrder, Calls calls, Order order, Dates dates, Defaults defaults)
          Creates a lenient mock object of the given type.
static
<T> T
createRegularMock(Class<T> mockType)
          Creates a regular EasyMock mock object of the given type.
static
<T> T
createRegularMock(Class<T> mockType, InvocationOrder invocationOrder, Calls calls)
          Creates a regular EasyMock mock object of the given type.
static
<T> T
lenEq(T object)
          Expects the given object argument but uses a reflection argument matcher to compare the given value with the actual value during the test.
static
<T> T
refEq(T object, ReflectionComparatorMode... modes)
          Expects the given object argument but uses a reflection argument matcher with the given comparator modes to compare the given value with the actual value during the test.
static void replay()
          Unit tests should call this method after having set their recorded expected behavior on the mock objects.
static void reset()
           
static void verify()
          Unit tests can call this method to check whether all recorded expected behavior was actually observed during the test.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EasyMockUnitils

public EasyMockUnitils()
Method Detail

lenEq

public static <T> T lenEq(T object)
Expects the given object argument but uses a reflection argument matcher to compare the given value with the actual value during the test. The comparator modes are set to ignore defaults and lenient order.

Same as refEq with ignore defaults and lenient order as comparator modes.

Type Parameters:
T - The type of the object to compare with
Parameters:
object - the value
Returns:
null

refEq

public static <T> T refEq(T object,
                          ReflectionComparatorMode... modes)
Expects the given object argument but uses a reflection argument matcher with the given comparator modes to compare the given value with the actual value during the test.

Type Parameters:
T - the type of the object to compare with
Parameters:
object - the value
modes - the comparator modes
Returns:
null

createRegularMock

public static <T> T createRegularMock(Class<T> mockType)
Creates a regular EasyMock mock object of the given type.

Same as createRegularMock(Class, InvocationOrder, Calls) with a default invocation order and default calls value. These defaults can be set in the unitils configuration.

An instance of the mock control is stored, so that it can be set to the replay/verify state when replay() or verify() is called.

Type Parameters:
T - the type of the mock
Parameters:
mockType - the type of the mock, not null
Returns:
a mock for the given class or interface, not null

createRegularMock

public static <T> T createRegularMock(Class<T> mockType,
                                      InvocationOrder invocationOrder,
                                      Calls calls)
Creates a regular EasyMock mock object of the given type.

An instance of the mock control is stored, so that it can be set to the replay/verify state when replay() or verify() is called.

Type Parameters:
T - the type of the mock
Parameters:
mockType - the class type for the mock, not null
invocationOrder - the order setting, not null
calls - the calls setting, not null
Returns:
a mock for the given class or interface, not null

createMock

public static <T> T createMock(Class<T> mockType)
Creates a lenient mock object of the given type. The LenientMocksControl is used for creating the mock.

Same as createMock(Class, InvocationOrder, Calls, Order, Dates, Defaults) with a default invocation order, default calls, default order, default dates and default defaults value. These defaults can be set in the unitils configuration.

An instance of the mock control is stored, so that it can be set to the replay/verify state when replay() or verify() is called.

Type Parameters:
T - the type of the mock
Parameters:
mockType - the type of the mock, not null
Returns:
a mock for the given class or interface, not null

createMock

public static <T> T createMock(Class<T> mockType,
                               InvocationOrder invocationOrder,
                               Calls calls,
                               Order order,
                               Dates dates,
                               Defaults defaults)
Creates a lenient mock object of the given type. The LenientMocksControl is used for creating the mock.

Same as createMock(Class, InvocationOrder, Calls, Order, Dates, Defaults) with a default invocation order, default calls, default order, default dates and default defaults value. These defaults can be set in the unitils configuration.

An instance of the mock control is stored, so that it can be set to the replay/verify state when replay() or verify() is called.

Type Parameters:
T - the type of the mock
Parameters:
mockType - the type of the mock, not null
invocationOrder - the invocation order setting, not null
calls - the calls setting, not null
order - the order setting, not null
dates - the dates setting, not null
defaults - the defaults setting, not null
Returns:
a mock for the given class or interface, not null

replay

public static void replay()
Unit tests should call this method after having set their recorded expected behavior on the mock objects.

This method makes sure EasyMock's replay method is called on every mock object that was supplied to the fields annotated with Mock, or directly created by the createRegularMock(Class, InvocationOrder, Calls) and createMock(Class, InvocationOrder, Calls, Order, Dates, Defaults) methods.

After each test, the expected behavior is verified automatically, or explicitly by calling verify().


reset

public static void reset()

verify

public static void verify()
Unit tests can call this method to check whether all recorded expected behavior was actually observed during the test.

This method makes sure MocksControl.verify() method is called for every mock mock object that was injected to a field annotated with Mock, or directly created by the createRegularMock(Class, InvocationOrder, Calls) or createMock(Class, InvocationOrder, Calls, Order, Dates, Defaults) methods.

By default, the expected behavior is verified automatically. This can be disabled however by setting the property EasyMockModule.autoVerifyAfterTest.enabled to false. In that case, verification can also be performed explicitly by calling this method.



Copyright © 2011. All Rights Reserved.