Package org.hamcrest.collection
Class IsCollectionWithSize<E>
- java.lang.Object
-
- org.hamcrest.BaseMatcher<T>
-
- org.hamcrest.TypeSafeDiagnosingMatcher<T>
-
- org.hamcrest.FeatureMatcher<java.util.Collection<? extends E>,java.lang.Integer>
-
- org.hamcrest.collection.IsCollectionWithSize<E>
-
- All Implemented Interfaces:
Matcher<java.util.Collection<? extends E>>
,SelfDescribing
public class IsCollectionWithSize<E> extends FeatureMatcher<java.util.Collection<? extends E>,java.lang.Integer>
Matches if collection size satisfies a nested matcher.
-
-
Constructor Summary
Constructors Constructor Description IsCollectionWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Integer
featureValueOf(java.util.Collection<? extends E> actual)
Implement this to extract the interesting feature.static <E> Matcher<java.util.Collection<? extends E>>
hasSize(int size)
Creates a matcher forCollection
s that matches when thesize()
method returns a value equal to the specifiedsize
.static <E> Matcher<java.util.Collection<? extends E>>
hasSize(Matcher<? super java.lang.Integer> sizeMatcher)
Creates a matcher forCollection
s that matches when thesize()
method returns a value that satisfies the specified matcher.-
Methods inherited from class org.hamcrest.FeatureMatcher
describeTo, matchesSafely
-
Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matches
-
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
-
-
-
-
Constructor Detail
-
IsCollectionWithSize
public IsCollectionWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
-
-
Method Detail
-
featureValueOf
protected java.lang.Integer featureValueOf(java.util.Collection<? extends E> actual)
Description copied from class:FeatureMatcher
Implement this to extract the interesting feature.- Specified by:
featureValueOf
in classFeatureMatcher<java.util.Collection<? extends E>,java.lang.Integer>
- Parameters:
actual
- the target object- Returns:
- the feature to be matched
-
hasSize
public static <E> Matcher<java.util.Collection<? extends E>> hasSize(Matcher<? super java.lang.Integer> sizeMatcher)
Creates a matcher forCollection
s that matches when thesize()
method returns a value that satisfies the specified matcher. For example:assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))
- Parameters:
sizeMatcher
- a matcher for the size of an examinedCollection
-
hasSize
public static <E> Matcher<java.util.Collection<? extends E>> hasSize(int size)
Creates a matcher forCollection
s that matches when thesize()
method returns a value equal to the specifiedsize
. For example:assertThat(Arrays.asList("foo", "bar"), hasSize(2))
- Parameters:
size
- the expected size of an examinedCollection
-
-