Class StringSubject
A subject for
String
values.- Author:
- David Saff, Christian Gruber (cgruber@israfil.net)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Offers case-insensitive checks for string values.Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.Factory<SubjectT extends Subject, ActualT>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
StringSubject
(FailureMetadata metadata, @Nullable String actual) Constructor for use by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionvoid
contains
(@Nullable CharSequence string) Checks that the actual value contains the given sequence.void
containsMatch
(@Nullable String regex) Checks that the actual value contains a match on the given regex.void
containsMatch
(@Nullable Pattern regex) Checks that the actual value contains a match on the given regex.void
doesNotContain
(@Nullable CharSequence string) Checks that the actual value does not contain the given sequence.void
doesNotContainMatch
(@Nullable String regex) Checks that the actual value does not contain a match on the given regex.void
doesNotContainMatch
(@Nullable Pattern regex) Checks that the actual value does not contain a match on the given regex.void
doesNotMatch
(@Nullable String regex) Checks that the actual value does not match the given regex.void
doesNotMatch
(@Nullable Pattern regex) Checks that the actual value does not match the given regex.void
Checks that the actual value ends with the given string.void
hasLength
(int length) Checks that the actual value has the given length.Returns aStringSubject
-like instance that will ignore the case of the characters.void
isEmpty()
Checks that the actual value is the empty string.final void
isEquivalentAccordingToCompareTo
(@Nullable String expected) Deprecated.void
Checks that the actual value is not the empty string.void
Checks that the actual value matches the given regex.void
Checks that the actual value matches the given regex.void
startsWith
(@Nullable String string) Checks that the actual value starts 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 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 actual value 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 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
Checks that the actual value contains the given sequence. -
doesNotContain
Checks that the actual value does not contain the given sequence. -
startsWith
-
endsWith
-
matches
-
matches
Checks that the actual value matches the given regex. -
doesNotMatch
-
doesNotMatch
Checks that the actual value does not match the given regex. -
containsMatch
Checks that the actual value contains a match on the given regex. -
containsMatch
-
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
-
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.