Skip to content

Allow supplying predicate description to anyMatch and noneMatch #3638

@jh-instant

Description

@jh-instant

Feature summary

It would be helpful to be able to supply a custom predicate description to all predicate-based iterable assertions (allMatch, anyMatch and noneMatch). Currently only allMatch allows supplying a custom predicate description.

From the docs (under the example for all 3):

"You can pass a predicate description to make the error message more explicit if the assertion fails" under the example of all three.

It would be good to keep the docs aligned to the functionality, although in this case aligning the functionality to the docs would be preferable.

Example

List<String> myList = List.of("a", "b", "cc");
assertThat(myList).allMatch(entry -> entry.length() == 2, "length of 2"); // ✅
assertThat(myList).anyMatch(entry -> entry.length() == 2, "length of 2"); // ❌
assertThat(myList).noneMatch(entry -> entry.length() == 2, "length of 2"); // ❌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions