使用 Mockito 的
Hamcrest Matchers any(( 在 Java 8 中不起作用。
when(simpleJdbcCall.execute(Matchers.any(SqlParameterSource.class))).thenReturn(outputParameters);
any(( 仅适用于已弃用的 org.mockito.Matchers。
在Java 8中还有另一种方法可以使用此方法吗?
使用 Mockito 的 any(Class)
,而不是 Hamcrest 的
when(simpleJdbcCall.execute(Mockito.any(SqlParameterSource.class))).thenReturn(outputParameters);
你试图让Mockito使用Hamcrest的方法。这是行不通的。因此,将您的呼叫从Matchers.any(SqlParameterSource.class)
更改为Mockito.any(SqlParameterSource.class)
。