org.hamcrest.collection.IsEmptyIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hamcrest-library Show documentation
Show all versions of hamcrest-library Show documentation
A library of Hamcrest matchers - deprecated, please use "hamcrest" instead
package org.hamcrest.collection;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
/**
* Tests if collection is empty.
*/
public class IsEmptyIterable extends TypeSafeMatcher> {
@Override
public boolean matchesSafely(Iterable extends E> iterable) {
return !iterable.iterator().hasNext();
}
@Override
public void describeMismatchSafely(Iterable extends E> iter, Description mismatchDescription) {
mismatchDescription.appendValueList("[", ",", "]", iter);
}
@Override
public void describeTo(Description description) {
description.appendText("an empty iterable");
}
/**
* Creates a matcher for {@link Iterable}s matching examined iterables that yield no items.
*
* For example:
* assertThat(new ArrayList<String>(), is(emptyIterable()))
*
*/
@Factory
public static Matcher> emptyIterable() {
return new IsEmptyIterable();
}
/**
* Creates a matcher for {@link Iterable}s matching examined iterables that yield no items.
*
* For example:
* assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
*
* @param type
* the type of the iterable's content
*/
@Factory
public static Matcher> emptyIterableOf(Class type) {
@SuppressWarnings({ "rawtypes", "unchecked" })
final Matcher> result = (Matcher)emptyIterable();
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy