net.sourceforge.xconf.toolbox.easymock
Class MockObjectFactory

java.lang.Object
  extended by net.sourceforge.xconf.toolbox.easymock.MockObjectFactory
All Implemented Interfaces:
MockFactory

public class MockObjectFactory
extends Object
implements MockFactory

This class wraps both an InterfaceMockFactory and a ClassMockFactory, and dynamically figures out which MockFactory to use to create a mock object for a given class. If you don't have the EasyMock class extension library in your classpath, you will not be able to create mock objects for concrete classes, however you will still be able to create mock objects for interfaces as long as you have the basic EasyMock library in your classpath.

Author:
Tom Czarniecki
See Also:
InterfaceMockFactory, ClassMockFactory

Constructor Summary
MockObjectFactory()
           
 
Method Summary
 void clear()
          Clear all created mock objects.
<T> T
createMock(Class<T> toMock)
          Creates an EasyMock mock object with default behaviour semantics for the given class.
<T> T
createNiceMock(Class<T> toMock)
          Creates an EasyMock mock object with nice behaviour semantics for the given class.
<T> T
createStrictMock(Class<T> toMock)
          Creates an EasyMock mock object with strict behaviour semantics for the given class.
 void register(Object mock)
          Register a mock object to be managed by this factory.
 void replay()
          Invokes EasyMock.replay() on all mock objects created by this factory.
 void reset()
          Invokes EasyMock.reset() on all mock objects created by this factory.
 void verify()
          Invokes EasyMock.verify() on all mock objects created by this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockObjectFactory

public MockObjectFactory()
Method Detail

createMock

public <T> T createMock(Class<T> toMock)
Creates an EasyMock mock object with default behaviour semantics for the given class. If the class is not an interface, and the org.easymock.classextension.EasyMock library is available, this method will attempt to create a mock class object.

Specified by:
createMock in interface MockFactory
Throws:
FactoryException - If given a concrete class to mock and the EasyMock class extension library is not available.

createNiceMock

public <T> T createNiceMock(Class<T> toMock)
Creates an EasyMock mock object with nice behaviour semantics for the given class. If the class is not an interface, and the org.easymock.classextension.EasyMock library is available, this method will attempt to create a mock class object.

Specified by:
createNiceMock in interface MockFactory
Throws:
FactoryException - If given a concrete class to mock and the EasyMock class extension library is not available.

createStrictMock

public <T> T createStrictMock(Class<T> toMock)
Creates an EasyMock mock object with strict behaviour semantics for the given class. If the class is not an interface, and the org.easymock.classextension.EasyMock library is available, this method will attempt to create a mock class object.

Specified by:
createStrictMock in interface MockFactory
Throws:
FactoryException - If given a concrete class to mock and the EasyMock class extension library is not available.

replay

public void replay()
Invokes EasyMock.replay() on all mock objects created by this factory.

Specified by:
replay in interface MockFactory

reset

public void reset()
Invokes EasyMock.reset() on all mock objects created by this factory.

Specified by:
reset in interface MockFactory

verify

public void verify()
Invokes EasyMock.verify() on all mock objects created by this factory.

Specified by:
verify in interface MockFactory

clear

public void clear()
Clear all created mock objects.

Specified by:
clear in interface MockFactory

register

public void register(Object mock)
Register a mock object to be managed by this factory. This allows you to create your own mock object and then register it with this factory for replay, reset and verify invocation.

Specified by:
register in interface MockFactory
Throws:
FactoryException - If given a class mock object and the EasyMock class extension library is not available.


Copyright © 2007 Thomas Czarniecki. All Rights Reserved.