org.mockito.internal.creation
Class CglibMockMaker

java.lang.Object
  extended by org.mockito.internal.creation.CglibMockMaker
All Implemented Interfaces:
MockMaker

public final class CglibMockMaker
extends java.lang.Object
implements MockMaker

A MockMaker that uses cglib to generate mocks on a JVM.


Constructor Summary
CglibMockMaker()
           
 
Method Summary
<T> T
createMock(MockCreationSettings<T> settings, MockHandler handler)
          If you want to provide your own implementation of MockMaker this method should: Create a proxy object that implements settings.typeToMock and potentially also settings.extraInterfaces. You may use the information from settings to create/configure your proxy object. Your proxy object should carry the hander with it.
 MockHandler getHandler(java.lang.Object mock)
          Returns the handler for the mock.
 void resetMock(java.lang.Object mock, MockHandler newHandler, MockCreationSettings settings)
          Replaces the existing handler on mock with newHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CglibMockMaker

public CglibMockMaker()
Method Detail

createMock

public <T> T createMock(MockCreationSettings<T> settings,
                        MockHandler handler)
Description copied from interface: MockMaker
If you want to provide your own implementation of MockMaker this method should:

Specified by:
createMock in interface MockMaker
Type Parameters:
T - Type of the mock to return, actually the settings.getTypeToMock.
Parameters:
settings - - mock creation settings like type to mock, extra interfaces and so on.
handler - See MockHandler. Do not provide your own implementation at this time. Make sure your implementation of MockMaker.getHandler(Object) will return this instance.
Returns:
The mock instance.

resetMock

public void resetMock(java.lang.Object mock,
                      MockHandler newHandler,
                      MockCreationSettings settings)
Description copied from interface: MockMaker
Replaces the existing handler on mock with newHandler.

The invocation handler actually store invocations to achieve stubbing and verification. In order to reset the mock, we pass a new instance of the invocation handler.

Your implementation should make sure the newHandler is correctly associated to passed mock

Specified by:
resetMock in interface MockMaker
Parameters:
mock - The mock instance whose invocation handler is to be replaced.
newHandler - The new invocation handler instance.
settings - The mock settings - should you need to access some of the mock creation details.

getHandler

public MockHandler getHandler(java.lang.Object mock)
Description copied from interface: MockMaker
Returns the handler for the mock. Do not provide your own implementations at this time because the work on the MockHandler api is not completed. Use the instance provided to you by Mockito at MockMaker.createMock(org.mockito.mock.MockCreationSettings, org.mockito.invocation.MockHandler) or MockMaker.resetMock(java.lang.Object, org.mockito.invocation.MockHandler, org.mockito.mock.MockCreationSettings).

Specified by:
getHandler in interface MockMaker
Parameters:
mock - The mock instance.
Returns:
may return null - it means that there is no handler attached to provided object. This means the passed object is not really a Mockito mock.