org.unitils.mock
Class MockModule

java.lang.Object
  extended by org.unitils.mock.MockModule
All Implemented Interfaces:
Module

public class MockModule
extends Object
implements Module

Module for testing with mock objects.

Author:
Filip Neven, Tim Ducheyne, Kenny Claes

Nested Class Summary
protected  class MockModule.MockTestListener
          Test listener that handles the scenario and mock creation, and makes sure a final syntax check is performed after each test and that scenario reports are logged if required.
 
Constructor Summary
MockModule()
           
 
Method Summary
 void afterInit()
          Gives the module the opportunity to performs initialization that can only work after all other modules have been initialized
protected  void callAfterCreateMockMethods(Object testObject, Mock<?> mockObject, String name)
          Calls all AfterCreateMock annotated methods on the test, passing the given mock.
protected  void createAndInjectDummiesIntoTest(Object testObject)
          checks for the Dummy annotation on the testObject.
protected  void createAndInjectMocksIntoTest(Object testObject)
           
protected  void createAndInjectPartialMocksIntoTest(Object testObject)
           
protected
<T> Mock<T>
createMock(Object testObject, String name, Class<?> type)
           
protected
<T> Mock<T>
createPartialMock(Object testObject, String name, Class<?> type)
           
protected  Class<?> getMockedClass(Field field)
           
 TestListener getTestListener()
          Creates the listener for plugging in the behavior of this module into the test runs.
 void init(Properties configuration)
          Initializes the module with the given configuration settings.
protected  void injectMock(Object testObject, Field field, Mock<?> mock)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockModule

public MockModule()
Method Detail

init

public void init(Properties configuration)
Description copied from interface: Module
Initializes the module with the given configuration settings.

Specified by:
init in interface Module
Parameters:
configuration - The config, not null

afterInit

public void afterInit()
Description copied from interface: Module
Gives the module the opportunity to performs initialization that can only work after all other modules have been initialized

Specified by:
afterInit in interface Module

createAndInjectMocksIntoTest

protected void createAndInjectMocksIntoTest(Object testObject)

createAndInjectPartialMocksIntoTest

protected void createAndInjectPartialMocksIntoTest(Object testObject)

createMock

protected <T> Mock<T> createMock(Object testObject,
                                 String name,
                                 Class<?> type)

createPartialMock

protected <T> Mock<T> createPartialMock(Object testObject,
                                        String name,
                                        Class<?> type)

getMockedClass

protected Class<?> getMockedClass(Field field)

injectMock

protected void injectMock(Object testObject,
                          Field field,
                          Mock<?> mock)

createAndInjectDummiesIntoTest

protected void createAndInjectDummiesIntoTest(Object testObject)
checks for the Dummy annotation on the testObject. If so it is created by the DummyObjectUtil. The two aproaches possible are stuffed or normal depending on the value in the Dummy annotation.

Parameters:
testObject - The tested object not null

callAfterCreateMockMethods

protected void callAfterCreateMockMethods(Object testObject,
                                          Mock<?> mockObject,
                                          String name)
Calls all 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.

Parameters:
testObject - the test, not null
mockObject - the mock, not null
name - the field(=mock) name, not null

getTestListener

public TestListener getTestListener()
Creates the listener for plugging in the behavior of this module into the test runs.

Specified by:
getTestListener in interface Module
Returns:
the listener


Copyright © 2011. All Rights Reserved.