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

it.ozimov.cirneco.hamcrest.number.IsNotANumber Maven / Gradle / Ivy

package it.ozimov.cirneco.hamcrest.number;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;


/**
 * Is the numeric value a number?
 *
 * @since version 0.1 for JDK7
 */
public class IsNotANumber extends TypeSafeMatcher {

    /**
     * Creates a matcher for {@code N} that matches when the number is a {@linkplain Double}
     * or {@linkplain Float} such that a call to method isNaN() returns true.
     * 

* For example: *

assertThat((1.0/.0D), notANumber())
* will return true. */ public static Matcher notANumber() { return new IsNotANumber<>(); } @Override protected boolean matchesSafely(final N number) { if (number instanceof Double) { return ((Double) number).isNaN(); } else if (number instanceof Float) { return ((Float) number).isNaN(); } return false; } @Override protected void describeMismatchSafely(final N item, final Description mismatchDescription) { mismatchDescription.appendValue(item) .appendText(" is not a number (i.e. Double.NaN or Float.NaN)"); } @Override public void describeTo(final Description description) { description.appendText(" not a number (i.e. Double.NaN or Float.NaN)"); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy