Class StringSubject
A subject for
String values.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOffers case-insensitive checks for string values.Nested classes/interfaces inherited from class Subject
Subject.Factory<SubjectT,ActualT> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStringSubject(FailureMetadata metadata, @Nullable String actual) The constructor is for use by subclasses only. -
Method Summary
Modifier and TypeMethodDescriptionvoidcontains(@Nullable CharSequence string) Checks that the actual value contains the given sequence.voidcontainsMatch(@Nullable String regex) Checks that the actual value contains a match on the given regex.voidcontainsMatch(@Nullable Pattern regex) Checks that the actual value contains a match on the given regex.voiddoesNotContain(@Nullable CharSequence string) Checks that the actual value does not contain the given sequence.voiddoesNotContainMatch(@Nullable String regex) Checks that the actual value does not contain a match on the given regex.voiddoesNotContainMatch(@Nullable Pattern regex) Checks that the actual value does not contain a match on the given regex.voiddoesNotMatch(@Nullable String regex) Checks that the actual value does not match the given regex.voiddoesNotMatch(@Nullable Pattern regex) Checks that the actual value does not match the given regex.voidChecks that the actual value ends with the given string.voidhasLength(int length) Checks that the actual value has the given length.Returns aStringSubject-like instance that will ignore the case of the characters.voidisEmpty()Checks that the actual value is the empty string.final voidisEquivalentAccordingToCompareTo(@Nullable String expected) Deprecated.voidChecks that the actual value is not the empty string.voidChecks that the actual value matches the given regex.voidChecks that the actual value matches the given regex.voidstartsWith(@Nullable String string) Checks that the actual value starts with the given string.Methods inherited from class ComparableSubject
isAtLeast, isAtMost, isGreaterThan, isIn, isLessThan, isNotInModifier and TypeMethodDescriptionfinal voidChecks that the actual value is greater than or equal toother.final voidChecks that the actual value is less than or equal toother.final voidisGreaterThan(String other) Checks that the actual value is greater thanother.final voidChecks that the actual value is inrange.final voidisLessThan(String other) Checks that the actual value is less thanother.final voidChecks that the actual value is not inrange.Methods inherited from class Subject
actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toStringModifier and TypeMethodDescriptionprotected StringReturns a string representation of the actual value for inclusion in failure messages.protected final StandardSubjectBuilderReturns a builder for creating a derived subject.final booleanDeprecated.Object.equals(Object)is not supported on Truth subjects.protected final voidfailWithActual(Fact first, Fact... rest) Fails, reporting a message with the given facts, followed by an automatically added fact of the form: but was: actual value.protected final voidfailWithActual(String key, @Nullable Object value) Fails, reporting a message with two "facts": key: value but was: actual value.protected final voidfailWithoutActual(Fact first, Fact... rest) Fails, reporting a message with the given facts, without automatically adding the actual value.final inthashCode()Deprecated.Object.hashCode()is not supported on Truth subjects.protected final StandardSubjectBuilderBegins a new call chain that ignores any failures.voidChecks that the value under test is equal to any of the given elements.voidChecks that the value under test is equal to the given object.voidChecks that the value under test is equal to any element in the given iterable.voidisInstanceOf(@Nullable Class<?> clazz) Checks that the value under test is an instance of the given class.voidChecks that the value under test is not equal to any of the given elements.voidisNotEqualTo(@Nullable Object other) Checks that the value under test is not equal to the given object.voidChecks that the value under test is not equal to any element in the given iterable.voidisNotInstanceOf(@Nullable Class<?> clazz) Checks that the value under test is not an instance of the given class.voidChecks that the value under test is not null.final voidisNotSameInstanceAs(@Nullable Object other) Checks that the value under test is not the same instance as the given object.voidisNull()Checks that the value under test is null.final voidisSameInstanceAs(@Nullable Object expected) Checks that the value under test is the same instance as the given object.toString()Deprecated.Object.toString()is not supported on Truth subjects.
-
Constructor Details
-
StringSubject
The constructor is for use by subclasses only. If you want to create an instance of this class itself, callcheck(...).that(actual).
-
-
Method Details
-
isEquivalentAccordingToCompareTo
Deprecated.UseSubject.isEqualTo(Object)instead. String comparison is consistent with equality.Description copied from class:ComparableSubjectChecks that the actual value is equivalent tootheraccording 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:
isEquivalentAccordingToCompareToin 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(Object)instead.