Package org.hamcrest.text
Class CharSequenceLength
java.lang.Object
- All Implemented Interfaces:
Matcher<CharSequence>
,SelfDescribing
A Matcher that checks the length of a string.
-
Constructor Summary
ConstructorDescriptionCharSequenceLength
(Matcher<? super Integer> lengthMatcher) Constructor, best called fromhasLength(Matcher)
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Integer
featureValueOf
(CharSequence actual) Implement this to extract the interesting feature.static Matcher
<CharSequence> hasLength
(int length) Creates a matcher ofCharSequence
that matches when a char sequence has the given length For example:static Matcher
<CharSequence> 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 Details
-
CharSequenceLength
Constructor, best called fromhasLength(Matcher)
.- Parameters:
lengthMatcher
- the expected length- See Also:
-
-
Method Details
-
featureValueOf
Description copied from class:FeatureMatcher
Implement this to extract the interesting feature.- Specified by:
featureValueOf
in classFeatureMatcher<CharSequence,
Integer> - Parameters:
actual
- the target object- Returns:
- the feature to be matched
-
hasLength
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
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.
-