Class StringSubject


public class StringSubject extends ComparableSubject<String>
Propositions for string subjects.
  • Field Details

    • actual

      private final String actual
  • Constructor Details

    • StringSubject

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

    • isEquivalentAccordingToCompareTo

      @Deprecated public final void isEquivalentAccordingToCompareTo(String other)
      Deprecated.
      Use Subject.isEqualTo(java.lang.Object) instead. String comparison is consistent with equality.
      Description copied from class: ComparableSubject
      Checks that the subject is equivalent to other according to Comparable.compareTo(T), (i.e., checks that a.comparesTo(b) == 0).

      Note: Do not use this method for checking object equality. Instead, use Subject.isEqualTo(Object).

      Overrides:
      isEquivalentAccordingToCompareTo in class ComparableSubject<String>
    • 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(CharSequence string)
      Fails if the string does not contain the given sequence.
    • doesNotContain

      public void doesNotContain(CharSequence string)
      Fails if the string contains the given sequence.
    • startsWith

      public void startsWith(String string)
      Fails if the string does not start with the given string.
    • endsWith

      public void endsWith(String string)
      Fails if the string does not end with the given string.
    • matches

      public void matches(String regex)
      Fails if the string does not match the given regex.
    • matches

      public void matches(Pattern regex)
      Fails if the string does not match the given regex.
    • doesNotMatch

      public void doesNotMatch(String regex)
      Fails if the string matches the given regex.
    • doesNotMatch

      public void doesNotMatch(Pattern regex)
      Fails if the string matches the given regex.
    • containsMatch

      public void containsMatch(Pattern regex)
      Fails if the string does not contain a match on the given regex.
    • containsMatch

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

      public void doesNotContainMatch(Pattern regex)
      Fails if the string contains a match on the given regex.
    • doesNotContainMatch

      public void doesNotContainMatch(String regex)
      Fails if the string contains a match on the given regex.
    • 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.