mercredi 19 juin 2019

Why does notNullValue() not compile when used with everyItem in Hamcrest

In Hamcrest the matcher notNullValue() can be used to check that a value is not null:

String string = "Foo";
assertThat(string, notNullValue());

However, this pattern cannot be used for collections:

List<String> strings = Arrays.asList("Foo", "Bar");
assertThat(strings, everyItem(notNullValue()));

As it produces a compilation error "The method assertThat(T, Matcher) in the type MatcherAssert is not applicable for the arguments (List, Matcher>)".

What explains this discrepancy? How can I make the code compile?

Aucun commentaire:

Enregistrer un commentaire