I have one of the methods in a util class which returns me an instance of Application.
private static Application application;
public static Application getApplication() {
return application;
}
Now, I need to mock this method, which I did in the following way. I am using Mockito framework.
@Mock
private Application application;
@Test
public void testMethod(){
Utils utils = mock(Utils.class);
when(utils.getApplication()).thenReturn(application);
}
But, this throws away exception
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);
What change should I make in my code so that it works ?