java - examples - import static org hamcrest matchers equalto
¿Cómo afirmar que algo es nulo con Hamcrest? (4)
¿Cómo puedo assertThat algo es null ?
por ejemplo
assertThat(attr.getValue(), is(""));
Pero recibo un error que dice que no puedo tener null en is(null) .
¿por qué no usar assertNull(object) / assertNotNull(object) ?
Puede usar el método IsNull.nullValue() :
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
Si quieres hamcrest , puedes hacer
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
En Junit puedes hacer
import static junit.framework.Assert.assertNull;
assertNull(object);
Use lo siguiente (de Hamcrest):
assertThat(attr.getValue(), is(nullValue()));