1

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 ?

thedarkpassenger
  • 7,158
  • 3
  • 37
  • 61
  • 2
    You cannot mock static methods with Mockito, use PowerMockito on top of it. See [this question](http://stackoverflow.com/questions/21105403/mocking-static-methods-with-mockito) – troig May 04 '16 at 09:11

0 Answers0