For a mock of NamedParameterJdbcTemplate
@Mock
NamedParameterJdbcTemplate template;
I tried to stub it as follows:
doReturn(1L).when(template).queryForObject(Mockito.anyString(), Mockito.any(MapSqlParameterSource.class), Long.class);
and got this error:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
3 matchers expected, 2 recorded:
-> at com.bns.tds.api.mortgage.points.fulfillment.repository.dao.PointsIssuanceReconDaoTest.insertPointsIssuanceReconEntryNoProfile(PointsIssuanceReconDaoTest.java:59)
-> at com.bns.tds.api.mortgage.points.fulfillment.repository.dao.PointsIssuanceReconDaoTest.insertPointsIssuanceReconEntryNoProfile(PointsIssuanceReconDaoTest.java:59)
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(any(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(any(), eq("String by matcher"));
What did I get wrong?