-1

I have a method that will call a service with a Callable implementation. However, I have no idea how to mock this implementation in my test code because the Callable is implemented with lambda expression on the fly. Is there any way i can achieve this?

protected Foo (){
    final Callable<MyResponse> myTask = () -> {
        MyRequest myRequest = new MyRequest();
        Mycliet.call(myRequest);
    }
    Future<MyResponse> myResponse = executor.submit(myTask);
  }
}

1 Answers1

0

No you can't (without doing terrible reflection hacks). A mock must be injected in some way.

So you will need to refactor.

Henri
  • 5,551
  • 1
  • 22
  • 29