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

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

/*  Copyright (c) 2000-2010 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 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())
* */ @Factory 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())))
* */ @Factory 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 */ @Factory 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 * */ @Factory public static Matcher notNullValue(Class type) { return not(nullValue(type)); } }