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

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

package it.ozimov.cirneco.hamcrest.number;

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


/**
 * Is the value a number with negative infinite value?
 *
 * @since version 0.1 for JDK7
 */
public class IsNegativeInfinity extends TypeSafeMatcher {

    /**
     * Creates a matcher for {@code N} that matches when the number is a {@linkplain Double}
     * or {@linkplain Float} with value equal to NEGATIVE_INFINITY.
     * 

* For example: *

assertThat(Float.NegativeInfinity, negativeInfinity())
* will return true. * while: *
assertThat(10, negativeInfinity())
*
assertThat(Double.PositiveInfinity, negativeInfinity())
* will both return false. */ public static Matcher negativeInfinity() { return new IsNegativeInfinity<>(); } @Override protected boolean matchesSafely(final N number) { if (number instanceof Double) { return ((Double) number).compareTo(Double.NEGATIVE_INFINITY) == 0; } else if (number instanceof Float) { return ((Float) number).compareTo(Float.NEGATIVE_INFINITY) == 0; } return false; } @Override protected void describeMismatchSafely(final N item, final Description mismatchDescription) { mismatchDescription.appendValue(item) .appendText(" is not negative infinity"); } @Override public void describeTo(final Description description) { description.appendText("a value equals to negative infinity"); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy