0

I have something like this:

assertThat(someList).extracting("someField")

and I want to continue the assert with asserting that only duplicates exist in the extraction. Is there a good way to do this?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Hans Wurst
  • 376
  • 1
  • 3
  • 12

1 Answers1

1

If you know what value is expected, containsOnly could be an option:

Verifies that the actual group contains only the given values and nothing else, in any order and ignoring duplicates (i.e. once a value is found, its duplicates are also considered found).

Extending your example:

List<SomeObject> someList = List.of(
  new SomeObject("someValue"),
  new SomeObject("someValue")
);

assertThat(someList)
  .extracting("someField")
  .containsOnly("someValue");
Stefano Cordio
  • 1,687
  • 10
  • 20