Package com.google.common.truth
Class StringSubject
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.ComparableSubject<String>
-
- com.google.common.truth.StringSubject
-
public class StringSubject extends ComparableSubject<String>
Propositions for string subjects.- Author:
- David Saff, Christian Gruber (cgruber@israfil.net)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
StringSubject.CaseInsensitiveStringComparison
Case insensitive propositions for string subjects.-
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.Factory<SubjectT extends Subject,ActualT>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
StringSubject(FailureMetadata metadata, @Nullable String string)
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
contains(@Nullable CharSequence string)
Fails if the string does not contain the given sequence.void
containsMatch(@Nullable String regex)
Fails if the string does not contain a match on the given regex.void
containsMatch(@Nullable Pattern regex)
Fails if the string does not contain a match on the given regex.void
doesNotContain(@Nullable CharSequence string)
Fails if the string contains the given sequence.void
doesNotContainMatch(@Nullable String regex)
Fails if the string contains a match on the given regex.void
doesNotContainMatch(@Nullable Pattern regex)
Fails if the string contains a match on the given regex.void
doesNotMatch(@Nullable String regex)
Fails if the string matches the given regex.void
doesNotMatch(@Nullable Pattern regex)
Fails if the string matches the given regex.void
endsWith(@Nullable String string)
Fails if the string does not end with the given string.void
hasLength(int expectedLength)
Fails if the string does not have the given length.StringSubject.CaseInsensitiveStringComparison
ignoringCase()
Returns aStringSubject
-like instance that will ignore the case of the characters.void
isEmpty()
Fails if the string is not equal to the zero-length "empty string."void
isEquivalentAccordingToCompareTo(@Nullable String other)
Deprecated.UseSubject.isEqualTo(java.lang.Object)
instead.void
isNotEmpty()
Fails if the string is equal to the zero-length "empty string."void
matches(@Nullable String regex)
Fails if the string does not match the given regex.void
matches(@Nullable Pattern regex)
Fails if the string does not match the given regex.void
startsWith(@Nullable String string)
Fails if the string does not start with the given string.-
Methods inherited from class com.google.common.truth.ComparableSubject
isAtLeast, isAtMost, isGreaterThan, isIn, isLessThan, isNotIn
-
Methods inherited from class com.google.common.truth.Subject
actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
-
-
-
-
Constructor Detail
-
StringSubject
protected StringSubject(FailureMetadata metadata, @Nullable String string)
Constructor for use by subclasses. If you want to create an instance of this class itself, callcheck(...)
.that(actual)
.
-
-
Method Detail
-
isEquivalentAccordingToCompareTo
@Deprecated public final void isEquivalentAccordingToCompareTo(@Nullable String other)
Deprecated.UseSubject.isEqualTo(java.lang.Object)
instead. String comparison is consistent with equality.Description copied from class:ComparableSubject
Checks that the subject is equivalent toother
according toComparable.compareTo(T)
, (i.e., checks thata.comparesTo(b) == 0
).Note: Do not use this method for checking object equality. Instead, use
Subject.isEqualTo(Object)
.- Overrides:
isEquivalentAccordingToCompareTo
in classComparableSubject<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(@Nullable CharSequence string)
Fails if the string does not contain the given sequence.
-
doesNotContain
public void doesNotContain(@Nullable CharSequence string)
Fails if the string contains the given sequence.
-
startsWith
public void startsWith(@Nullable String string)
Fails if the string does not start with the given string.
-
endsWith
public void endsWith(@Nullable String string)
Fails if the string does not end with the given string.
-
matches
public void matches(@Nullable String regex)
Fails if the string does not match the given regex.
-
matches
@GwtIncompatible("java.util.regex.Pattern") public void matches(@Nullable Pattern regex)
Fails if the string does not match the given regex.
-
doesNotMatch
public void doesNotMatch(@Nullable String regex)
Fails if the string matches the given regex.
-
doesNotMatch
@GwtIncompatible("java.util.regex.Pattern") public void doesNotMatch(@Nullable Pattern regex)
Fails if the string matches the given regex.
-
containsMatch
@GwtIncompatible("java.util.regex.Pattern") public void containsMatch(@Nullable Pattern regex)
Fails if the string does not contain a match on the given regex.
-
containsMatch
public void containsMatch(@Nullable 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 Pattern regex)
Fails if the string contains a match on the given regex.
-
doesNotContainMatch
public void doesNotContainMatch(@Nullable String regex)
Fails if the string contains a match on the given regex.
-
ignoringCase
public StringSubject.CaseInsensitiveStringComparison ignoringCase()
Returns aStringSubject
-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 callingCharacter.toUpperCase(char)
. Note that this is independent of any locale.
-
-