Class StringSubject


public class StringSubject extends ComparableSubject<String>
A subject for String values.
Author:
David Saff, Christian Gruber (cgruber@israfil.net)
  • Constructor Details

    • StringSubject

      protected StringSubject(FailureMetadata metadata, @Nullable String actual)
      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(@Nullable String expected)
      Deprecated.
      Use Subject.isEqualTo(java.lang.Object) instead. String comparison is consistent with equality.
      Description copied from class: ComparableSubject
      Checks that the actual value 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 length)
      Checks that the actual value has the given length.
    • isEmpty

      public void isEmpty()
      Checks that the actual value is the empty string.
    • isNotEmpty

      public void isNotEmpty()
      Checks that the actual value is not the empty string.
    • contains

      public void contains(@Nullable CharSequence string)
      Checks that the actual value contains the given sequence.
    • doesNotContain

      public void doesNotContain(@Nullable CharSequence string)
      Checks that the actual value does not contain the given sequence.
    • startsWith

      public void startsWith(@Nullable String string)
      Checks that the actual value starts with the given string.
    • endsWith

      public void endsWith(@Nullable String string)
      Checks that the actual value ends with the given string.
    • matches

      public void matches(@Nullable String regex)
      Checks that the actual value matches the given regex.
    • matches

      @GwtIncompatible("java.util.regex.Pattern") public void matches(@Nullable Pattern regex)
      Checks that the actual value matches the given regex.
    • doesNotMatch

      public void doesNotMatch(@Nullable String regex)
      Checks that the actual value does not match the given regex.
    • doesNotMatch

      @GwtIncompatible("java.util.regex.Pattern") public void doesNotMatch(@Nullable Pattern regex)
      Checks that the actual value does not match the given regex.
    • containsMatch

      @GwtIncompatible("java.util.regex.Pattern") public void containsMatch(@Nullable Pattern regex)
      Checks that the actual value contains a match on the given regex.
    • containsMatch

      public void containsMatch(@Nullable String regex)
      Checks that the actual value contains a match on the given regex.
    • doesNotContainMatch

      @GwtIncompatible("java.util.regex.Pattern") public void doesNotContainMatch(@Nullable Pattern regex)
      Checks that the actual value does not contain a match on the given regex.
    • doesNotContainMatch

      public void doesNotContainMatch(@Nullable String regex)
      Checks that the actual value does not contain 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.