Nasıl bir assertThatşey olurdu null?
Örneğin
assertThat(attr.getValue(), is(""));
Ama sahip olamayacağını söyleyerek bir hata alıyorum nulliçinde is(null).
Nasıl bir assertThatşey olurdu null?
Örneğin
assertThat(attr.getValue(), is(""));
Ama sahip olamayacağını söyleyerek bir hata alıyorum nulliçinde is(null).
Yanıtlar:
IsNull.nullValue()Yöntemi kullanabilirsiniz :
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNullBu sınıftaki statik bir yöntemdir. Sadece yap static importya da kullan IsNull.nullValue().
import static org.hamcrest.core.IsNull.nullValue;Sınıfınıza ekleyin .
import static org.hamcrest.CoreMatchers.nullValue.
neden kullanılmıyor assertNull(object)/ assertNotNull(object)?
Eğer istersen hamcrestyapabilirsin
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
Gelen JunitYapabileceğiniz
import static junit.framework.Assert.assertNull;
assertNull(object);
Aşağıdakileri kullanın (Hamcrest'ten):
assertThat(attr.getValue(), is(nullValue()));
Kotlin'de issaklıdır bu yüzden kullanın:
assertThat(attr.getValue(), `is`(nullValue()));
ismı?