[英]Mockito: how to mock type `.class`
我有想要模拟响应的方法
jdbcTemplate.queryForList(query, Integer.class, nick);
我试着这样嘲笑
doReturn(Collections.singletonList(1))
.when(jdbcTemplate)
.queryForList(anyString(), any(Integer.class), anyString());
但这是行不通的。
我如何模拟任何Integer.class
?
您想模拟通话
template.queryForList(String s, Class<T> elementType, Object... args);
所以你需要做
when(template)
.queryForList(anyString(), any(Class.class), any(Object[].class)
.thenReturn(1);
您应该减少any
使用,最好这样做
when(template)
.queryForList("sql", Integer.class, "yourArg")
或结合
when(template)
.queryForList(eq("sql"), eq(Integer.class), any(Object[].class))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.