How to achieve the below:
List<Data> streams = new ArrayList<>();
assertThat(streams).usingFieldByFieldElementComparatorIgnoringGivenFields("createdOn").containsOnly(data1, data2);
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.
The AssertJ project provides fluent assertion statements for test code written in Java. These assert statements are typically used with Java JUnit tests. The base method for AssertJ assertions is the assertThat method followed by the assertion.
Use ListAssert.usingElementComparatorIgnoringFields(String... fields)
that does the same thing as ListAssert.usingFieldByFieldElementComparator()
but by allowing to ignore some fields/properties :
Use field/property by field/property comparison on all fields/properties except the given ones
So you could write :
List<Data> streams = new ArrayList<>();
//...
Assertions.assertThat(streams)
.usingElementComparatorIgnoringFields("createdOn")
.containsOnly(data1, data2);
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