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

ext.test4j.hamcrest.collection.IsCollectionWithSize Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package ext.test4j.hamcrest.collection;

import ext.test4j.hamcrest.Factory;
import ext.test4j.hamcrest.FeatureMatcher;
import ext.test4j.hamcrest.Matcher;

import java.util.Collection;

import static ext.test4j.hamcrest.core.IsEqual.equalTo;

/**
 * Matches if collection size satisfies a nested matcher.
 */
public class IsCollectionWithSize extends FeatureMatcher, Integer> {
    public IsCollectionWithSize(Matcher sizeMatcher) {
      super(sizeMatcher, "a collection with size", "collection size");
    }

    @Override
    protected Integer featureValueOf(Collection actual) {
      return actual.size();
    }

    /**
     * Does collection size satisfy a given matcher?
     */
    @Factory
    public static  Matcher> hasSize(Matcher size) {
        return new IsCollectionWithSize(size);
    }


    /**
     * This is a shortcut to the frequently used hasSize(equalTo(x)).
     *
     * For example,  assertThat(hasSize(equal_to(x)))
     *          vs.  assertThat(hasSize(x))
     */
    @Factory
    public static  Matcher> hasSize(int size) {
        Matcher matcher = equalTo(size);
        return IsCollectionWithSize.hasSize(matcher);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy