ollie314 / hamcrest

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

hasKey, hasValue collection matchers not working #127

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

While using eclipse, I was writing some tests with (hamcrest-all-1.1.jar AND 
JUnit 4.8.1) and experienced the error 

"The method assertThat(T, Matcher<T>) in the type Assert is not applicable for 
the arguments (Map<String,String>, Matcher<Map<String,Object>>)"

The set up for the test included
Map<String,String> tokenToServiceMapper = new HashMap<String,String>(); 
tokenToServiceMapper.put("F", "FINANCE_PRICES");

This is not verbatim, but it is an accurate representation of the test case

assertThat(tokenToServiceMapper, hasKey("F")); 
assertThat(tokenToServiceMapper, hasValue("FINANCE_PRICES")); 

Can this be remedied, or should I analyse the code and submit a possible fix?
Regards
Alan Lewis

BTW I'm really impressed with the work that has gone into Hamcrest, together 
with JUnit and jMock is an outstanding testing framework. Please keep up the 
great work.

Original issue reported on code.google.com by alanlew...@gmail.com on 14 Oct 2010 at 8:59

GoogleCodeExporter commented 8 years ago
This seems to be solved in 1.2.1, the issue is not reproducible for me

Original comment by dietrich...@gmail.com on 26 Oct 2011 at 11:22

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 25 Apr 2012 at 11:27

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Odd. Not seeing this comment on the web page.

Have you tried any the candidate 1.3 release?

S.

Original comment by smgfree...@gmail.com on 15 May 2012 at 7:08

GoogleCodeExporter commented 8 years ago
Yeah, I deleted my comment about seeing this in 1.2.1. I was seeing it with a 
custom matcher and it turns out the issue was with my matcher. I can confirm 
that I see this issue in 1.2 but not in 1.2.1.

For anyone who comes across something similar, the issue for me turned out to 
be that the type parameters to Matcher were too strict. Replacing this:

public static <K, V> Matcher<Map<K, V>> hasSize(final int size) { ... }

with this:

public static <K, V> Matcher<Map<? extends K, ? extends V>> hasSize(final int 
size) { ... }

Got rid of the error I was seeing. I'm guessing v1.2.1 introduced a similar 
change to hasKey/hasValue.

Original comment by jdotmc@gmail.com on 15 May 2012 at 1:16