Open GoogleCodeExporter opened 9 years ago
Yes, the overrides are a mess, largely thanks to broken Java generics, but it
looks to me like there's a varargs
version.
Also, remember that contains() will expect there to be the same number of
matchers as items in the collection,
so you don't need the second matcher.
Check the latest drop for iterableWithSize. It should have better generics.
That said, I sometimes end up writing
helper methods around an expectation to force the type.
Original comment by smgfree...@gmail.com
on 28 Feb 2009 at 11:32
iterableWithSize also caused problems for me, but I was able to use hasSize
instead.
Note that hasSize works on Collection instead of Iterable, but this was not a
problem for me.
Original comment by pjvleeu...@gmail.com
on 25 Oct 2010 at 1:42
tagging
Original comment by t.denley
on 12 May 2012 at 11:01
Same problem here:
Iterable<Foo> result = …
assertThat(result, is(iterableOfSize(2))); <- compile error
Shouldn't iterableOfSize(…) return a Matcher<? extends Object> instead of
Matcher<Object>?
Original comment by oliver.gierke@me.com
on 19 Jul 2012 at 7:11
It's clunky but the following will compile and work
assertThat(result, IsIterableWithSize.<Foo>iterableWithSize(2));
See also
http://stackoverflow.com/questions/9707531/hamcrest-generics-hell-2-iterablewith
size-gives-errror-is-not-applicable-for
Original comment by crottype...@gmail.com
on 31 Jan 2013 at 7:09
Correction:
assertThat(result, IsIterableWithSize.<Foo>iterableWithSize(2)); works in
eclipse but not necessarily elsewhere!
Original comment by crottype...@gmail.com
on 31 Jan 2013 at 7:50
@Oliver this is working for me. Note that I am not using
org.junit.Assert.assertThat. I had to bring hamcrest before junit in my eclipse
classpath to achieve this. I am not sure on the details of how maven handles
this.
@Test
public void test() {
Foo foo = new Foo();
Iterable<Foo> result = Arrays.asList(foo, foo);
org.hamcrest.MatcherAssert.assertThat(result, org.hamcrest.Matchers.is(org.hamcrest.Matchers.<Foo> iterableWithSize(2)));
}
Fully qualified because it matters what the external classes are!
Original comment by crottype...@gmail.com
on 15 Mar 2013 at 12:46
Original issue reported on code.google.com by
rwallace...@gmail.com
on 1 Jan 2009 at 5:05