mercredi 31 décembre 2014

Mocking a function call using Mockito throw up InvalidUseOfMatchersException

I am trying to use Mockito to mock a function call.


I have a method runQueryForDataWindow in a class called QueryBuilder. The method runQueryForDataWindow takes two arguments - 1) a string 2) an instance of class FetchWindow



runQueryForDataWindow(String str, FetchWindow fetchWindow)


Here is how my test case for mocking looks like



final QueryBuilder queryBuilder = mock(QueryBuilder.class);

Mockito.when(queryBuilder.runQueryForDataWindow(anyString(),
any(FetchWindow.class))).thenReturn(queryResult);


I want to return queryResult irrespective of the function arguments.


When I ran this, the test fails with org.mockito.exceptions.misusing.InvalidUseOfMatchersException


I guess there is something wrong with the way I am trying to pass in the instance of FetchWindow. Appreciate any leads here.


Aucun commentaire:

Enregistrer un commentaire