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?
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?
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");