I want to capture calls to a mock object
public interface Service {
public String stringify(Object o);
}
service = mockery.mock(Service.class);
mockery.a
There's no direct way to find the target, because method references just get translated to lambdas (which are, by definition, anonymous) under the covers. So you'll need to use a workaround.
Presumably you're familiar with Java 7's proxies, since you've managed to implement your mock
factory method.
The workaround then is that when someone invokes your allowing
method, you set some sort of global flag to alert all your mocks that you want to record the next call, and then you invoke the lambda you were given. By seeing which mock recorded the call, you've now found the target of the method reference, and you can unset the global flag and proceed on with the rest of your mocking framework.
It's ugly, I know.