Reputation: 2356
I've read this post, but my problem is that my myFunction
returns void
instead of an Object. So I get errors at
when(mock.myFunction(anyString()))
saying
when (java.lang.Void) in Mockito cannot be applied
to (void)
How can I deal with this issue?
Upvotes: 8
Views: 6119
Reputation: 63991
I have the same answer in a comment on the question, but just to make it easier for future readers to see, here it is.
doNothing().when(mock).myFunction(anyString());
in order to be able to handle the void
return type.
Upvotes: 12
Reputation: 79808
The answer to this can be found in my answer to that other post that you linked to.
doAnswer(returnsFirstArg()).when(mock).myFunction(anyString());
where the returnsFirstArg()
method is static in the AdditionalAnswers
class.
Upvotes: 3