Mockito:匹配除一个以外的任何字符串 [英] Mockito: Match any String except one

查看:110
本文介绍了Mockito:匹配除一个以外的任何字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用Mockito编写一个匹配除特定字符串以外的任何字符串的匹配器?

How can I write a matcher using Mockito that matches any string except a specific one?

我曾尝试使用一些hamcrest匹配器来求反并组合其他匹配器,但是hamcrest匹配器都返回Matcher<T>类型的值,这与Mockito匹配器不太兼容.

I have tried using some hamcrest matchers to negate and combine other matchers, but the hamcrest matchers all return values of type Matcher<T> which dont work very well with Mockito matchers.

推荐答案

我使用的解决方案:

argThat(not("ExceptionString"))

argThat是Mockito匹配器的地方,
not是Hamcrest Matcher

Where argThat is a Mockito matcher,
and not is a Hamcrest Matcher

这篇关于Mockito:匹配除一个以外的任何字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆