Skip to content

Add MapMatcher - #34

Closed
spkrka wants to merge 1 commit into
masterfrom
krka/functions
Closed

spkrka wants to merge 1 commit into
masterfrom
krka/functions

Conversation

@spkrka

@spkrka spkrka commented Jan 25, 2019

Copy link
Copy Markdown
Member

No description provided.

Comment thread README.md

You can also apply general functions/lambdas for matches:
```java
assertThat("A string", MapMatcher.map(s -> s.charAt(0), equalTo('A')))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if you could describe the intended uses a little bit more or provide some more examples - couldn't this example also be solved with assertThat("A string", startsWith("a"))?

http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#startsWith(java.lang.String)

Just curious what other uses you have in mind

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real usecase that made me look for something like this is:

assertThat(protobufObj, map(UserAttributesMutated::getAttributesList, hasItem(map(AttributeMutation::getName, equalTo("country")))))));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that this use-case is already fulfilled by the POJO matcher.

assertThat(protobufObj, is(pojo(UserAttributesMutated.class).where(UserAttributesMutated::getAttributesList, hasItem(...)))

We can probably make it more concise but that should be a PR for the POJO matcher.

Also, MapMatcher to me sounds like something matching on Map objects, and using the word map goes a bit against the declarative wording of hamcrest. I would in any case prefer the wording resultOf or something.

@caesar-ralf

Copy link
Copy Markdown
Contributor

closing old PR that has not been reviewed/merged in years. Feel free to re-open if you believe it's still relevant

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.

4 participants