@Incubating public class InlineByteBuddyMockMaker extends Object implements InlineMockMaker, Instantiator
MockMaker.ConstructionMockControl<T>, MockMaker.StaticMockControl<T>, MockMaker.TypeMockability| Constructor and Description |
|---|
InlineByteBuddyMockMaker() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearAllCaches()
Clears all cashes for mocked types and removes all byte code alterations, if possible.
|
void |
clearAllMocks()
Cleans up internal state for all existing mocks.
|
void |
clearMock(Object mock)
Clean up internal state for specified
mock. |
<T> MockMaker.ConstructionMockControl<T> |
createConstructionMock(Class<T> type,
Function<MockedConstruction.Context,MockCreationSettings<T>> settingsFactory,
Function<MockedConstruction.Context,MockHandler<T>> handlerFactory,
MockedConstruction.MockInitializer<T> mockInitializer)
If you want to provide your own implementation of
MockMaker this method should:
Intercept all constructions of the specified type in the current thread
Only intercept the construction after being enabled.
Stops the interception when disabled.
|
<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 handler with it. |
<T> Class<? extends T> |
createMockType(MockCreationSettings<T> settings) |
<T> Optional<T> |
createSpy(MockCreationSettings<T> settings,
MockHandler handler,
T instance)
By implementing this method, a mock maker can optionally support the creation of spies where all fields
are set within a constructor.
|
<T> MockMaker.StaticMockControl<T> |
createStaticMock(Class<T> type,
MockCreationSettings<T> settings,
MockHandler handler)
If you want to provide your own implementation of
MockMaker this method should:
Alter the supplied class to only change its behavior in the current thread.
Only alters the static method's behavior after being enabled.
Stops the altered behavior when disabled.
|
MockHandler |
getHandler(Object mock)
Returns the handler for the
mock. |
MockMaker.TypeMockability |
isTypeMockable(Class<?> type)
Indicates if the given type can be mocked by this mockmaker.
|
<T> T |
newInstance(Class<T> cls)
Creates instance of given class
|
void |
resetMock(Object mock,
MockHandler newHandler,
MockCreationSettings settings)
Replaces the existing handler on
mock with newHandler. |
public <T> T newInstance(Class<T> cls)
InstantiatornewInstance in interface Instantiatorpublic <T> Class<? extends T> createMockType(MockCreationSettings<T> settings)
public void clearMock(Object mock)
InlineMockMakermock. You may assume there won't be any interaction to the specific
mock after this is called.clearMock in interface InlineMockMakermock - the mock instance whose internal state is to be cleaned.public void clearAllMocks()
InlineMockMakerclearAllMocks in interface InlineMockMakerpublic <T> T createMock(MockCreationSettings<T> settings, MockHandler handler)
MockMakerMockMaker this method should:
settings.typeToMock and potentially also settings.extraInterfaces.settings to create/configure your proxy object.handler with it. For example, if you generate byte code
to create the proxy you could generate an extra field to keep the handler with the generated object.
Your implementation of MockMaker is required to provide this instance of handler when
MockMaker.getHandler(Object) is called.
createMock in interface MockMakerT - Type of the mock to return, actually the settings.getTypeToMock.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.public <T> Optional<T> createSpy(MockCreationSettings<T> settings, MockHandler handler, T instance)
MockMakercreateSpy in interface MockMakerT - Type of the mock to return, actually the settings.getTypeToMock.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.instance - The object to spy upon.public MockHandler getHandler(Object mock)
MockMakermock. 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<T>, org.mockito.invocation.MockHandler) or MockMaker.resetMock(java.lang.Object, org.mockito.invocation.MockHandler, org.mockito.mock.MockCreationSettings).getHandler in interface MockMakermock - The mock instance.public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings)
MockMakermock 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
public MockMaker.TypeMockability isTypeMockable(Class<?> type)
MockMakerMockmaker 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.
isTypeMockable in interface MockMakertype - The type inspected for mockability.public <T> MockMaker.StaticMockControl<T> createStaticMock(Class<T> type, MockCreationSettings<T> settings, MockHandler handler)
MockMakerMockMaker this method should:
createStaticMock in interface MockMakerT - Type of the mock to return, actually the settings.getTypeToMock.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.public <T> MockMaker.ConstructionMockControl<T> createConstructionMock(Class<T> type, Function<MockedConstruction.Context,MockCreationSettings<T>> settingsFactory, Function<MockedConstruction.Context,MockHandler<T>> handlerFactory, MockedConstruction.MockInitializer<T> mockInitializer)
MockMakerMockMaker this method should:
createConstructionMock in interface MockMakerT - Type of the mock to return, actually the settings.getTypeToMock.settingsFactory - Factory for mock creation settings like type to mock, extra interfaces and so on.handlerFactory - Factory for settings. See MockHandler.
Do not provide your own implementation at this time. Make sure your implementation of
MockMaker.getHandler(Object) will return this instance.public void clearAllCaches()
MockMakerclearAllCaches in interface MockMakerCopyright © 2025. All rights reserved.