ollie314 / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

IsMapWithSize #192

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
java.util.Map is not a subtype of java.util.Collection

Please provide a way to match on its size.

Original issue reported on code.google.com by sebastia...@gmail.com on 1 Apr 2013 at 3:12

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
You have my permission to incorporate the source into your code base without 
mentioning my name if necessary.

Original comment by sebastia...@gmail.com on 1 Apr 2013 at 3:15

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by t.denley on 6 Apr 2013 at 8:08

GoogleCodeExporter commented 8 years ago
You can achieve this using the existing matchers by using the map's entry set.

        final Map<String, String> map = new HashMap<String, String>();

        MatcherAssert.assertThat(map.entrySet(), Matchers.hasSize(3));

Original comment by t.denley on 6 Apr 2013 at 8:29

GoogleCodeExporter commented 8 years ago
Oh, and such a Matcher has already been written for inclusion in the next 
release of Hamcrest -- see 
https://github.com/hamcrest/JavaHamcrest/blob/master/hamcrest-library/src/main/j
ava/org/hamcrest/collection/IsMapWithSize.java

When this is released, you'll be able to do:

        MatcherAssert.assertThat(map, Matchers.aMapWithSize(3));

Original comment by t.denley on 6 Apr 2013 at 8:39