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 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 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()))
* */ @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