Using Mockito, how do I intercept a callback object on a void method?

For functions returning void, use doAnswer()

doAnswer(...).when(mockedObject).handle(any(Callback[].class));

And an Answer that performs the interception must go in as the parameter to doAnswer, e.g. as an anonymous class:

new Answer() {
  public Object answer(InvocationOnMock invocation) {
      Object[] args = invocation.getArguments();
      Mock mock = invocation.getMock();
      return null;
  }}

In this case args will be the array Callback[]!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)