@Deprecated public class MockController extends Object
MockControl
objects to mock out
interfaces in unit tests.
It provides automatic MockControl creation and invocation, as well as consistent replay and verification of all mock
objects.
It assumes a certain pattern of unit test. This class should not be used / extended from anymore as the current approach to unit testing in JIRA is
to use Mockito
.
Modifier and Type | Class and Description |
---|---|
static class |
MockController.ControllerState
Deprecated.
An enumeration to show the different states of the MockController
|
Constructor and Description |
---|
MockController()
Deprecated.
Instantiates a MockController that produces strict MockControl objects by default
|
Modifier and Type | Method and Description |
---|---|
<T> T |
addObjectInstance(T objectInstance)
Deprecated.
This method allow you to add an actual object instance to be added into the mix.
|
<T> T |
createMock(Class<T> aClass)
Deprecated.
Synonym for
getMock(Class) to be more EasyMock like |
static MockController |
createNiceContoller()
Deprecated.
|
<T> T |
createNiceMock(Class<T> aClass)
Deprecated.
Synonym for
getNiceMock(Class) to be more EasyMock like |
static MockController |
createStrictContoller()
Deprecated.
|
<T> T |
createStrictMock(Class<T> aClass)
Deprecated.
Synonym for
getStrictMock(Class) to be more EasyMock like |
org.easymock.MockControl |
getCurrentMockControl()
Deprecated.
This method allows you access to the current MockControl.
|
<T> T |
getMock(Class<T> aClass)
Deprecated.
This returns a mocked out implementation of aClass AND creates a
MockControl under to covers for this
interface. |
org.easymock.MockControl |
getMockControl(Class<?> interfaceClass)
Deprecated.
This method allows you access to the underlying MockControl objects.
|
List<org.easymock.MockControl> |
getMockControls()
Deprecated.
This method allows you access to the MockControl instances that have been created by this MockController.
|
List<Object> |
getMockedObjects()
Deprecated.
This method allows you access to the mocked object instances that have been mocked out by this MockController.
|
List<Class<?>> |
getMockedTypes()
Deprecated.
This method allows you access to the interfaces and classes that have been mocked out by this MockController.
|
<T> T |
getNiceMock(Class<T> aClass)
Deprecated.
This returns a mocked out implementation of aClass AND creates a nice
MockControl under to covers for
this interface. |
List<Object> |
getObjectInstances()
Deprecated.
This method allows you access to the object instances that have been placed in the mix by called to
addObjectInstance(Object) . |
MockController.ControllerState |
getState()
Deprecated.
Returns the current state of the MockController
|
<T> T |
getStrictMock(Class<T> aClass)
Deprecated.
This returns a mocked out implementation of aClass AND creates a strict
MockControl under to covers for
this interface. |
<T> T |
instantiate(Class<T> classUnderTest)
Deprecated.
This will create an instance of the passed class for testing.
|
<T> T |
instantiateAndReplay(Class<T> classUnderTest)
Deprecated.
This will try to use the mock interfaces that have been previously been added to the MockController to
instantiate a new instance of implementationClass.
|
<T> T |
instantiateAndReplayNice(Class<T> classUnderTest,
Constructor<T> constructor)
Deprecated.
Try an create an instance of the passed class for testing.
|
void |
onTestEnd()
Deprecated.
This method can be called at the end of a TestCase to check that the MockController is in a good state.
|
void |
replay(Object... easyMockedCreatedObjects)
Deprecated.
Called to replay ALL of the MockControl objects inside this MockController as well as replay any EasyMock created
mocks that where created outside the mock controller.
|
void |
reset(Object... easyMockedCreatedObjects)
Deprecated.
Called to reset ALL of the MockControl objects inside this MockController as well as reset any EasyMock created
mocks that where created outside the mock controller.
|
void |
setDefaultReturnValue(boolean b)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
void |
setDefaultReturnValue(Object o)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
void |
setReturnValue(boolean b)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
void |
setReturnValue(long l)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
void |
setReturnValue(Object o)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
void |
setReturnValue(Object o,
int i)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
void |
setThrowable(Throwable throwable)
Deprecated.
since we moved to
EasyMock . Use EasyMock expectations instead |
String |
toString()
Deprecated.
|
void |
verify(Object... easyMockedCreatedObjects)
Deprecated.
Called to verify ALL of the MockControl objects inside this MockController as well as verify any EasyMock created
mocks that where created outside the mock controller.
|
public MockController()
public static MockController createStrictContoller()
MockControl
's by default when getMock(Class)
is calledpublic static MockController createNiceContoller()
MockControl
's by default when getMock(Class)
is calledpublic MockController.ControllerState getState()
public <T> T getMock(Class<T> aClass)
MockControl
under to covers for this
interface. The type of MockControl (strict or nice) depends on the default behaviour for this MockController.
The created MockControl then becomes the current MockControl in play
If you have already asked for an instance of interfaceClass, then the same mock object is returned to the caller
and now extra objects will be created.aClass
- the class or interface class to mock outpublic <T> T createMock(Class<T> aClass)
getMock(Class)
to be more EasyMock likeaClass
- the class or interface class to mock outpublic <T> T getStrictMock(Class<T> aClass)
MockControl
under to covers for
this interface. This MockControl then becomes the current MockControl in play
If you have already asked for an instance of interfaceClass, then the same mock object is returned to the caller
and now extra objects will be created.aClass
- the class or interface class to mock outpublic <T> T createStrictMock(Class<T> aClass)
getStrictMock(Class)
to be more EasyMock likeaClass
- the class or interface class to mock outpublic <T> T getNiceMock(Class<T> aClass)
MockControl
under to covers for
this interface. This MockControl then becomes the current MockControl in play
If you have already asked for an instance of interfaceClass, then the same mock object is returned to the caller
and now extra objects will be created.aClass
- the class or interface class to mock outpublic <T> T createNiceMock(Class<T> aClass)
getNiceMock(Class)
to be more EasyMock likeaClass
- the class or interface class to mock outpublic <T> T addObjectInstance(T objectInstance)
objectInstance
- a non null object instancepublic org.easymock.MockControl getMockControl(Class<?> interfaceClass)
interfaceClass
- the interface class that is being mocked outpublic org.easymock.MockControl getCurrentMockControl()
public List<Class<?>> getMockedTypes()
Class
espublic List<Object> getMockedObjects()
Object
spublic List<org.easymock.MockControl> getMockControls()
MockControl
spublic List<Object> getObjectInstances()
addObjectInstance(Object)
. Ordinarily you should not have to call this method but its here for completeness.Object
spublic <T> T instantiateAndReplay(Class<T> classUnderTest)
classUnderTest
- the class to instantiate. It must be non null and it must not be an Interface.IllegalStateException
- if an instance cannot be instantiated because of a lack of mocked interfaces.public <T> T instantiateAndReplayNice(Class<T> classUnderTest, Constructor<T> constructor)
classUnderTest
- the class to attempt to create.constructor
- the constructor to call.IllegalStateException
- if the controller is unable to create the object for any reason.public <T> T instantiate(Class<T> classUnderTest)
instantiate(Class)
with the added bonus of being less characters to
read and write ;)
This is the method you will most likely call on the MockController to instatiate the class under testclassUnderTest
- the class to attempt to create.IllegalStateException
- if the controller is unable to create the object for any reason.public void onTestEnd()
IllegalStateException
- if you haven't called replay() (eg you are in RECORD state.public void replay(Object... easyMockedCreatedObjects)
easyMockedCreatedObjects
- any EasyMocks created via EasyMock.createMock(Class)
that
you also want to replaypublic final void verify(Object... easyMockedCreatedObjects)
easyMockedCreatedObjects
- any EasyMocks created via EasyMock.createMock(Class)
that you also want
to verifypublic final void reset(Object... easyMockedCreatedObjects)
easyMockedCreatedObjects
- any EasyMocks created via EasyMock.createMock(Class)
that you also want
to verify@Deprecated public void setThrowable(Throwable throwable)
EasyMock
. Use EasyMock expectations instead@Deprecated public void setReturnValue(boolean b)
EasyMock
. Use EasyMock expectations instead@Deprecated public void setReturnValue(long l)
EasyMock
. Use EasyMock expectations instead@Deprecated public void setReturnValue(Object o)
EasyMock
. Use EasyMock expectations instead@Deprecated public void setReturnValue(Object o, int i)
EasyMock
. Use EasyMock expectations instead@Deprecated public void setDefaultReturnValue(boolean b)
EasyMock
. Use EasyMock expectations instead@Deprecated public void setDefaultReturnValue(Object o)
EasyMock
. Use EasyMock expectations insteadCopyright © 2002-2015 Atlassian. All Rights Reserved.