1 package org.hamcrest.number;
2 
3 import org.hamcrest.Description;
4 import org.hamcrest.Matcher;
5 import org.hamcrest.TypeSafeMatcher;
6 
7 
8 /**
9  * Is the value a number actually not a number (NaN)?
10  */
11 public final class IsNaN extends TypeSafeMatcher<Double> {
12 
IsNaN()13     private IsNaN() { }
14 
15     @Override
matchesSafely(Double item)16     public boolean matchesSafely(Double item) {
17         return Double.isNaN(item);
18     }
19 
20     @Override
describeMismatchSafely(Double item, Description mismatchDescription)21     public void describeMismatchSafely(Double item, Description mismatchDescription) {
22         mismatchDescription.appendText("was ").appendValue(item);
23     }
24 
25     @Override
describeTo(Description description)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      */
notANumber()35     public static Matcher<Double> notANumber() {
36         return new IsNaN();
37     }
38 }
39