AssertJhasValueSatisfying(Consumer<T> requirement)
为 JavaOptional
对象提供了方法。此方法允许在可选值上创建断言,如下所示:
assertThat(myOptional).hasValueSatisfying(v -> {
assertThat(v.getFirstName()).isEqualTo("Stephen");
assertThat(v.getLastName()).isEqualTo("Smith");
assertThat(v.getAge()).isEqualTo(22);
});
有没有等效的收藏方法?因为我可以滥用这样的allMatch(Predicate<? super T> predicate)
方法
assertThat(myIcelanderFriends).extracting(Person::getAddress)
.allMatch(a -> {
assertThat(a.getCountry()).isEqualTo("Iceland");
assertThat(a.getPhoneContryCode()).isEqualTo("+354");
assertThat(a.getSurname()).endsWith("son");
return true; // Predictes must return a boolean
});
但是我必须添加误导return true;
行,因为 Predicate 需要返回值。我更希望这里也有haveValuesSatisfying(Consumer<T> requirement)
方法。我是否监督过这种方法或它不存在(还)?