Class 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 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 class FeatureMatcher<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 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
      • hasLength

        public static Matcher<java.lang.CharSequence> hasLength​(Matcher<? super java.lang.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