jocarreira / hamcrest

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

org.hamcrest.collection.IsMapContaining #69

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have a map of type Map<K, List<X>>
and I would like to test whether the map has a particular key.

I would like to test it as

assertThat(map, hasKey(key));

where 'map' is instance of some Map
and 'key' is the instance of some Key.

But I get the error 

assertThat(Map<K, java.lang.Object>, Matcher<Map<K, java.lang.Object>>)
cannot be applied to
assertThat(Map<K, List<V>>, Matcher<Map<K, java.lang.Object>)

I think usage of generics in the methods of IsMapContaining are not 
properly implemented to handle the situation described above.

I wrote a work around code to solve it
assertThat(map, IsMapContaining.hasEntry(is(key), 
IsAnything.<List<V>>anything()));

May be the above code will help to understand the issue.

Original issue reported on code.google.com by rakesh.p...@gmail.com on 2 Mar 2009 at 12:32

GoogleCodeExporter commented 8 years ago
I can't reproduce this. I wrote a test that calls the method

private <K, X> void assertGenericsMap(Map<K, List<X>> map, K key) {
  assertThat(map, hasKey(key));
}

Can you give us more code and confirm the version of Hamcrest and Java
Can you also try the latest RC drop to make sure it's not already fixed.

Original comment by smgfree...@gmail.com on 2 Mar 2009 at 8:38

GoogleCodeExporter commented 8 years ago
I am using hamcrest-all-1.1.jar and Java 5

Attached is the file that shows the bug

Original comment by rakesh.p...@gmail.com on 3 Mar 2009 at 1:26

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry to bother you, it got resolved in the latest RC drop.

Original comment by rakesh.p...@gmail.com on 4 Mar 2009 at 8:02

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 21 Mar 2009 at 11:44