
ext.test4j.hamcrest.collection.IsCollectionWithSize Maven / Gradle / Ivy
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 super Integer> sizeMatcher) {
super(sizeMatcher, "a collection with size", "collection size");
}
@Override
protected Integer featureValueOf(Collection extends E> actual) {
return actual.size();
}
/**
* Does collection size satisfy a given matcher?
*/
@Factory
public static Matcher> hasSize(Matcher super Integer> 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 super Integer> matcher = equalTo(size);
return IsCollectionWithSize.hasSize(matcher);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy