AssertJ 使用 List 字段验证对象列表不为空

Geo*_*rge 1 assertj

例子:

public class Office {
  List<Employee> employee;
}
Run Code Online (Sandbox Code Playgroud)

我如何断言在我List<Office> offices没有员工的情况下没有?是否可以用一个断言链来断言这一点?

Joe*_*ola 6

如果我正确理解你的问题,你想检查所有办公室是否有员工,如果有,allSatisfy可以使用:

assertThat(offices).allSatisfy(office -> {
                              assertThat(office.employee).isNotEmpty();
                            });
Run Code Online (Sandbox Code Playgroud)

noneSatisfy顺便说一句,还有一个断言可用。