nl.beesting.util
Class MockingTest

java.lang.Object
  extended by nl.beesting.util.MockingTest

public abstract class MockingTest
extends java.lang.Object

Abstract parent test class that takes care of setting up some easymock stuff.


Constructor Summary
MockingTest()
           
 
Method Summary
protected  void clear()
          Clear the mock cache.
protected
<T> T
createMock(java.lang.Class<T> clazz)
          Creates an EasyMock mock, and adds it to the cache so that we can easily replay and verify all mocks simultaneously.
protected
<T> T
createNiceMock(java.lang.Class<T> clazz)
          Creates a "nice" EasyMock mock and adds it to the cache.
protected  java.lang.Object getValue(java.lang.Object instance, java.lang.String field)
          Helper method to get a value from an instance which doesn't have a getter for the field.
protected  void replayAll()
          Replay all mocks in the class.
static void setValue(java.lang.Object instance, java.lang.String field, java.lang.Object value)
          Helper method to set a value on an instance which doesn't have a setter for the field.
 void tearDown()
          Clears the mock cache after each method.
protected  void verifyAll()
          Verify all mocks in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockingTest

public MockingTest()
Method Detail

tearDown

public void tearDown()
Clears the mock cache after each method.


createMock

protected <T> T createMock(java.lang.Class<T> clazz)
Creates an EasyMock mock, and adds it to the cache so that we can easily replay and verify all mocks simultaneously.

Type Parameters:
T - The type of the mock that should be returned.
Parameters:
clazz - The class or interface to create a mock of.
Returns:
A newly created mock.

createNiceMock

protected <T> T createNiceMock(java.lang.Class<T> clazz)
Creates a "nice" EasyMock mock and adds it to the cache.

Type Parameters:
T - the type of the mock that should be returned.
Parameters:
clazz - The class of interface to create a mock of.
Returns:
A newly created "nice" mock.

verifyAll

protected void verifyAll()
Verify all mocks in the cache.


replayAll

protected void replayAll()
Replay all mocks in the class.


clear

protected void clear()
Clear the mock cache.


setValue

public static void setValue(java.lang.Object instance,
                            java.lang.String field,
                            java.lang.Object value)
                     throws java.lang.NoSuchFieldException,
                            java.lang.IllegalAccessException
Helper method to set a value on an instance which doesn't have a setter for the field.

Parameters:
instance - the instance to set the value on.
field - The field to set the value on.
value - The value to set on the field of the instance.
Throws:
java.lang.NoSuchFieldException - If the field could not be found in the class of the instance or any of its superclasses.
java.lang.IllegalAccessException - If the field could not be set.

getValue

protected java.lang.Object getValue(java.lang.Object instance,
                                    java.lang.String field)
                             throws java.lang.NoSuchFieldException,
                                    java.lang.IllegalAccessException
Helper method to get a value from an instance which doesn't have a getter for the field.

Parameters:
instance - The instance to get the value of.
field - The field to get the value from.
Returns:
The value of the field of the instance.
Throws:
java.lang.NoSuchFieldException - If the field could not be found in the class of the instance or any of its superclasses.
java.lang.IllegalAccessException - If the field could not be get.


Copyright © 2008. All Rights Reserved.