user2811419 user2811419 - 4 months ago 38
Java Question

How to assertThat something is null with Hamcrest?

How would I

assertThat
something is
null
?

for example

assertThat(attr.getValue(), is(""));


But I get an error saying that I cannot have
null
in
is(null)
.

Answer

You can use IsNull.nullValue() method:

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

assertThat(attr.getValue(), is(nullValue()));