All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hamcrest.collection.IsEmptyCollection Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
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 item) {
        return item.isEmpty();
    }

    @Override
    public void describeMismatchSafely(Collection 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