com.atlassian.jira.mock.controller
Class MockController

java.lang.Object
  extended by com.atlassian.jira.mock.controller.MockController

Deprecated. since 5.0

@Deprecated
public class MockController
extends Object

This class can be used to better "formalise" the use of EasyMock 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.

  1. The TestCase will create a new MockController in its setup()
  2. Each interface that is to be mocked out will be created via calls to controller.getMock()
  3. Before the object under test is made, the controller.replay() will be called
  4. After the testing is done, the controller.verify() is called

Every time you interaction with a mocked out class, (via getMock() or invoke a mocked out method with in record mode, then its peer MockControl becomes the current one and hence calls to methods like setReturnValue() will be delegated to that MockControl under the covers.

This class should not be used / extended from anymore as the current approach to unit testing in JIRA is to use Mockito.

Since:
4.0

Nested Class Summary
static class MockController.ControllerState
          Deprecated. An enumeration to show the different states of the MockController
 
Constructor Summary
MockController()
          Deprecated. Instantiates a MockController that produces strict MockControl objects by default
 
Method Summary
<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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockController

public MockController()
Deprecated. 
Instantiates a MockController that produces strict MockControl objects by default

Method Detail

createStrictContoller

public static MockController createStrictContoller()
Deprecated. 
Returns:
a MockController that uses strict MockControl's by default when getMock(Class) is called

createNiceContoller

public static MockController createNiceContoller()
Deprecated. 
Returns:
a MockController that uses nice MockControl's by default when getMock(Class) is called

getState

public MockController.ControllerState getState()
Deprecated. 
Returns the current state of the MockController

Returns:
the current state of the MockController

toString

public String toString()
Deprecated. 
Overrides:
toString in class Object

getMock

public <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. 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.

Parameters:
aClass - the class or interface class to mock out
Returns:
a mocked out instance of interfaceClass

createMock

public <T> T createMock(Class<T> aClass)
Deprecated. 
Synonym for getMock(Class) to be more EasyMock like

Parameters:
aClass - the class or interface class to mock out
Returns:
a mocked out instance of interfaceClass

getStrictMock

public <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. 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.

Parameters:
aClass - the class or interface class to mock out
Returns:
a mocked out instance of interfaceClass

createStrictMock

public <T> T createStrictMock(Class<T> aClass)
Deprecated. 
Synonym for getStrictMock(Class) to be more EasyMock like

Parameters:
aClass - the class or interface class to mock out
Returns:
a mocked out instance of interfaceClass

getNiceMock

public <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. 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.

Parameters:
aClass - the class or interface class to mock out
Returns:
a mocked out instance of interfaceClass

createNiceMock

public <T> T createNiceMock(Class<T> aClass)
Deprecated. 
Synonym for getNiceMock(Class) to be more EasyMock like

Parameters:
aClass - the class or interface class to mock out
Returns:
a mocked out instance of interfaceClass

addObjectInstance

public <T> T addObjectInstance(T objectInstance)
Deprecated. 
This method allow you to add an actual object instance to be added into the mix. For example if a class you are mocking out needs an actual class type and not a interface type, then you can use this method to supply the object

Parameters:
objectInstance - a non null object instance
Returns:
objectInstance

getMockControl

public org.easymock.MockControl getMockControl(Class<?> interfaceClass)
Deprecated. 
This method allows you access to the underlying MockControl objects. Ordinarily you should need to use this method unless doing something special.

Parameters:
interfaceClass - the interface class that is being mocked out
Returns:
MockControl or null if not call to @link #getMock} for this interfaceClass has not been made

getCurrentMockControl

public org.easymock.MockControl getCurrentMockControl()
Deprecated. 
This method allows you access to the current MockControl. Ordinarily you would not need access to this method as the MockControl methods are delegated to the currentMockControl when called.

Returns:
the current MockControl or null if there isn't one

getMockedTypes

public List<Class<?>> getMockedTypes()
Deprecated. 
This method allows you access to the interfaces and classes that have been mocked out by this MockController. Ordinarily you should not have to call this method but its here for completeness.

Returns:
a non null List or interface Classes

getMockedObjects

public List<Object> getMockedObjects()
Deprecated. 
This method allows you access to the mocked object instances that have been mocked out by this MockController. Ordinarily you should not have to call this method but its here for completeness.

Returns:
a non null List of mocked Objects

getMockControls

public List<org.easymock.MockControl> getMockControls()
Deprecated. 
This method allows you access to the MockControl instances that have been created by this MockController. Ordinarily you should not have to call this method but its here for completeness.

Returns:
a non null List of MockControls

getObjectInstances

public 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) . Ordinarily you should not have to call this method but its here for completeness.

Returns:
a non null List of Objects

instantiateAndReplay

public <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. It uses a greediest constructor based algorithm to do this.

It will then replay the MockControl objects in play, ready for the instantiated object to be tested.

Parameters:
classUnderTest - the class to instantiate. It must be non null and it must not be an Interface.
Returns:
an instance of implementationClass using the mocked out interfaces already in the MockController
Throws:
IllegalStateException - if an instance cannot be instantiated because of a lack of mocked interfaces.

instantiateAndReplayNice

public <T> T instantiateAndReplayNice(Class<T> classUnderTest,
                                      Constructor<T> constructor)
Deprecated. 
Try an create an instance of the passed class for testing. It tries to create the object by calling the passed constructor. The arguments to the constructor will be made from mocks previously registered with the controller or new mocks if they have not been registered. All the mocks will be placed in the replay state.

Parameters:
classUnderTest - the class to attempt to create.
constructor - the constructor to call.
Returns:
the newly created object.
Throws:
IllegalStateException - if the controller is unable to create the object for any reason.

instantiate

public <T> T instantiate(Class<T> classUnderTest)
Deprecated. 
This will create an instance of the passed class for testing. It tries to create the object by calling each of the objects constructors in turn. The arguments to the constructor will be made from mocks previously registered with the controller or new mocks if they have not been registered. All the mocks will be placed in the replay state.

This is a synonym for 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 test

Parameters:
classUnderTest - the class to attempt to create.
Returns:
the newly created object.
Throws:
IllegalStateException - if the controller is unable to create the object for any reason.

onTestEnd

public void onTestEnd()
Deprecated. 
This method can be called at the end of a TestCase to check that the MockController is in a good state. It will check that you have called replay(). It will also call verify() if its hasn't already been called.

Throws:
IllegalStateException - if you haven't called replay() (eg you are in RECORD state.

replay

public 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.

Parameters:
easyMockedCreatedObjects - any EasyMocks created via EasyMock.createMock(Class) that you also want to replay

verify

public final 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.

Parameters:
easyMockedCreatedObjects - any EasyMocks created via EasyMock.createMock(Class) that you also want to verify

reset

public final 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.

Parameters:
easyMockedCreatedObjects - any EasyMocks created via EasyMock.createMock(Class) that you also want to verify

setThrowable

@Deprecated
public void setThrowable(Throwable throwable)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead


setReturnValue

@Deprecated
public void setReturnValue(boolean b)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead


setReturnValue

@Deprecated
public void setReturnValue(long l)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead


setReturnValue

@Deprecated
public void setReturnValue(Object o)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead


setReturnValue

@Deprecated
public void setReturnValue(Object o,
                                      int i)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead


setDefaultReturnValue

@Deprecated
public void setDefaultReturnValue(boolean b)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead


setDefaultReturnValue

@Deprecated
public void setDefaultReturnValue(Object o)
Deprecated. since we moved to EasyMock. Use EasyMock expectations instead



Copyright © 2002-2013 Atlassian. All Rights Reserved.