Interface InlineMockMaker
-
- All Superinterfaces:
MockMaker
public interface InlineMockMaker extends MockMaker
Extension toMockMaker
for mock makers that changes inline method implementations and need keep track of created mock objects.Mockito's default inline mock maker keeps track of created mock objects via weak reference map. This poses a risk of memory leaks in certain scenarios (issue #1619). There is no clean way to tackle those problems at the moment. Hence,
InlineMockMaker
interface exposes methods to explicitly clear mock references. Those methods are called byMockitoFramework.clearInlineMocks()
. When the user encounters a leak, he can mitigate the problem withMockitoFramework.clearInlineMocks()
.InlineMockMaker
is for expert users and framework integrators, when custom inline mock maker is in use. If you have a customMockMaker
that keeps track of mock objects, please have your mock maker implementInlineMockMaker
interface. This way, it can participate inMockitoFramework.clearInlineMocks()
API.- Since:
- 2.25.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.mockito.plugins.MockMaker
MockMaker.ConstructionMockControl<T>, MockMaker.StaticMockControl<T>, MockMaker.TypeMockability
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clearAllMocks()
Cleans up internal state for all existing mocks.void
clearMock(Object mock)
Clean up internal state for specifiedmock
.-
Methods inherited from interface org.mockito.plugins.MockMaker
clearAllCaches, createConstructionMock, createMock, createSpy, createStaticMock, getHandler, isTypeMockable, resetMock
-
-
-
-
Method Detail
-
clearMock
void clearMock(Object mock)
Clean up internal state for specifiedmock
. You may assume there won't be any interaction to the specific mock after this is called.- Parameters:
mock
- the mock instance whose internal state is to be cleaned.- Since:
- 2.25.0
-
clearAllMocks
void clearAllMocks()
Cleans up internal state for all existing mocks. You may assume there won't be any interaction to mocks created previously after this is called.- Since:
- 2.25.0
-
-