I have been getting writing unit tests for a method that invokes jdbcTemplate.query and returns some data. It doesn't seems to be working and throwing exception.
Here's the code.
@Test public void NewDealDaoGetClientOwnershipValuesTest() { List<OptionView> optionViews = new ArrayList<OptionView>(); optionViews.add(new OptionView("one", "two")); when(jdbcTemplate.query("<some sql query>", newDealDaoImpl.getResultSetExtractor(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))).thenReturn(optionViews); assertEquals(newDealDaoImpl.getClientOwnershipValues(), optionViews); } Error message
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 2 matchers expected, 3 recorded. This exception may occur if matchers are combined with raw values: //incorrect: someMethod(anyObject(), "raw String"); When using matchers, all arguments have to be provided by matchers. For example: //correct: someMethod(anyObject(), eq("String by matcher")); Just for your information that method newDealDaoImpl.getResultSetExtractor takes 3 arguments<String, String, String>.