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>
A subject forStringvalues.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringSubject.CaseInsensitiveStringComparisonOffers 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
Constructors Modifier Constructor Description protectedStringSubject(FailureMetadata metadata, @Nullable String actual)The constructor is for use by subclasses only.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcontains(@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.voidendsWith(@Nullable String string)Checks that the actual value ends with the given string.voidhasLength(int length)Checks that the actual value has the given length.StringSubject.CaseInsensitiveStringComparisonignoringCase()Returns aStringSubject-like instance that will ignore the case of the characters.voidisEmpty()Checks that the actual value is the empty string.voidisEquivalentAccordingToCompareTo(@Nullable String expected)Deprecated.UseSubject.isEqualTo(java.lang.Object)instead.voidisNotEmpty()Checks that the actual value is not the empty string.voidmatches(@Nullable String regex)Checks that the actual value matches the given regex.voidmatches(@Nullable Pattern regex)Checks 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 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 actual)
The constructor is for use by subclasses only. If you want to create an instance of this class itself, callcheck(...).that(actual).
-
-
Method Detail
-
isEquivalentAccordingToCompareTo
@Deprecated public final void isEquivalentAccordingToCompareTo(@Nullable String expected)
Deprecated.UseSubject.isEqualTo(java.lang.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
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
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.
-
-