【发布时间】:2015-05-05 18:38:16
【问题描述】:
给定 Collection 或 Iterable 的项目,是否有任何 Matcher(或匹配器的组合)会断言每个项目都匹配单个 Matcher?
例如,给定这个项目类型:
public interface Person {
public String getGender();
}
我想写一个断言,即Persons 集合中的所有项目都具有特定的gender 值。我在想这样的事情:
Iterable<Person> people = ...;
assertThat(people, each(hasProperty("gender", "Male")));
有什么方法可以在不自己编写 each 匹配器的情况下做到这一点?
【问题讨论】:
-
或许你可以使用everyItem Matcher:junit.sourceforge.net/javadoc/org/junit/matchers/…