
ext.test4j.hamcrest.core.AnyOf Maven / Gradle / Ivy
package ext.test4j.hamcrest.core;
import java.util.Arrays;
import ext.test4j.hamcrest.Description;
import ext.test4j.hamcrest.Factory;
import ext.test4j.hamcrest.Matcher;
/**
* Calculates the logical disjunction of multiple matchers. Evaluation is
* shortcut, so subsequent matchers are not called if an earlier matcher returns
* true
.
*/
@SuppressWarnings({ "rawtypes" })
public class AnyOf extends ShortcutCombination {
public AnyOf(Iterable matchers) {
super(matchers);
}
@Override
public boolean matches(Object o) {
return matches(o, true);
}
@Override
public void describeTo(Description description) {
describeTo(description, "or");
}
/**
* Evaluates to true if ANY of the passed in matchers evaluate to true.
*/
@Factory
public static AnyOf anyOf(Iterable matchers) {
return new AnyOf(matchers);
}
/**
* Evaluates to true if ANY of the passed in matchers evaluate to true.
*/
@Factory
public static AnyOf anyOf(Matcher... matchers) {
return anyOf(Arrays.asList(matchers));
}
@Factory
public static Matcher notAny(Iterable matchers) {
Matcher matcher = IsNot.not(AnyOf.anyOf(matchers));
return matcher;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy