Como eu assertThatalguma coisa é null?
por exemplo
assertThat(attr.getValue(), is(""));
Mas eu recebo um erro dizendo que eu não posso ter nullno is(null).
Como eu assertThatalguma coisa é null?
por exemplo
assertThat(attr.getValue(), is(""));
Mas eu recebo um erro dizendo que eu não posso ter nullno is(null).
Respostas:
Você pode usar o IsNull.nullValue()método:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNullÉ um método estático nessa classe. Basta fazer static importou usar IsNull.nullValue().
import static org.hamcrest.core.IsNull.nullValue;à sua turma.
import static org.hamcrest.CoreMatchers.nullValue.
por que não usar assertNull(object)/ assertNotNull(object)?
Se você quiser hamcrest, você pode fazer
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
Em Junitvocê pode fazer
import static junit.framework.Assert.assertNull;
assertNull(object);
Use o seguinte (do Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
No Kotlin isé reservado, então use:
assertThat(attr.getValue(), `is`(nullValue()));
is?