summaryrefslogtreecommitdiffstats
path: root/hamcrest-core/src/org/hamcrest/core/IsNull.java
blob: 737dcf20b5af8726001e28fdef978fa8e6a4e353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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();
    }
}