I want to capture calls to a mock object
public interface Service {
public String stringify(Object o);
}
service = mockery.mock(Service.class);
mockery.a
Using the trick from this SO post you can find the target. The important method below is findTarget. As it turns out, lambdas do indeed capture their targets, and you can access them from the SerializedLambda.
However, this is a pretty nasty reflection hack and it's likely to break in future versions. I do not condone its usage.
import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.function.Function;
public class FindMethodReferenceTarget {
public static void main(String[] args) {
String s = "123";
Optional