George
George

Reputation: 3030

AssertJ List of String Must Exist In Expected, Ignoring Duplicates

I have a expected List of Strings:

List<String> expected = Arrays.asList("a", "b");

I want these assertions be evaluated with these results:

{"a", "a", "b", "b"} -> true
{"a", "b", "c"} -> false

Essentially, I want assertJ to ignore/remove any duplicates that is being evaluated. How can I do this with the Assertions API?

Upvotes: 0

Views: 461

Answers (1)

Joel Costigliola
Joel Costigliola

Reputation: 7116

Try containsOnly, to quote the javadoc:

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).

Upvotes: 1

Related Questions