Class StringSubject


  • public class StringSubject
    extends ComparableSubject<java.lang.String>
    Propositions for string subjects.
    Author:
    David Saff, Christian Gruber (cgruber@israfil.net)
    • Constructor Detail

      • StringSubject

        protected StringSubject​(FailureMetadata metadata,
                                @Nullable java.lang.String string)
        Constructor for use by subclasses. If you want to create an instance of this class itself, call check(...).that(actual).
    • Method Detail

      • hasLength

        public void hasLength​(int expectedLength)
        Fails if the string does not have the given length.
      • isEmpty

        public void isEmpty()
        Fails if the string is not equal to the zero-length "empty string."
      • isNotEmpty

        public void isNotEmpty()
        Fails if the string is equal to the zero-length "empty string."
      • contains

        public void contains​(@Nullable java.lang.CharSequence string)
        Fails if the string does not contain the given sequence.
      • doesNotContain

        public void doesNotContain​(@Nullable java.lang.CharSequence string)
        Fails if the string contains the given sequence.
      • startsWith

        public void startsWith​(@Nullable java.lang.String string)
        Fails if the string does not start with the given string.
      • endsWith

        public void endsWith​(@Nullable java.lang.String string)
        Fails if the string does not end with the given string.
      • matches

        public void matches​(@Nullable java.lang.String regex)
        Fails if the string does not match the given regex.
      • matches

        @GwtIncompatible("java.util.regex.Pattern")
        public void matches​(@Nullable java.util.regex.Pattern regex)
        Fails if the string does not match the given regex.
      • doesNotMatch

        public void doesNotMatch​(@Nullable java.lang.String regex)
        Fails if the string matches the given regex.
      • doesNotMatch

        @GwtIncompatible("java.util.regex.Pattern")
        public void doesNotMatch​(@Nullable java.util.regex.Pattern regex)
        Fails if the string matches the given regex.
      • containsMatch

        @GwtIncompatible("java.util.regex.Pattern")
        public void containsMatch​(@Nullable java.util.regex.Pattern regex)
        Fails if the string does not contain a match on the given regex.
      • containsMatch

        public void containsMatch​(@Nullable java.lang.String regex)
        Fails if the string does not contain a match on the given regex.
      • doesNotContainMatch

        @GwtIncompatible("java.util.regex.Pattern")
        public void doesNotContainMatch​(@Nullable java.util.regex.Pattern regex)
        Fails if the string contains a match on the given regex.
      • doesNotContainMatch

        public void doesNotContainMatch​(@Nullable java.lang.String regex)
        Fails if the string contains a match on the given regex.
      • ignoringCase

        public StringSubject.CaseInsensitiveStringComparison ignoringCase()
        Returns a StringSubject-like instance that will ignore the case of the characters.

        Character equality ignoring case is defined as follows: Characters must be equal either after calling Character.toLowerCase(char) or after calling Character.toUpperCase(char). Note that this is independent of any locale.