|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.easymock.EasyMockModule
public class EasyMockModule
Module for testing with mock objects using EasyMock.
Mock creation is simplified by automatically inserting EasyMock generated mocks for fields annotated with theMock
annotation.
All methods annotated with AfterCreateMock
will be called when a mock object was created. This provides
you with a hook method for custom handling of the mock (e.g. adding the mocks to a service locator repository).
A method can only be called if it has following signature void myMethod(Object mock, String name, Class type)
.
Mocks can also be created explicitly
todo javadoc
Switching to the replay state and verifying expectations of all mocks (including the mocks created with
the createMock() method can be done by calling
the replay()
and verify()
methods.
Nested Class Summary | |
---|---|
protected class |
EasyMockModule.EasyMockTestListener
Test listener that handles the mock creation and injection. |
Field Summary | |
---|---|
static String |
PROPKEY_AUTO_VERIFY_AFTER_TEST_ENABLED
|
Constructor Summary | |
---|---|
EasyMockModule()
|
Method Summary | ||
---|---|---|
void |
afterInit()
No after initialization needed for this module |
|
protected void |
callAfterCreateMockMethods(Object testObject,
Object mockObject,
String name,
Class<?> type)
Calls all AfterCreateMock annotated methods on the test, passing the given mock. |
|
protected void |
createAndInjectMocksIntoTest(Object testObject)
|
|
protected void |
createAndInjectRegularMocksIntoTest(Object testObject)
Creates and sets a mock for all RegularMock annotated fields. |
|
|
createMock(Class<T> mockType,
InvocationOrder invocationOrder,
Calls calls,
Order order,
Dates dates,
Defaults defaults)
todo javadoc Creates an EasyMock mock instance of the given type (class/interface). |
|
|
createRegularMock(Class<T> mockType,
InvocationOrder invocationOrder,
Calls calls)
Creates an EasyMock mock object of the given type. |
|
TestListener |
getTestListener()
Creates the listener for plugging in the behavior of this module into the test runs. |
|
void |
init(Properties configuration)
Initializes the module |
|
void |
replay()
Replays all mock controls. |
|
void |
reset()
Resets all mock controls. |
|
void |
verify()
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 calling
createRegularMock(Class, InvocationOrder, Calls) or
createMock(Class, InvocationOrder, Calls, Order, Dates, Defaults) . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PROPKEY_AUTO_VERIFY_AFTER_TEST_ENABLED
Constructor Detail |
---|
public EasyMockModule()
Method Detail |
---|
public void init(Properties configuration)
init
in interface Module
configuration
- The config, not nullpublic void afterInit()
afterInit
in interface Module
public TestListener getTestListener()
getTestListener
in interface Module
public <T> T createRegularMock(Class<T> mockType, InvocationOrder invocationOrder, Calls calls)
replay()
or verify()
is called.
T
- the type of the mockmockType
- the class type for the mock, not nullinvocationOrder
- the order setting, not nullcalls
- the calls setting, not null
public <T> T createMock(Class<T> mockType, InvocationOrder invocationOrder, Calls calls, Order order, Dates dates, Defaults defaults)
T
- the type of the mockmockType
- the type of the mock, not nullinvocationOrder
- the order setting, not nullcalls
- the calls setting, not nullorder
- tododates
- tododefaults
- todo
public void replay()
public void reset()
public void verify()
MocksControl.verify()
method is called for every mock mock object
that was injected to a field annotated with Mock
, or directly created by calling
createRegularMock(Class, InvocationOrder, Calls)
or
createMock(Class, InvocationOrder, Calls, Order, Dates, Defaults)
.
If there are mocks that weren't already switched to the replay state using MocksControl.replay()
} or by
calling EasyMockUnitils.replay()
, this method is called first.
protected void createAndInjectRegularMocksIntoTest(Object testObject)
RegularMock
annotated fields.
The
todo javadoc
method is called for creating the mocks. Ones the mock is created, all methods annotated with AfterCreateMock
will be called passing the created mock.
testObject
- the test, not nullprotected void createAndInjectMocksIntoTest(Object testObject)
protected void callAfterCreateMockMethods(Object testObject, Object mockObject, String name, Class<?> type)
AfterCreateMock
annotated methods on the test, passing the given mock.
These annotated methods must have following signature void myMethod(Object mock, String name, Class type)
.
If this is not the case, a runtime exception is called.
testObject
- the test, not nullmockObject
- the mock, not nullname
- the field(=mock) name, not nulltype
- the field(=mock) type
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |