Package com.google.common.truth
Class StringSubject
Propositions for string subjects.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
Case insensitive propositions for string subjects.Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.EqualityCheck, Subject.Factory<SubjectT extends Subject,
ActualT> -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
StringSubject
(FailureMetadata metadata, String string) Constructor for use by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionvoid
contains
(CharSequence string) Fails if the string does not contain the given sequence.void
containsMatch
(String regex) Fails if the string does not contain a match on the given regex.void
containsMatch
(Pattern regex) Fails if the string does not contain a match on the given regex.void
doesNotContain
(CharSequence string) Fails if the string contains the given sequence.void
doesNotContainMatch
(String regex) Fails if the string contains a match on the given regex.void
doesNotContainMatch
(Pattern regex) Fails if the string contains a match on the given regex.void
doesNotMatch
(String regex) Fails if the string matches the given regex.void
doesNotMatch
(Pattern regex) Fails if the string matches the given regex.void
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.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."final void
Deprecated.void
Fails if the string is equal to the zero-length "empty string."void
Fails if the string does not match the given regex.void
Fails if the string does not match the given regex.void
startsWith
(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
actual, actualCustomStringRepresentation, actualCustomStringRepresentationForPackageMembersToCall, butWas, check, check, checkNoNeedToDisplayBothValues, equals, fail, fail, fail, failEqualityCheckForEqualsWithoutDescription, failWithActual, failWithActual, failWithActual, failWithActual, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutActual, failWithoutActual, failWithoutActual, failWithoutSubject, hashCode, ignoreCheck, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString, typeDescription
-
Field Details
-
actual
-
-
Constructor Details
-
StringSubject
Constructor for use by subclasses. If you want to create an instance of this class itself, callcheck(...)
.that(actual)
.
-
-
Method Details
-
isEquivalentAccordingToCompareTo
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
Fails if the string does not contain the given sequence. -
doesNotContain
Fails if the string contains the given sequence. -
startsWith
Fails if the string does not start with the given string. -
endsWith
Fails if the string does not end with the given string. -
matches
Fails if the string does not match the given regex. -
matches
Fails if the string does not match the given regex. -
doesNotMatch
Fails if the string matches the given regex. -
doesNotMatch
Fails if the string matches the given regex. -
containsMatch
Fails if the string does not contain a match on the given regex. -
containsMatch
Fails if the string does not contain a match on the given regex. -
doesNotContainMatch
Fails if the string contains a match on the given regex. -
doesNotContainMatch
Fails if the string contains a match on the given regex. -
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.
-
Subject.isEqualTo(java.lang.Object)
instead.