Mockito Error Is Not Applicable for the Arguments (void)

Tags: , ,



Mockito throws error "The method when(T) in the type Stubber is not applicable for the arguments (void)" for a class I’m mocking, can’t figure out why.

the code in question is:

Mockito.when(mockObject.myMethod(Mockito.any(MyExecutionContext.class))).thenReturn(value);

I’m aware similar questions have been asked but if somebody could explain a solution for this or point me in the right direction I would greatly appreciate it

Answer

Solution:

Mockito.doReturn(value)
       .when(mockObject)
       .myMethod(Mockito.any(MyExecutionContext‌​.class))


Source: stackoverflow