Mockito issue – when(java.lang.Void) in Stubber cannot be applied to void

This stub is wrong :

doNothing().when(mockObject.methodToStub(captor.capture())); // wrong

methodToStub(...) must be outside the when if using this API style (it should only contain the mock) :

doNothing().when(mockObject).methodToStub(captor.capture()); // correct

Tho remarks however :

  1. doNothing is the default for void methods for a mock.
  2. You can use the BDDMockito aliases that enables your code to be real à la Behavior Driven Development

Leave a Comment

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