Class ProxyMockMaker
java.lang.Object
org.mockito.internal.creation.proxy.ProxyMockMaker
- All Implemented Interfaces:
MockMaker
A mock maker that is using the
Proxy utility and is therefore only capable of mocking interfaces but
does not rely on manual byte code generation but only uses official and public Java API.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.mockito.plugins.MockMaker
MockMaker.ConstructionMockControl<T>, MockMaker.StaticMockControl<T>, MockMaker.TypeMockability -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TcreateMock(MockCreationSettings<T> settings, MockHandler handler) If you want to provide your own implementation ofMockMakerthis method should: Create a proxy object that implementssettings.typeToMockand potentially alsosettings.extraInterfaces. You may use the information fromsettingsto create/configure your proxy object. Your proxy object should carry thehandlerwith it.getHandler(Object mock) Returns the handler for themock.isTypeMockable(Class<?> type) Indicates if the given type can be mocked by this mockmaker.voidresetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) Replaces the existing handler onmockwithnewHandler.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.mockito.plugins.MockMaker
clearAllCaches, createConstructionMock, createSpy, createStaticMock
-
Constructor Details
-
ProxyMockMaker
public ProxyMockMaker()
-
-
Method Details
-
createMock
Description copied from interface:MockMakerIf you want to provide your own implementation ofMockMakerthis method should:- Create a proxy object that implements
settings.typeToMockand potentially alsosettings.extraInterfaces. - You may use the information from
settingsto create/configure your proxy object. - Your proxy object should carry the
handlerwith it. For example, if you generate byte code to create the proxy you could generate an extra field to keep thehandlerwith the generated object. Your implementation ofMockMakeris required to provide this instance ofhandlerwhenMockMaker.getHandler(Object)is called.
- Specified by:
createMockin interfaceMockMaker- Type Parameters:
T- Type of the mock to return, actually thesettings.getTypeToMock.- Parameters:
settings- Mock creation settings like type to mock, extra interfaces and so on.handler- SeeMockHandler. Do not provide your own implementation at this time. Make sure your implementation ofMockMaker.getHandler(Object)will return this instance.- Returns:
- The mock instance.
- Create a proxy object that implements
-
getHandler
Description copied from interface:MockMakerReturns the handler for themock. Do not provide your own implementations at this time because the work on theMockHandlerapi is not completed. Use the instance provided to you by Mockito atMockMaker.createMock(org.mockito.mock.MockCreationSettings<T>, org.mockito.invocation.MockHandler)orMockMaker.resetMock(java.lang.Object, org.mockito.invocation.MockHandler, org.mockito.mock.MockCreationSettings).- Specified by:
getHandlerin interfaceMockMaker- Parameters:
mock- The mock instance.- Returns:
- The mock handler, but 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.
-
resetMock
Description copied from interface:MockMakerReplaces the existing handler onmockwithnewHandler.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
newHandleris correctly associated to passedmock -
isTypeMockable
Description copied from interface:MockMakerIndicates if the given type can be mocked by this mockmaker.Mockmaker may have different capabilities in term of mocking, typically Mockito 1.x's internal mockmaker cannot mock final types. Other implementations, may have different limitations.
- Specified by:
isTypeMockablein interfaceMockMaker- Parameters:
type- The type inspected for mockability.- Returns:
- object that carries the information about mockability of given type.
-