it.ozimov.cirneco.hamcrest.number.IsPositiveInfinity 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 positive infinite value?
*
* @since version 0.1 for JDK7
*/
public class IsPositiveInfinity extends TypeSafeMatcher {
/**
* Creates a matcher for {@code N} that matches when the number is a {@linkplain Double}
* or {@linkplain Float} with value equal to POSITIVE_INFINITY
.
*
* For example:
*
assertThat(Double.PositiveInfinity, positiveInfinity())
* will return true
.
* while:
* assertThat(10, positiveInfinity())
* assertThat(Float.NegativeInfinity, positiveInfinity())
* will both return false
.
*/
public static Matcher positiveInfinity() {
return new IsPositiveInfinity<>();
}
@Override
protected boolean matchesSafely(final N number) {
if (number instanceof Double) {
return ((Double) number).compareTo(Double.POSITIVE_INFINITY) == 0;
} else if (number instanceof Float) {
return ((Float) number).compareTo(Float.POSITIVE_INFINITY) == 0;
}
return false;
}
@Override
protected void describeMismatchSafely(final N item, final Description mismatchDescription) {
mismatchDescription.appendValue(item)
.appendText(" is not positive infinity");
}
@Override
public void describeTo(final Description description) {
description.appendText("a value equals to positive infinity");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy