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

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

There is a newer version: 3.0
Show newest version
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 iterable) {
        return !iterable.iterator().hasNext();
    }
    @Override
    public void describeMismatchSafely(Iterable 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