0

So, have an use case where in I extract title from the object, as list say 10 items, now need to verify the title is present in anyof the first 5 items. Using below method to extract the items.But not sure how to reduce the list and verify it.

softAssertions.assertThat(resultArrayList)
                      .extracting("title")
                      .as("Title match")
                      .isEqualTo(placeToSearch);
Rejish R
  • 43
  • 1
  • 4

1 Answers1

0

There is no direct way to do this with AssertJ, I think the easiest solution would be to take the 5 first elements and simply use contains as in:

softAssertions.assertThat(resultArrayList.subList(0, 5))
                  .extracting("title")
                  .as("Title match")
                  .contains(expectedTitle);

Note that using isEqualTo does not work in your example unless it corresponds to the exact list of the expected titles.

Joel Costigliola
  • 6,308
  • 27
  • 35