Hamcrest matchers with Java 8 functional interfaces?

340 views
Skip to first unread message

Janne Hyötylä

unread,
Dec 12, 2015, 4:58:31 PM12/12/15
to Hamcrest Developers
Hello,

Has anybody written Hamcrest matchers that make use of Java 8 functional interfaces?
I'm thinking especially of the Function interface; the matcher would apply a mapping before matching.

This would be really useful for collections, like this:

List<Person> personList = getListofPersons();
assertThat(personList, mappedWith(Person::getFirstName, hasItem("Peter")));

That would match a Person in the List where getFirstName yields "Peter". (The mappedWith method supplies the mapping matcher)

Regards,

Janne
Reply all
Reply to author
Forward
0 new messages