@Test
public void testGetScheduleTotalCount() {
when(jdbcTemplate.queryForObject(Mockito.anyString(),Mockito.anyMap(),Mockito.eq(Integer.class))).thenReturn(2);
}
在运行上面的测试时,我得到以下错误:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 参数匹配器的使用无效!预计有3名匹配者,2名记录:
关于jdbcTemplate.queryForObject(query, namedParameters, Integer.class);
,您的设置应该是:
Mockito.doReturn(myInteger).when(jdbcTemplateMock).queryForObject(Mockito.anyString()
, Mockito.any(Object[].class), Mockito.eq(Integer.class));
关于queryForObject(sql, paramMap, new SingleColumnRowMapper<>(requiredType));
,您的设置可能是:
Mockito.doReturn(myInteger)
.when(n)
.queryForObject(Mockito.anyString()
, ArgumentMatchers.<Map<Integer,?>>any()
, ArgumentMatchers.<org.springframework.jdbc.core.RowMapper<Integer>>any());