Package org.hamcrest.collection
Class IsArrayWithSize<E>
java.lang.Object
org.hamcrest.BaseMatcher<E[]>
org.hamcrest.TypeSafeDiagnosingMatcher<E[]>
org.hamcrest.FeatureMatcher<E[],Integer>
org.hamcrest.collection.IsArrayWithSize<E>
- Type Parameters:
E
- the array element type
- All Implemented Interfaces:
Matcher<E[]>
,SelfDescribing
Matches if array size satisfies a size matcher.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> Matcher
<E[]> arrayWithSize
(int size) Creates a matcher for arrays that matches when thelength
of the array equals the specifiedsize
.static <E> Matcher
<E[]> arrayWithSize
(Matcher<? super Integer> sizeMatcher) Creates a matcher for arrays that matches when thelength
of the array satisfies the specified matcher.static <E> Matcher
<E[]> Creates a matcher for arrays that matches when thelength
of the array is zero.protected Integer
featureValueOf
(E[] actual) Implement this to extract the interesting feature.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
-
IsArrayWithSize
- 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<E[],
Integer> - Parameters:
actual
- the target object- Returns:
- the feature to be matched
-
arrayWithSize
Creates a matcher for arrays that matches when thelength
of the array satisfies the specified matcher. For example:assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
- Type Parameters:
E
- the matcher type.- Parameters:
sizeMatcher
- a matcher for the length of an examined array- Returns:
- The matcher.
-
arrayWithSize
Creates a matcher for arrays that matches when thelength
of the array equals the specifiedsize
. For example:assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
- Type Parameters:
E
- the matcher type.- Parameters:
size
- the length that an examined array must have for a positive match- Returns:
- The matcher.
-
emptyArray
Creates a matcher for arrays that matches when thelength
of the array is zero. For example:assertThat(new String[0], emptyArray())
- Type Parameters:
E
- the matcher type.- Returns:
- The matcher.
-