Come dovrei assertThatqualcosa null?
per esempio
assertThat(attr.getValue(), is(""));
Ma ottengo un errore che dice che non posso avere nullin is(null).
Come dovrei assertThatqualcosa null?
per esempio
assertThat(attr.getValue(), is(""));
Ma ottengo un errore che dice che non posso avere nullin is(null).
Risposte:
Puoi usare il IsNull.nullValue()metodo:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNullÈ un metodo statico in quella classe. Basta fare static importo usare IsNull.nullValue().
import static org.hamcrest.core.IsNull.nullValue;alla tua classe.
import static org.hamcrest.CoreMatchers.nullValue.
perché non usare assertNull(object)/ assertNotNull(object)?
Se vuoi hamcrest, puoi farlo
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
In Junitte puoi fare
import static junit.framework.Assert.assertNull;
assertNull(object);
Utilizzare quanto segue (da Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
In Kotlin isè riservato quindi usare:
assertThat(attr.getValue(), `is`(nullValue()));
is?