【发布时间】:2018-09-30 10:28:57
【问题描述】:
使用 AssertJ,我可以检查 Map 是否具有引用值满足特定 Consumer 的键:
@AllArgsConstructor
@Getter
public static class User {
private Long id;
private String name;
}
@Test
public void x() {
Map<String, User> map = new HashMap<>();
map.put("key", new User(123, "Random Hacker"));
Assertions.assertThat(map).hasEntrySatisfying("key", __ -> {
Assertions.assertThat(__.getName()).isEqualTo("Random Hacker");
});
}
是否可以使用 Hamcrest 检查给定键(以及键/值存在)的特定 Map 值的条件?
注意 public SELF hasEntrySatisfying(K key, Consumer<? super V> valueRequirements) 自 v3.6.0 (2016-11-21) 起已添加到 AspectJ。
【问题讨论】: