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>.
The problem is that you are using argument matchers:
Mockito.anyString()
on an object that is not managed by Mockito (mock, spy etc.)
Try to pass an empty String or other random value to your:
newDealDaoImpl.getResultSetExtractor(...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.