I am using AssertJ
. I have a class like MyObj
. And I have a List
of MyObj
.
Class MyObj {
...
Map<K,V> myMap;
...
}
When I use:
assertThat(list).extracting("myMap")
, I cannot use .containsKey()
method.assertThat(list).extracting("myMap", Map.class)
, but it does not work either.What is the right way of using it?
AssertJ has entry() method. You can assert map value like this.
assertThat(list)
.extracting("myMap")
.contains(entry("foo1", "bar1"), entry("foo2", "bar2"));
Here's javadoc : http://joel-costigliola.github.io/assertj/core/api/org/assertj/core/data/MapEntry.html