1package org.hamcrest.number;
2
3import org.hamcrest.Description;
4import org.hamcrest.Matcher;
5import org.hamcrest.TypeSafeMatcher;
6
7
8/**
9 * Is the value a number actually not a number (NaN)?
10 */
11public final class IsNaN extends TypeSafeMatcher<Double> {
12
13    private IsNaN() { }
14
15    @Override
16    public boolean matchesSafely(Double item) {
17        return Double.isNaN(item);
18    }
19
20    @Override
21    public void describeMismatchSafely(Double item, Description mismatchDescription) {
22        mismatchDescription.appendText("was ").appendValue(item);
23    }
24
25    @Override
26    public void describeTo(Description description) {
27        description.appendText("a double value of NaN");
28    }
29
30    /**
31     * Creates a matcher of {@link Double}s that matches when an examined double is not a number.
32     * For example:
33     * <pre>assertThat(Double.NaN, is(notANumber()))</pre>
34     */
35    public static Matcher<Double> notANumber() {
36        return new IsNaN();
37    }
38}
39