All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hamcrest.core.IsNull Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

import static org.hamcrest.core.IsNot.not;

/**
 * Is the value null?
 */
public class IsNull extends BaseMatcher {
    @Override
    public boolean matches(Object o) {
        return o == null;
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("null");
    }

    /**
     * Creates a matcher that matches if examined object is null.
     * For example:
     * 
assertThat(cheese, is(nullValue())
* */ public static Matcher nullValue() { return new IsNull(); } /** * A shortcut to the frequently used not(nullValue()). * For example: *
assertThat(cheese, is(notNullValue()))
* instead of: *
assertThat(cheese, is(not(nullValue())))
* */ public static Matcher notNullValue() { return not(nullValue()); } /** * Creates a matcher that matches if examined object is null. Accepts a * single dummy argument to facilitate type inference. * For example: *
assertThat(cheese, is(nullValue(Cheese.class))
* * @param type * dummy parameter used to infer the generic type of the returned matcher */ public static Matcher nullValue(Class type) { return new IsNull(); } /** * A shortcut to the frequently used not(nullValue(X.class)). Accepts a * single dummy argument to facilitate type inference.. * For example: *
assertThat(cheese, is(notNullValue(X.class)))
* instead of: *
assertThat(cheese, is(not(nullValue(X.class))))
* * @param type * dummy parameter used to infer the generic type of the returned matcher * */ public static Matcher notNullValue(Class type) { return not(nullValue(type)); } }