[英]mockito test error Invalid use of argument matchers
I have been getting writing unit tests for a method that invokes jdbcTemplate.query
and returns some data.我一直在为调用jdbcTemplate.query
并返回一些数据的方法编写单元测试。 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>.仅供参考, newDealDaoImpl.getResultSetExtractor
方法采用 3 个参数<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.)在不受 Mockito 管理的 object 上(模拟、间谍等)
Try to pass an empty String or other random value to your:尝试将空字符串或其他随机值传递给您的:
newDealDaoImpl.getResultSetExtractor(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.