Hey,
I was wondering if anyone knew of a way to check if a List is empty using assertThat() and Matchers?
Best way I could see just use JUnit:
assertFalse(list.isEmpty());
But I was hoping that there was some way to do this in Hamcrest.
Thanks!
Hey,
I was wondering if anyone knew of a way to check if a List is empty using assertThat() and Matchers?
Best way I could see just use JUnit:
assertFalse(list.isEmpty());
But I was hoping that there was some way to do this in Hamcrest.
Thanks!
Well there's always
assertThat(list.isEmpty(), is(false));
... but I'm guessing that's not quite what you meant :)
Alternatively:
assertThat((Collection)list, is(not(empty())));
empty() is a static in the Matchers class. Note the need to cast the list to Collection, thanks to Hamcrest's wonky generics.
Use IsEmptyCollection.empty() matcher. Here is hamcrests unit tests using this. Specifically:
List list = new ArrayList();
assertMatches("empty collection", empty(), list);
For a better solution, vote for: http://code.google.com/p/hamcrest/issues/detail?id=97