org.hamcrest.collection
Class IsArrayWithSize<E>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeDiagnosingMatcher<T>
org.hamcrest.FeatureMatcher<E[],java.lang.Integer>
org.hamcrest.collection.IsArrayWithSize<E>
- All Implemented Interfaces:
- Matcher<E[]>, SelfDescribing
public class IsArrayWithSize<E>
- extends FeatureMatcher<E[],java.lang.Integer>
Matches if array size satisfies a nested matcher.
Method Summary |
static
|
arrayWithSize(int size)
Creates a matcher for arrays that matches when the length of the array
equals the specified size . |
static
|
arrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
Creates a matcher for arrays that matches when the length of the array
satisfies the specified matcher. |
static
|
emptyArray()
Creates a matcher for arrays that matches when the length of the array
is zero. |
protected java.lang.Integer |
featureValueOf(E[] actual)
Implement this to extract the interesting feature. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
IsArrayWithSize
public IsArrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
featureValueOf
protected java.lang.Integer featureValueOf(E[] actual)
- Description copied from class:
FeatureMatcher
- Implement this to extract the interesting feature.
- Specified by:
featureValueOf
in class FeatureMatcher<E[],java.lang.Integer>
- Parameters:
actual
- the target object
- Returns:
- the feature to be matched
arrayWithSize
public static <E> Matcher<E[]> arrayWithSize(Matcher<? super java.lang.Integer> sizeMatcher)
- Creates a matcher for arrays that matches when the
length
of the array
satisfies the specified matcher.
For example:
assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
- Parameters:
sizeMatcher
- a matcher for the length of an examined array
arrayWithSize
public static <E> Matcher<E[]> arrayWithSize(int size)
- Creates a matcher for arrays that matches when the
length
of the array
equals the specified size
.
For example:
assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
- Parameters:
size
- the length that an examined array must have for a positive match
emptyArray
public static <E> Matcher<E[]> emptyArray()
- Creates a matcher for arrays that matches when the
length
of the array
is zero.
For example:
assertThat(new String[0], emptyArray())