我想检查正在测试的集合是否包含以特定字符串结尾的任何元素。
对于 Hamcrest,它可能是这样的:
assertThat("Contains an element ending with 'xyz'",
myCollection, hasItems(endsWith("xyz")));
如何使用 AssertJ 做同样的事情?
最佳答案
您可以使用anyMatch(Predicate)
或anySatisfy(assertions on elements)
,例如:
assertThat(myCollection).as("Contains an element ending with 'xyz'")
.anyMatch(element -> element.endsWith("xyz"));
关于java - AssertJ:集合包含值以字符串结尾的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59754811/