org.hamcrest.core.IsNot Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
/* Copyright (c) 2000-2009 hamcrest.org
*/
package org.hamcrest.core;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import static org.hamcrest.core.IsEqual.equalTo;
/**
* Calculates the logical negation of a matcher.
*/
public class IsNot extends BaseMatcher {
private final Matcher matcher;
public IsNot(Matcher matcher) {
this.matcher = matcher;
}
@Override
public boolean matches(Object arg) {
return !matcher.matches(arg);
}
@Override
public void describeTo(Description description) {
description.appendText("not ").appendDescriptionOf(matcher);
}
/**
* Creates a matcher that wraps an existing matcher, but inverts the logic by which
* it will match.
*
* For example:
* assertThat(cheese, is(not(equalTo(smelly))))
*
* @param matcher
* the matcher whose sense should be inverted
*/
@Factory
public static Matcher not(Matcher matcher) {
return new IsNot(matcher);
}
/**
* A shortcut to the frequently used not(equalTo(x))
.
*
* For example:
* assertThat(cheese, is(not(smelly)))
* instead of:
* assertThat(cheese, is(not(equalTo(smelly))))
*
* @param value
* the value that any examined object should not equal
*/
@Factory
public static Matcher not(T value) {
return not(equalTo(value));
}
}