Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow matching against polymorphic collections #422

Merged
merged 4 commits into from
Sep 22, 2024

Conversation

tumbarumba
Copy link
Member

As discussed in #252, there are problems with matching against polymorphic collections.

This fix attempts to apply the PECS rule (producer extends, consumer super) to the Hamcrest IsIterableContaining matcher. In this instance, a collection of items should be treated as a producer according to this rule, while a matcher acts as a consumer. There was some confustion about PECS in the context of collections of matchers, but I'm hoping this change addresses those issues.

I'm keen for others to test this work out

@foal
Copy link

foal commented Sep 9, 2024

Nice!
About PECS, INHO it is clear - the itemMatcher is consumer - it consumes the elements of the target collection to check them.It may check the element or any parent of the element (e.g. object != null). The output is producer - it produces global matcher for a whole collection and should be applied to collection of the elements or to collection of element's children.

@tumbarumba tumbarumba merged commit 242604a into hamcrest:master Sep 22, 2024
2 checks passed
@tumbarumba tumbarumba deleted the collection-polymorphism branch September 22, 2024 01:38
@jstewmon jstewmon mentioned this pull request Oct 17, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants