java - AssertJ:一个集合包含一个值以字符串结尾的元素
问题描述
我想检查被测集合是否包含任何以特定字符串结尾的元素。
使用 Hamcrest 可能是这样的:
assertThat("Contains an element ending with 'xyz'",
myCollection, hasItems(endsWith("xyz")));
如何对 AssertJ 做同样的事情?
解决方案
您可以使用anyMatch(Predicate)
or anySatisfy(assertions on elements)
,例如:
assertThat(myCollection).as("Contains an element ending with 'xyz'")
.anyMatch(element -> element.endsWith("xyz"));
推荐阅读
- java - Spring Rest 模板使用 % 将值注入参数
- java - Selenium Java 中的 WebElement 类是否有任何获取正文标记方法?
- java - 用java删除数据CSV
- python - 部署到服务器后 Django 语言环境不工作 [已修复]
- wcf - 将 Membership 的使用转换为可在 .NET Core 中用于 WCF 服务调用的东西
- amazon-cognito - Cognito 用户池中的 SMS MFA 状态是通过调用 setPreferredMFA 设置的还是其他的?
- wordpress - Wordpress - 从帖子中隐藏类别
- sql - Oracle SQL:为列中的每个值创建一个新行,其中更多值用逗号分隔
- assembly - Raspberry Pi 4 的正确 .cpu、.fpu 程序集条目是什么
- flutter - Flutter 小部件未正确交换其位置