小编Anw*_*war的帖子

参数匹配器的使用无效

下面的简单测试用例失败,但有例外.

org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers! 3 matchers expected, 2 recorded:
Run Code Online (Sandbox Code Playgroud)

我不确定是什么问题

@Test
public void testGetStringTest(){

    final long testId = 1;
    String dlrBAC = null;
    NamedParameterJdbcTemplate jdbcTemplate = mock(NamedParameterJdbcTemplate.class);
    when(this.dao.getNamedParameterJdbcTemplate()).thenReturn(jdbcTemplate);
    when(jdbcTemplate.queryForObject(anyString(), any(SqlParameterSource.class), String.class
                        )).thenReturn("Test");
    dlrBAC =  dao.getStringTest(testId);
    assertNotNull(dlrBAC);

}
Run Code Online (Sandbox Code Playgroud)

java mockito

15
推荐指数
1
解决办法
4万
查看次数

标签 统计

java ×1

mockito ×1