zhangjingli35 / hamcrest

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

IsEmptyMap #193

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 whether its empty.

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

GoogleCodeExporter commented 8 years ago
[deleted comment]
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:41

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.empty());

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

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.anEmptyMap());

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