Mockito Core Matcher-GreaterThan

问题描述 投票:0回答:1

我正在尝试在项目中升级模拟版本。

当前版本:mockito-all [1.9.5]

升级到:mockito-core [2.8.8]

我的一些旧测试因此问题而失败

测试:

.andExpect(jsonPath("$.paymentTransaction.totalAmount").value(new GreaterThan<Double>(0.0D)))

失败消息:

java.lang.AssertionError: For JSON path $.paymentTransaction.totalAmount type of value 
Expected :class org.mockito.internal.matchers.GreaterThan
Actual   :class java.lang.Double

任何线索,如果要通过模仿版本升级以其他方式处理?

junit mockito matcher spring-test-mvc
1个回答
0
投票

您最终使用了错误的重载:

public ResultMatcher value(Object expectedValue)https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/result/JsonPathResultMatchers.html#value-java.lang.Object-

代替

public <T> ResultMatcher value(Matcher<T> matcher)https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/result/JsonPathResultMatchers.html#value-org.hamcrest.Matcher-

原因是您使用了Mockito的匹配器,而不是Hamcrest的匹配器。您需要使用:org.hamcrest.Matchers.greaterThan(T value)

© www.soinside.com 2019 - 2024. All rights reserved.