0

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

matt
  • 25
  • 5
  • 2
    `contains` iis for single elements **not** for a full collection of elements. You need `containsAll` for that. This is probably also what the compilation error is telling you (that a list cannot be cast to an array or single element). – M. Deinum Feb 21 '23 at 06:35

0 Answers0