¿Cómo sería assertThatalgo null?
por ejemplo
assertThat(attr.getValue(), is(""));
Pero me da un error que dice que no puedo tener nullen is(null).
¿Cómo sería assertThatalgo null?
por ejemplo
assertThat(attr.getValue(), is(""));
Pero me da un error que dice que no puedo tener nullen is(null).
Respuestas:
Puedes usar el IsNull.nullValue()método:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNullEs un método estático en esa clase. Solo hazlo static importo úsalo IsNull.nullValue().
import static org.hamcrest.core.IsNull.nullValue;a tu clase.
import static org.hamcrest.CoreMatchers.nullValue.
¿Por qué no usar assertNull(object)/ assertNotNull(object)?
Si quieres hamcrest, puedes hacerlo
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
En lo Junitque puedes hacer
import static junit.framework.Assert.assertNull;
assertNull(object);
Use lo siguiente (de Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
En Kotlin isestá reservado, así que use:
assertThat(attr.getValue(), `is`(nullValue()));
is?