
uk.org.lidalia.test.AllOf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lidalia-test Show documentation
Show all versions of lidalia-test Show documentation
A collection of useful common assertions & matchers for unit testing.
The newest version!
package uk.org.lidalia.test;
import org.hamcrest.Description;
import org.hamcrest.DiagnosingMatcher;
import org.hamcrest.Matcher;
/**
* Calculates the logical conjunction of multiple matchers. Evaluation is shortcut, so
* subsequent matchers are not called if an earlier matcher returns false
.
*/
class AllOf extends DiagnosingMatcher {
private final Iterable> matchers;
AllOf(final Iterable> matchers) {
super();
this.matchers = matchers;
}
@Override
public boolean matches(final Object object, final Description mismatch) {
for (final Matcher super T> matcher : matchers) {
if (!matcher.matches(object)) {
matcher.describeMismatch(object, mismatch);
return false;
}
}
return true;
}
@Override
public void describeTo(final Description description) {
description.appendList("(", " " + "and" + " ", ")", matchers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy