我有一个奇怪的编译问题。我无法解决这个问题。同一段代码在另一个项目中运行良好
org.mockito.Mockito.when(jdbcTemplate.query(org.mockito.Matchers.anyString(),
org.mockito.Matchers.any(BeanPropertyRowMapper.class))).thenReturn(SOMELIST);
我收到错误为
The method query(String, ResultSetExtractor<T>) in the type JdbcTemplate is not applicable for the arguments (String, BeanPropertyRowMapper)
但是当我这样做时,我没有收到任何错误。但我并不期待这一点。
BeanPropertyRowMapper<MyClass> mapper =
new BeanPropertyRowMapper<MyClass>(MyClass.class);
org.mockito.Mockito.when(jdbcTemplate.query(org.mockito.Matchers.anyString(),
mapper)).thenReturn(SOMELIST);
我不确定这是否是 Eclipse 的问题。感谢您对此的帮助。
最佳答案
自 BeanPropertyRowMapper<T>
是一个通用接口(interface),您应该调用 any()
像这样:
Mockito.when(jdbcTemplate.query(Matchers.anyString(),
Matchers.<BeanPropertyRowMapper<MyClass>>any())).thenReturn(SOMELIST);
关于java - JdbcTemplate 类型中的方法 query(String, ResultSetExtractor<T>) 不适用于参数 (String, BeanPropertyRowMapper),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26020607/