是否可以使用FieldByFieldElementComparator 从assertJ 中排除某些字段?

Is it possible to exclude some fields from assertJ usingFieldByFieldElementComparator?

如何实现以下:

List<Data> streams = new ArrayList<>();
assertThat(streams).usingFieldByFieldElementComparatorIgnoringGivenFields("createdOn").containsOnly(data1, data2);

使用 ListAssert.usingElementComparatorIgnoringFields(String... fields) that does the same thing as ListAssert.usingFieldByFieldElementComparator() 但允许忽略一些 fields/properties :

Use field/property by field/property comparison on all fields/properties except the given ones

所以你可以这样写:

List<Data> streams = new ArrayList<>();
//...
Assertions.assertThat(streams)
          .usingElementComparatorIgnoringFields("createdOn")
          .containsOnly(data1, data2);