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

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

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

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

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

/**
 * Matches if array size satisfies a nested matcher.
 */
public class IsArrayWithSize extends FeatureMatcher {
    public IsArrayWithSize(Matcher sizeMatcher) {
        super(sizeMatcher, "an array with size","array size");
    }

    @Override
    protected Integer featureValueOf(E[] actual) {
      return actual.length;
    };

    /**
     * Does array size satisfy a given matcher?
     */
    @Factory
    public static  Matcher arrayWithSize(Matcher sizeMatcher) {
        return new IsArrayWithSize(sizeMatcher);
    }

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

    /**
     * Matches an empty array.
     */
    @Factory
    public static  Matcher emptyArray() {
        Matcher isEmpty = arrayWithSize(0);
        return describedAs("an empty array", isEmpty);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy