diff options
Diffstat (limited to 'hamcrest-core/src/org/hamcrest/core/IsNull.java')
-rw-r--r-- | hamcrest-core/src/org/hamcrest/core/IsNull.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/hamcrest-core/src/org/hamcrest/core/IsNull.java b/hamcrest-core/src/org/hamcrest/core/IsNull.java new file mode 100644 index 0000000..737dcf2 --- /dev/null +++ b/hamcrest-core/src/org/hamcrest/core/IsNull.java @@ -0,0 +1,55 @@ +/* Copyright (c) 2000-2006 hamcrest.org + */ +package org.hamcrest.core; + +import static org.hamcrest.core.IsNot.not; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.Factory; +import org.hamcrest.BaseMatcher; + +/** + * Is the value null? + */ +public class IsNull<T> extends BaseMatcher<T> { + public boolean matches(Object o) { + return o == null; + } + + public void describeTo(Description description) { + description.appendText("null"); + } + + /** + * Matches if value is null. + */ + @Factory + public static <T> Matcher<T> nullValue() { + return new IsNull<T>(); + } + + /** + * Matches if value is not null. + */ + @Factory + public static <T> Matcher<T> notNullValue() { + return not(IsNull.<T>nullValue()); + } + + /** + * Matches if value is null. With type inference. + */ + @Factory + public static <T> Matcher<T> nullValue(@SuppressWarnings("unused") Class<T> type) { + return nullValue(); + } + + /** + * Matches if value is not null. With type inference. + */ + @Factory + public static <T> Matcher<T> notNullValue(@SuppressWarnings("unused") Class<T> type) { + return notNullValue(); + } +} + |