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)
.
You can use IsNull.nullValue()
method:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNull
It's a static method in that class. Just do static import
, or use IsNull.nullValue()
.
Commented
Sep 24, 2013 at 17:03
import static org.hamcrest.core.IsNull.nullValue;
to your class.
Commented
Sep 24, 2013 at 17:05
import static org.hamcrest.CoreMatchers.nullValue
.
why not use assertNull(object)
/ assertNotNull(object)
?
If you want to hamcrest
, you can do
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
In Junit
you can do
import static junit.framework.Assert.assertNull;
assertNull(object);
Use the following (from Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
In Kotlin is
is reserved so use:
assertThat(attr.getValue(), `is`(nullValue()));