Skip to content

Addind an InvocationListener to a mock, after it has been created. More specific, make a mock verbose. #507

Description

@GoogleCodeExporter
Hi,

Can we have such the functionality below "officially" part of Mockito? Maybe in 
MockitoDebuggerImpl? It seems to be only way to attach an InvocationListener to 
a mock *after* it has been created.

I find such a method useful when dealing with legacy code tested with mockito. 
The place where the mock is created is not (easily) reachable to me.

    public static void makeMockVerbose(Object mock) {

        Factory factory = (Factory) mock;
        MethodInterceptorFilter filter = (MethodInterceptorFilter) factory.getCallback(0);
        InternalMockHandler<?> mockHandler = (InternalMockHandler<?>) filter.getHandler();
        MockCreationSettings settings = mockHandler.getMockSettings();
        settings.getInvocationListeners().add(new VerboseMockInvocationLogger());
    }

Original issue reported on code.google.com by ccrav...@gmail.com on 27 Mar 2015 at 9:53

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions