SomeClass instance = someService.getSomething.apply("by-something");
above statement is being used in controller to fetch data. I want to test controller. So i am mocking above line in test as below.
@Mock
private SomeService someService;
@Mock
private Function<String, SomeTrigger> someTriggerFunction;
when(someService.getSomething.apply("by-something")).thenReturn(someTrigger);
Now it giving me below error
org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
You should set the getSomething
field in someService
like this :
@Mock
private SomeService someService;
@Mock
private Function<String, SomeTrigger> someTriggerFunction;
...
someService.getSomething = someTriggerFunction;
when(someTriggerFunction.apply("by-something")).thenReturn(someTrigger);