Say I have a class like this:
public class Character {
public Character(String name){
this.name = name;
}
private String name;
public String getName() { return name; }
}
And later, a Map
Map<Character, Integer> characterAges = new HashMap<Character, Integer>();
characterAges.put(new Character("Frodo"), 34);
Using assertj, what is the best way to test that characterAges includes the "Frodo" character? For the age, I can do:
assertThat(characterAges).hasValue(34);
And I know I could do:
assertThat(characterAges.keySet())
.extracting("name")
.contains("Frodo");
But then I lose my fluency. What I really want it something like this:
assertThat(characterAges)
.hasKey(key.extracting("name").contains("Frodo")
.hasValue(34);
Or even better, so that I can make sure my key and value match:
assertThat(characterAges)
.hasEntry(key.extracting("name").contains("Frodo"), 34);
Is something like this possible?