org.unitils.mock
Class MockModule

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

public class MockModule
extends java.lang.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.
 
Field Summary
protected  boolean logDetailedObservedScenario
           
protected  boolean logFullScenarioReport
           
protected  boolean logObservedScenario
           
protected  boolean logSuggestedAsserts
           
static java.lang.String PROPERTY_LOG_DETAILED_OBSERVED_SCENARIO
           
static java.lang.String PROPERTY_LOG_FULL_SCENARIO_REPORT
           
static java.lang.String PROPERTY_LOG_OBSERVED_SCENARIO
           
static java.lang.String PROPERTY_LOG_SUGGESTED_ASSERTS
           
 
Constructor Summary
MockModule()
           
 
Method Summary
 void afterInit()
          No after initialization needed for this module
protected  void callAfterCreateMockMethods(java.lang.Object testObject, Mock<?> mockObject, java.lang.String name, java.lang.Class<?> type)
          Calls all AfterCreateMock annotated methods on the test, passing the given mock.
protected  void createAndInjectDummiesIntoTest(java.lang.Object testObject)
           
protected  void createAndInjectMocksIntoTest(java.lang.Object testObject)
           
protected  void createAndInjectPartialMocksIntoTest(java.lang.Object testObject)
           
<T> Mock<T>
createMock(java.lang.Object testObject, java.lang.String name, java.lang.Class<?> type)
           
<T> Mock<T>
createPartialMock(java.lang.Object testObject, java.lang.String name, java.lang.Class<?> type)
           
protected  java.lang.Class<?> getMockedClass(java.lang.reflect.Field field)
           
 Scenario getScenario()
           
 TestListener getTestListener()
          Creates the listener for plugging in the behavior of this module into the test runs.
 void init(java.util.Properties configuration)
          No initialization needed for this module
protected  void injectMock(java.lang.Object testObject, java.lang.reflect.Field field, Mock<?> mock)
           
 void logDetailedObservedScenario()
           
 void logFullScenarioReport()
           
 void logObservedScenario()
           
 void logSuggestedAsserts()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_LOG_FULL_SCENARIO_REPORT

public static final java.lang.String PROPERTY_LOG_FULL_SCENARIO_REPORT
See Also:
Constant Field Values

PROPERTY_LOG_OBSERVED_SCENARIO

public static final java.lang.String PROPERTY_LOG_OBSERVED_SCENARIO
See Also:
Constant Field Values

PROPERTY_LOG_DETAILED_OBSERVED_SCENARIO

public static final java.lang.String PROPERTY_LOG_DETAILED_OBSERVED_SCENARIO
See Also:
Constant Field Values

PROPERTY_LOG_SUGGESTED_ASSERTS

public static final java.lang.String PROPERTY_LOG_SUGGESTED_ASSERTS
See Also:
Constant Field Values

logFullScenarioReport

protected boolean logFullScenarioReport

logObservedScenario

protected boolean logObservedScenario

logDetailedObservedScenario

protected boolean logDetailedObservedScenario

logSuggestedAsserts

protected boolean logSuggestedAsserts
Constructor Detail

MockModule

public MockModule()
Method Detail

init

public void init(java.util.Properties configuration)
No initialization needed for this module

Specified by:
init in interface Module

afterInit

public void afterInit()
No after initialization needed for this module

Specified by:
afterInit in interface Module

getScenario

public Scenario getScenario()

logFullScenarioReport

public void logFullScenarioReport()

logObservedScenario

public void logObservedScenario()

logDetailedObservedScenario

public void logDetailedObservedScenario()

logSuggestedAsserts

public void logSuggestedAsserts()

createMock

public <T> Mock<T> createMock(java.lang.Object testObject,
                              java.lang.String name,
                              java.lang.Class<?> type)

createPartialMock

public <T> Mock<T> createPartialMock(java.lang.Object testObject,
                                     java.lang.String name,
                                     java.lang.Class<?> type)

getMockedClass

protected java.lang.Class<?> getMockedClass(java.lang.reflect.Field field)

createAndInjectMocksIntoTest

protected void createAndInjectMocksIntoTest(java.lang.Object testObject)

createAndInjectPartialMocksIntoTest

protected void createAndInjectPartialMocksIntoTest(java.lang.Object testObject)

injectMock

protected void injectMock(java.lang.Object testObject,
                          java.lang.reflect.Field field,
                          Mock<?> mock)

createAndInjectDummiesIntoTest

protected void createAndInjectDummiesIntoTest(java.lang.Object testObject)

callAfterCreateMockMethods

protected void callAfterCreateMockMethods(java.lang.Object testObject,
                                          Mock<?> mockObject,
                                          java.lang.String name,
                                          java.lang.Class<?> type)
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
type - the field(=mock) type

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 © 2009. All Rights Reserved.