I have a method that looks that looks something like:
public Response methodA(ParamObject po, Supplier<Response> supplier)
the Supplier
contains a call to a method on another class.
I am attempting to wrap some code in the Supplier
in a more complex set of logic, something akin to a Strategy pattern, it does make the code easier to follow.
It looks something like:
public Controller {
private Helper helper;
private Delegate delegate;
public void doSomething() {
ParamObject po = ....
delegate.methodA(po, () -> {
helper.doSomethingElse(v1, v2);
}
}
}
In my test for Controller
I have mocked both Helper
and Delegate
, I wish to validate that helper.doSomething
is called with the correct parameter values, and then return a mocked response.
Given that delegate
is a mock, the Supplier
is never actually executed, so no verification of the calls to helper
can be mocked or verified.
Is it possible to do this? It feels like I should be able to tell mockito to capture the lambda, and or the variables the lambda itself captured and assert they are the right values return my mock response if they are the values I was looking for.
Assuming that your class Helper looks like this:
Then it could be done like this: