Class CharSequenceLength

All Implemented Interfaces:
Matcher<CharSequence>, SelfDescribing

public class CharSequenceLength extends FeatureMatcher<CharSequence,Integer>
A Matcher that checks the length of a string.
  • Constructor Details

  • Method Details

    • featureValueOf

      protected Integer featureValueOf(CharSequence actual)
      Description copied from class: FeatureMatcher
      Implement this to extract the interesting feature.
      Specified by:
      featureValueOf in class FeatureMatcher<CharSequence,Integer>
      Parameters:
      actual - the target object
      Returns:
      the feature to be matched
    • hasLength

      public static Matcher<CharSequence> hasLength(int length)
      Creates a matcher of CharSequence 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<CharSequence> hasLength(Matcher<? super Integer> lengthMatcher)
      Creates a matcher of CharSequence 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.