The getContent()
method in Spring's PagedModel
is able to get all the content from an API response absolutely fine and it is possible to write an assertion that compares the content fetched by getContent()
isEqualTo
expected response. This assertion works perfectly fine:
public void verify(List<DemoResponse> books) {
PagedModel<DemoResponse> response = BaseClient.getResponse().as(new TypeRef<>() {
});
assertThat(response.getContent()).usingRecursiveFieldByFieldElementComparator()
.contains(books);
}
What if I like to assert that the expected response is contained in getContent()
, instead of equal to it?
It tried this:
public void verify(List<DemoResponse> books) {
PagedModel<DemoResponse> response = BaseClient.getResponse().as(new TypeRef<>() {
});
assertThat(response.getContent()).usingRecursiveFieldByFieldElementComparator()
.contains(books); // books cannot be resolved
}
All of a sudden, with contains
method, the expected response books
cannot be compiled. The issue looks like a data type conversion issue, but I am not sure how to convert the data type so that contains
method can be allowed