Jak bym assertThatcoś takiego null?
na przykład
assertThat(attr.getValue(), is(""));
Ale pojawia się błąd mówiąc, że nie mogę mieć nullw is(null).
Jak bym assertThatcoś takiego null?
na przykład
assertThat(attr.getValue(), is(""));
Ale pojawia się błąd mówiąc, że nie mogę mieć nullw is(null).
Odpowiedzi:
Możesz użyć IsNull.nullValue()metody:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNullTo statyczna metoda w tej klasie. Po prostu zrób static importlub użyj IsNull.nullValue().
import static org.hamcrest.core.IsNull.nullValue;do swojej klasy.
import static org.hamcrest.CoreMatchers.nullValue.
dlaczego nie użyć assertNull(object)/ assertNotNull(object)?
Jeśli chcesz hamcrest, możesz to zrobić
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
W Junitmożna zrobić
import static junit.framework.Assert.assertNull;
assertNull(object);
Użyj następujących (z Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
W Kotlinie isjest zarezerwowany, więc użyj:
assertThat(attr.getValue(), `is`(nullValue()));
is?