hardayal / hamcrest

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

Compile errors on hasSize #43

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm using the latest from trunk and the following line does not compile in 
eclipse:

ArrayList<String> arrayList = new ArrayList<String>();
assertThat(arrayList, hasSize(3))

the error reported is:
The method assertThat(T, Matcher<? super T>) in the type MatcherAssert is not 
applicable for the arguments 
(ArrayList<String>, Matcher<Collection<Object>>)

Which means that I've to now do this instead:
Matcher<Collection<String>> sizeMatcher = hasSize(3);
assertThat(arrayList, sizeMatcher);

Original issue reported on code.google.com by ketanpad...@gmail.com on 29 Aug 2008 at 10:51

GoogleCodeExporter commented 8 years ago

Original comment by nat.pr...@gmail.com on 15 Oct 2008 at 9:13

GoogleCodeExporter commented 8 years ago
I hit this too and commented here...

http://groups.google.com/group/hamcrest-
dev/browse_thread/thread/2d1e196c06d8dad7/90c7958113b9aa69#90c7958113b9aa69

A fix I found was to replace this... 

  <T> Matcher<Collection<T>> hasSize(int i) { 

with this 

  <T> Matcher<Collection<? extends T>> hasSize(int i) { 

which fixes these kinds of errors

Original comment by james.st...@gmail.com on 17 Oct 2008 at 12:09

GoogleCodeExporter commented 8 years ago
Here's a patch which fixes this issue - along with a related fix to the 
generator so that we generate methods 
correctly (including Something.<T>hasSize()) to avoid further compile errors

Original comment by james.st...@gmail.com on 17 Oct 2008 at 12:43

Attachments:

GoogleCodeExporter commented 8 years ago
Here's an extra patch that adds a test case showing the hasSize() methods now 
work with Object, String and ? 
element types.

We should also switch other collection related methods to use this mechanism 
too I'd have thought

Original comment by james.st...@gmail.com on 17 Oct 2008 at 12:52

Attachments:

GoogleCodeExporter commented 8 years ago
already fixed.

Original comment by smgfree...@gmail.com on 20 Nov 2008 at 7:34

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 22 Nov 2008 at 12:16