org.hamcrest.collection
Class IsArrayWithSize<E>

java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.hamcrest.TypeSafeDiagnosingMatcher<T>
          extended by org.hamcrest.FeatureMatcher<E[],Integer>
              extended by org.hamcrest.collection.IsArrayWithSize<E>
All Implemented Interfaces:
Matcher<E[]>, SelfDescribing

public class IsArrayWithSize<E>
extends FeatureMatcher<E[],Integer>

Matches if array size satisfies a nested matcher.


Constructor Summary
IsArrayWithSize(Matcher<? super Integer> sizeMatcher)
           
 
Method Summary
static
<E> Matcher<E[]>
arrayWithSize(int size)
          Creates a matcher for arrays that matches when the length of the array equals the specified size.
static
<E> Matcher<E[]>
arrayWithSize(Matcher<? super Integer> sizeMatcher)
          Creates a matcher for arrays that matches when the length of the array satisfies the specified matcher.
static
<E> Matcher<E[]>
emptyArray()
          Creates a matcher for arrays that matches when the length of the array is zero.
protected  Integer featureValueOf(E[] actual)
           
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IsArrayWithSize

public IsArrayWithSize(Matcher<? super Integer> sizeMatcher)
Method Detail

featureValueOf

protected Integer featureValueOf(E[] actual)
Specified by:
featureValueOf in class FeatureMatcher<E[],Integer>

arrayWithSize

public static <E> Matcher<E[]> arrayWithSize(Matcher<? super 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())



Copyright © 2014. All rights reserved.