I'm trying to mock the return value from a method but I'm getting NotAMockException
.
@InjectMocks private MyService myService; @Mock private OtherServiceUsedInMyServiceAsAutowired otherServiceUsedInMyServiceAsAutowired;
Inside MyService
I have a method called myMethod()
and I want to return dummy object when this method is called.
doReturn(someDummyObject).when(myService).myMethod(any(), any(), any());
And at that point I'm getting the error. What am I doing wrong? Full error:
org.mockito.exceptions.misusing.NotAMockException: Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMethod();