Package org.hamcrest.text
Class CharSequenceLength
- java.lang.Object
-
- org.hamcrest.BaseMatcher<T>
-
- org.hamcrest.TypeSafeDiagnosingMatcher<T>
-
- org.hamcrest.FeatureMatcher<java.lang.CharSequence,java.lang.Integer>
-
- org.hamcrest.text.CharSequenceLength
-
- All Implemented Interfaces:
Matcher<java.lang.CharSequence>
,SelfDescribing
public class CharSequenceLength extends FeatureMatcher<java.lang.CharSequence,java.lang.Integer>
- Author:
- Marco Leichsenring, Steve Freeman
-
-
Constructor Summary
Constructors Constructor Description CharSequenceLength(Matcher<? super java.lang.Integer> lengthMatcher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Integer
featureValueOf(java.lang.CharSequence actual)
Implement this to extract the interesting feature.static Matcher<java.lang.CharSequence>
hasLength(int length)
Creates a matcher ofCharSequence
that matches when a char sequence has the given length For example:static Matcher<java.lang.CharSequence>
hasLength(Matcher<? super java.lang.Integer> lengthMatcher)
Creates a matcher ofCharSequence
that matches when a char sequence has the given length For example:-
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 Detail
-
CharSequenceLength
public CharSequenceLength(Matcher<? super java.lang.Integer> lengthMatcher)
- Parameters:
lengthMatcher
- The matcher to apply to the feature
-
-
Method Detail
-
featureValueOf
protected java.lang.Integer featureValueOf(java.lang.CharSequence actual)
Description copied from class:FeatureMatcher
Implement this to extract the interesting feature.- Specified by:
featureValueOf
in classFeatureMatcher<java.lang.CharSequence,java.lang.Integer>
- Parameters:
actual
- the target object- Returns:
- the feature to be matched
-
hasLength
public static Matcher<java.lang.CharSequence> hasLength(int length)
Creates a matcher ofCharSequence
that matches when a char sequence has the given length For example:assertThat("text", hasLength(4))
- Parameters:
length
- the expected length of the string- Returns:
- The matcher.
-
hasLength
public static Matcher<java.lang.CharSequence> hasLength(Matcher<? super java.lang.Integer> lengthMatcher)
Creates a matcher ofCharSequence
that matches when a char sequence has the given length For example:assertThat("text", hasLength(lessThan(4)))
- Parameters:
lengthMatcher
- the expected length of the string- Returns:
- The matcher.
-
-