org.hamcrest.collection.IsEmptyCollection 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 java.util.Collection;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
/**
* Tests if collection is empty.
*/
public class IsEmptyCollection extends TypeSafeMatcher> {
@Override
public boolean matchesSafely(Collection extends E> item) {
return item.isEmpty();
}
@Override
public void describeMismatchSafely(Collection extends E> item, Description mismatchDescription) {
mismatchDescription.appendValue(item);
}
@Override
public void describeTo(Description description) {
description.appendText("an empty collection");
}
/**
* Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty
* method returns true
.
*
* For example:
* assertThat(new ArrayList<String>(), is(empty()))
*
*/
@Factory
public static Matcher> empty() {
return new IsEmptyCollection();
}
/**
* Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty
* method returns true
.
*
* For example:
* assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
*
* @param type
* the type of the collection's content
*/
@Factory
public static Matcher> emptyCollectionOf(Class type) {
@SuppressWarnings({ "rawtypes", "unchecked" })
final Matcher> result = (Matcher)empty();
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy