最佳答案
给定项的 Collection或 Iterable,是否有任何 Matcher(或匹配器的组合)断言每个项匹配单个 Matcher?
例如,给定此项类型:
public interface Person {
public String getGender();
}
我想写一个断言,说明 Person集合中的所有项目都有一个特定的 gender值。我是这么想的:
Iterable<Person> people = ...;
assertThat(people, each(hasProperty("gender", "Male")));
有没有什么办法可以不用自己写 each匹配程序就可以做到这一点?