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

Add Matchers.empty(), Matchers,hasSize() for Maps too. #35

Closed
mattbishop opened this issue Jun 12, 2013 · 6 comments
Closed

Add Matchers.empty(), Matchers,hasSize() for Maps too. #35

mattbishop opened this issue Jun 12, 2013 · 6 comments

Comments

@mattbishop
Copy link

While IsMapWithSize exists in the API to test for these conditions on a Map, they are hard to find. Most developers only use the Matchers facade to find matchers, so we end up with code that looks like this:

assertThat(aMap.entrySet(), Matchers,empty())

It would be nicer to write:

assertThat(aMap, Matchers.empty())
@Derbeth
Copy link

Derbeth commented Jun 28, 2013

What about IsMapWithSize.anEmptyMap() and IsMapWithSize.aMapWithSize()? That do exactly what you want. See #34

@mattbishop
Copy link
Author

You're right they do work. This issue is to put methods on the Matchers class itself. Most people don't know to look further than the Matchers class' static methods.

Matt Bishop

On 2013-06-28, at 2:59 AM, Piotr Kubowicz notifications@github.com wrote:

What about IsMapWithSize.anEmptyMap() and IsMapWithSize.aMapWithSize()? That do exactly what you want. See #34


Reply to this email directly or view it on GitHub.

@UrsMetz
Copy link

UrsMetz commented Jul 29, 2014

@mattbishop I think the static methods contained inside the Matchers class are automatically created: factory methods annotated with @Factory inside the Matcher classes like IsMapWithSize are "copied" over there, cf. http://github.com/hamcrest/JavaHamcrest/blob/master/hamcrest-generator/src/main/java/org/hamcrest/generator/config/XmlConfigurator.java and the generate-module-factory calls in https://github.com/hamcrest/JavaHamcrest/blob/master/build.xml

@josephw
Copy link
Contributor

josephw commented Sep 27, 2014

Both methods were marked with @Factory since they were introduced in 749ef4b; there's nothing else to fix here.

@npathai
Copy link
Contributor

npathai commented Nov 5, 2014

We already have this feature just with a slightly different name
assertThat(map, anEmptyMap()); for checking emptiness and
assertThat(map, aMapWithSize(2)); for checking the size.

@npathai
Copy link
Contributor

npathai commented Nov 5, 2014

I think this issue should be closed.

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

No branches or pull requests

6 participants