Is there a shorter version of the following assert statement using standard Hamcrest matchers?
Collection<Element> collection = ...
assertThat(collection, is(anyOf(nullValue(Collection.class),
emptyCollectionOf(Element.class))));
I realize there is a way to create a custom matcher, was hoping that maybe there is already something in place that addresses this without any additional code change.
There is no out-of-the-box solution, and worse, either()
can't be used due to this bug. So the shortest way is this:
assertThat(collection, anyOf(nullValue(), empty()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With