【问题标题】:org.hamcrest.Matchers.any not working in java 8 [closed]org.hamcrest.Matchers.any 在 java 8 中不起作用 [关闭]
【发布时间】:2018-03-05 17:21:20
【问题描述】:

Hamcrest Matchers any() 在 Java 8 中不起作用。

when(simpleJdbcCall.execute(Matchers.any(SqlParameterSource.class))).thenReturn(outputParameters);

any() 仅适用于已弃用的 org.mockito.Matchers。

在 Java 8 中还有其他方法可以使用此方法吗?

【问题讨论】:

  • 我称这是一个错字,因为你导入了错误的类,而且这里真的没有太多的见解可以收集。

标签: java junit mockito hamcrest


【解决方案1】:

使用 Mockito 的 any(Class),而不是 Hamcrest 的

when(simpleJdbcCall.execute(Mockito.any(SqlParameterSource.class))).thenReturn(outputParameters);

您正试图让 Mockito 使用 Hamcrest 的方法。它行不通。所以把你的电话从Matchers.any(SqlParameterSource.class)改为Mockito.any(SqlParameterSource.class)

【讨论】:

    猜你喜欢
    • 2018-03-03
    • 2013-06-11
    • 1970-01-01
    • 2023-03-08
    • 2013-05-13
    • 2017-11-04
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    相关资源
    最近更新 更多