1/* Copyright (c) 2000-2006 hamcrest.org 2 */ 3package org.hamcrest.core; 4 5import static org.hamcrest.core.IsNot.not; 6import org.hamcrest.Description; 7import org.hamcrest.Matcher; 8import org.hamcrest.Factory; 9import org.hamcrest.BaseMatcher; 10 11/** 12 * Is the value null? 13 */ 14public class IsNull<T> extends BaseMatcher<T> { 15 public boolean matches(Object o) { 16 return o == null; 17 } 18 19 public void describeTo(Description description) { 20 description.appendText("null"); 21 } 22 23 /** 24 * Matches if value is null. 25 */ 26 @Factory 27 public static <T> Matcher<T> nullValue() { 28 return new IsNull<T>(); 29 } 30 31 /** 32 * Matches if value is not null. 33 */ 34 @Factory 35 public static <T> Matcher<T> notNullValue() { 36 return not(IsNull.<T>nullValue()); 37 } 38 39 /** 40 * Matches if value is null. With type inference. 41 */ 42 @Factory 43 public static <T> Matcher<T> nullValue(@SuppressWarnings("unused") Class<T> type) { 44 return nullValue(); 45 } 46 47 /** 48 * Matches if value is not null. With type inference. 49 */ 50 @Factory 51 public static <T> Matcher<T> notNullValue(@SuppressWarnings("unused") Class<T> type) { 52 return notNullValue(); 53 } 54} 55 56