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 Show documentation
Show all versions of hamcrest Show documentation
Core API and libraries of hamcrest matcher framework.
package org.hamcrest.collection;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import java.util.Collection;
/**
* 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()))
*
* @param
* the matcher type.
* @return The matcher.
*/
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
* the matcher type.
* @param unusedToForceReturnType
* the type of the collection's content
* @return The matcher.
*/
@SuppressWarnings({"unchecked", "UnusedParameters"})
public static Matcher> emptyCollectionOf(Class unusedToForceReturnType) {
return (Matcher)empty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy