1

What is the best way to test the following static method with a callback

Service.doAction(request, Callback<Response> callback);

I am aware of similar questions around mocking and testing non-static objects and methods but this is specific to static methods. Is there any way to use Powermock with Answers or ArgumentCaptor to achieve this?

Community
  • 1
  • 1
Soham
  • 4,940
  • 3
  • 31
  • 48

2 Answers2

1

You claim you want to test the static method. So you most likely will not mock it as well, right?

What you do want to mock will be the parameters passed into the method - request and callback. But that's just the same as mocking any other parameters:

  • Create a mock
  • Define the behaviour
  • pass it in
  • verify the results / methods calles on the callback.
Jan
  • 13,738
  • 3
  • 30
  • 55
0

Create a mocked request, and the callback with the code you need to test that it's being called and being called with the right results, then just call it, exaclty as you posted.

Gavriel
  • 18,880
  • 12
  • 68
  • 105