it.ozimov.cirneco.hamcrest.number.IsNegative 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 {@linkplain Number} with negative value?
*
* @since version 0.2 for JDK7
*/
public class IsNegative extends TypeSafeMatcher {
/**
* Creates a matcher for {@code N} that matches when the it has a value that is less than zero.
*
* For example:
*
assertThat(-100, negative())
* will return true
.
*/
public static Matcher negative() {
return new IsNegative<>();
}
@Override
protected boolean matchesSafely(final N number) {
return number.doubleValue() < 0D;
}
@Override
protected void describeMismatchSafely(final N item, final Description mismatchDescription) {
mismatchDescription.appendValue(item)
.appendText(" is not negative");
}
@Override
public void describeTo(final Description description) {
description.appendText("a negative value");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy