如何将多个Mockito匹配器与逻辑“和"/“或"组合? [英] How to combine multiple Mockito matchers with a logical "and"/"or"?
本文介绍了如何将多个Mockito匹配器与逻辑“和"/“或"组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Mockito验证字符串参数是否满足两个条件:
I'd like to verify using Mockito that a string argument satisfies two conditions:
verify(mockClass).doSomething(Matchers.startsWith("prefix"));
verify(mockClass).doSomething(Matchers.endsWith("suffix"));
如何将两者结合成一条语句?
How to combine those two into one statement?
推荐答案
可以使用org.mockito.AdditionalMatchers
:
import static org.mockito.AdditionalMatchers.and;
verify(mockClass).doSomething(
and(Matchers.startsWith("prefix"),
Matchers.endsWith("suffix"));
还有org.mockito.AdditionalMatchers.or
和org.mockito.AdditionalMatchers.not
.
这篇关于如何将多个Mockito匹配器与逻辑“和"/“或"组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文