I am writing unit tests for my service PlanGenerator. I have mocked necessary services and I have InjectMocked plangenerator service as follows:
@Mock
private LoggerFactory lf;
@Mock
private Logger logger;
@Mock
private RequestGenerator requestGenerator;
@InjectMocks
private PlanGenerator planGenerator;
In methods, I am able to call when method on Mocked services like requestGenerator as this:
Mockito.when(requestGenerator.getLatestRequest()).thenReturn(latestRequestDummy);
However, I am not able to call the same method on planGenerator service like this:
Mockito.when(planGenerator.someOtherMethod()).thenReturn(someValue);
It gives me MissingMethodInvocationException
error while saying when() requires an argument which has to be 'a method call on a mock'
How can I mock planGenerator service, also it works as same as injectmocks?