Checking that a List is not empty in Hamcrest
问题 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. 回答1: 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