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?
Using AssertJ you can write cleaner and more readable code. Plus it is super easy to learn and use. AssertJ works with any Java version over Java 6, it also supports assertions using the newer features in Java such as lambdas. Find more about methods in AssertJ here.
Strict/lenient recursive comparison Compatible means that the expected object/field types are the same or a subtype of actual/field types, for example if actual is an Animal and expected a Dog , they will be compared fiels by field in strict type checking mode.
AssertJ core is a Java library that provides a fluent interface for writing assertions. Its main goal is to improve test code readability and make maintenance of tests easier. AssertJ core provides assertions for JDK standard types and can be used with JUnit, TestNG or any other test framework.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With