Skip to content

contains matcher should also support empty set evaluation or alternatively we should have one that can #435

@mat013

Description

@mat013

i have test case where the outcome returns empty set however I cannot use contains matcher as it throws following exception

Caused by: java.lang.IllegalArgumentException: Should specify at least one expected element
at org.hamcrest.collection.IsIterableContainingInOrder$MatchSeries.(IsIterableContainingInOrder.java:46)

The issue is not when you have a single test where one can test for isEmpty which i think would be more transparent

however if you want to run datadriven test where one of the test cases is that the outcome is an empty set, then it would be simplier to reuse the same test for that testcase rather than needing to execute those in a separate test

Alternatively to this one should introduce a new matcher which could (containsIncludingEmpty?) accept an empty set

The only workaround I could use if I did not have to implement is containsInAnyOrder but that does not take order into consideration
And example in spock

void 'unsupported'() {
  when:
     true
   then:
       that(given, contains(given.toArray()))
   where:
       given   | _
       ['abc'] | _
       []      | _

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions