Mockito: how to get arguments passed to a method when the return type of a method is invalid

I read this post , but my problem is that my myFunction returns void instead of Object. So I get errors in

when(mock.myFunction(anyString()))

speaking

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

How can I solve this problem?

+7
java mockito
source share
2 answers

I have the same answer in a commentary on this, but just to make it clear to future readers, here it is.

doNothing().when(mock).myFunction(anyString());

to be able to handle the void return type.

+12
source share

The answer to this question can be found in my answer to another message that you contacted.

 doAnswer(returnsFirstArg()).when(mock).myFunction(anyString()); 

where the returnsFirstArg() method is static in the AdditionalAnswers class.

+3
source share

All Articles