Reputation: 299
I have a List<Object> and want to verify in jUnit that the list has an object of a certain type. I tried this:
assertThat(myList,hasItem(isA(ExpectedClass.class)));
But, I get this:
java.lang.AssertionError: Expected: a collection containing null but: at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) at org.junit.Assert.assertThat(Assert.java:865) at org.junit.Assert.assertThat(Assert.java:832)
Could someone tell me how to build the appropriate matcher?
Upvotes: 2
Views: 782
Reputation: 40336
The problem is that you've used junit's assertThat instead of hamcrest's.
import org.hamcrest.MatcherAssert.assertThat;
works fine.
Upvotes: 1