Package org.hamcrest.collection
Class IsCollectionWithSize<E>
java.lang.Object
org.hamcrest.BaseMatcher<Collection<? extends E>>
org.hamcrest.TypeSafeDiagnosingMatcher<Collection<? extends E>>
org.hamcrest.FeatureMatcher<Collection<? extends E>,Integer>
org.hamcrest.collection.IsCollectionWithSize<E>
- Type Parameters:
E
- the collection element type
- All Implemented Interfaces:
Matcher<Collection<? extends E>>
,SelfDescribing
Matches if collection size satisfies a nested matcher.
-
Constructor Summary
ConstructorDescriptionIsCollectionWithSize
(Matcher<? super Integer> sizeMatcher) Constructor, best called fromhasSize(int)
orhasSize(Matcher)
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Integer
featureValueOf
(Collection<? extends E> actual) Implement this to extract the interesting feature.static <E> Matcher
<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
<Collection<? extends E>> 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_, isNotNull, toString
-
Constructor Details
-
IsCollectionWithSize
Constructor, best called fromhasSize(int)
orhasSize(Matcher)
.- Parameters:
sizeMatcher
- the expected size
-
-
Method Details
-
featureValueOf
Description copied from class:FeatureMatcher
Implement this to extract the interesting feature.- Specified by:
featureValueOf
in classFeatureMatcher<Collection<? extends E>,
Integer> - Parameters:
actual
- the target object- Returns:
- the feature to be matched
-
hasSize
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)))
- Type Parameters:
E
- the matcher type.- Parameters:
sizeMatcher
- a matcher for the size of an examinedCollection
- Returns:
- The matcher.
-
hasSize
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))
- Type Parameters:
E
- the matcher type.- Parameters:
size
- the expected size of an examinedCollection
- Returns:
- The matcher.
-