【发布时间】:2023-03-13 21:55:02
【问题描述】:
如何使用 Mockito 编写匹配器,以匹配除特定字符串之外的任何字符串?
我曾尝试使用一些 hamcrest 匹配器来否定和组合其他匹配器,但 hamcrest 匹配器都返回类型为 Matcher<T> 的值,这与 Mockito 匹配器效果不佳。
【问题讨论】:
-
使用
argThat(yourHamcrestMatcher)。 docs.mockito.googlecode.com/hg/org/mockito/Matchers.html -
@JBNizet 我认为这是可行的,因为
argThat(matcher())本质上将返回类型从Matcher<T>转换为<T>? -
@JNNizet:文档的 url 现在是 site.mockito.org/mockito/docs/current/org/mockito/Matchers.html
标签: java string junit mockito matcher