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 mockito-all Show documentation
Show all versions of mockito-all Show documentation
Mock objects library for java
/* Copyright (c) 2000-2006 hamcrest.org
*/
package org.hamcrest.core;
import static org.hamcrest.core.IsEqual.equalTo;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Factory;
import org.hamcrest.BaseMatcher;
/**
* Calculates the logical negation of a matcher.
*/
public class IsNot extends BaseMatcher {
private final Matcher matcher;
public IsNot(Matcher matcher) {
this.matcher = matcher;
}
public boolean matches(Object arg) {
return !matcher.matches(arg);
}
public void describeTo(Description description) {
description.appendText("not ").appendDescriptionOf(matcher);
}
/**
* Inverts the rule.
*/
@Factory
public static Matcher not(Matcher matcher) {
return new IsNot(matcher);
}
/**
* This is a shortcut to the frequently used not(equalTo(x)).
*
* eg. assertThat(cheese, is(not(equalTo(smelly))))
* vs assertThat(cheese, is(not(smelly)))
*/
@Factory
public static Matcher not(T value) {
return not(equalTo(value));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy