public class Subject extends Object
Subject
 contains isEqualTo(Object) and isInstanceOf(Class), and StringSubject
 contains startsWith(String).
 To create a Subject instance, most users will call an assertThat method. For information about other ways to create an instance, see this FAQ entry.
 
For information about writing a custom Subject, see our doc on extensions.
| Modifier and Type | Class and Description | 
|---|---|
static interface  | 
Subject.Factory<SubjectT extends Subject,ActualT>
 | 
| Modifier | Constructor and Description | 
|---|---|
protected  | 
Subject(FailureMetadata metadata,
       Object actual)
Constructor for use by subclasses. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
protected String | 
actualCustomStringRepresentation()
Supplies the direct string representation of the actual value to other methods which may prefix
 or otherwise position it in an error message. 
 | 
protected StandardSubjectBuilder | 
check(String format,
     Object... args)
Returns a builder for creating a derived subject. 
 | 
boolean | 
equals(Object o)
Deprecated. 
 
Object.equals(Object) is not supported on Truth subjects. If you meant to
     test object equality between an expected and the actual value, use isEqualTo(Object) instead. | 
protected void | 
failWithActual(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 void | 
failWithActual(String key,
              Object value)
Fails, reporting a message with two "facts":
 
   key: value
   but was: actual value. 
 | 
protected void | 
failWithoutActual(Fact first,
                 Fact... rest)
Fails, reporting a message with the given facts, without automatically adding the actual
 value. 
 | 
int | 
hashCode()
Deprecated. 
 
Object.hashCode() is not supported on Truth subjects. | 
protected StandardSubjectBuilder | 
ignoreCheck()
Begins a new call chain that ignores any failures. 
 | 
void | 
isAnyOf(Object first,
       Object second,
       Object... rest)
Fails unless the subject is equal to any of the given elements. 
 | 
void | 
isEqualTo(Object expected)
Fails if the subject is not equal to the given object. 
 | 
void | 
isIn(Iterable<?> iterable)
Fails unless the subject is equal to any element in the given iterable. 
 | 
void | 
isInstanceOf(Class<?> clazz)
Fails if the subject is not an instance of the given class. 
 | 
void | 
isNoneOf(Object first,
        Object second,
        Object... rest)
Fails if the subject is equal to any of the given elements. 
 | 
void | 
isNotEqualTo(Object unexpected)
Fails if the subject is equal to the given object. 
 | 
void | 
isNotIn(Iterable<?> iterable)
Fails if the subject is equal to any element in the given iterable. 
 | 
void | 
isNotInstanceOf(Class<?> clazz)
Fails if the subject is an instance of the given class. 
 | 
void | 
isNotNull()
Fails if the subject is null. 
 | 
void | 
isNotSameInstanceAs(Object unexpected)
Fails if the subject is the same instance as the given object. 
 | 
void | 
isNull()
Fails if the subject is not null. 
 | 
void | 
isSameInstanceAs(Object expected)
Fails if the subject is not the same instance as the given object. 
 | 
String | 
toString()  | 
protected Subject(FailureMetadata metadata, @NullableDecl Object actual)
check().that(actual).public void isNull()
public void isNotNull()
public void isEqualTo(@NullableDecl
                      Object expected)
Objects.equal(java.lang.Object, java.lang.Object)
   Arrays.equals(long[], long[])
       overload
   Byte, Short, Character, Integer, or Long) and they are numerically equal when converted to Long.
 Note: This method does not test the Object.equals(java.lang.Object) implementation itself; it
 assumes that method is functioning correctly according to its contract. Testing an
 equals implementation requires a utility such as guava-testlib's EqualsTester.
 
In some cases, this method might not even call equals. It may instead perform other
 tests that will return the same result as long as equals is implemented according to
 the contract for its type.
public void isNotEqualTo(@NullableDecl
                         Object unexpected)
isEqualTo(java.lang.Object) method.public final void isSameInstanceAs(@NullableDecl
                                   Object expected)
public final void isNotSameInstanceAs(@NullableDecl
                                      Object unexpected)
public void isInstanceOf(Class<?> clazz)
public void isNotInstanceOf(Class<?> clazz)
public void isIn(Iterable<?> iterable)
public void isAnyOf(@NullableDecl
                    Object first,
                    @NullableDecl
                    Object second,
                    @NullableDecl
                    Object... rest)
public void isNotIn(Iterable<?> iterable)
public void isNoneOf(@NullableDecl
                     Object first,
                     @NullableDecl
                     Object second,
                     @NullableDecl
                     Object... rest)
@ForOverride protected String actualCustomStringRepresentation()
Subjects should override this with care.
By default, this returns String.ValueOf(getActualValue()).
protected final StandardSubjectBuilder check(String format, Object... args)
Derived subjects retain the FailureStrategy and messages of the current subject, and in some cases, they
 automatically supplement their failure message with information about the original subject.
 
For example, ThrowableSubject.hasMessageThat(), which returns a StringSubject,
 is implemented with check("getMessage()").that(actual.getMessage()).
 
The arguments to check describe how the new subject was derived from the old,
 formatted like a chained method call. This allows Truth to include that information in its
 failure messages. For example, assertThat(caught).hasCauseThat().hasMessageThat() will
 produce a failure message that includes the string "throwable.getCause().getMessage()," thanks
 to internal check calls that supplied "getCause()" and "getMessage()" as arguments.
 
If the method you're delegating to accepts parameters, you can pass check a format
 string. For example, MultimapSubject.valuesForKey(java.lang.Object) calls check("valuesForKey(%s)", key).
 
If you aren't really delegating to an instance method on the actual value -- maybe you're
 calling a static method, or you're calling a chain of several methods -- you can supply
 whatever string will be most useful to users. For example, if you're delegating to getOnlyElement(actual.colors()), you might call check("onlyColor()").
format - a template with %s placeholdersargs - the arguments to be inserted into those placeholdersprotected final StandardSubjectBuilder ignoreCheck()
check() but have already reported a failure. In
 such cases it may still be necessary to return a Subject instance even though any
 subsequent assertions are meaningless. For example, if a user chains together more ThrowableSubject.hasCauseThat() calls than the actual exception has causes, hasCauseThat
 returns ignoreCheck().that(... a dummy exception ...).protected final void failWithActual(String key, @NullableDecl Object value)
This is the simplest failure API. For more advanced needs, see the other overload and failWithoutActual.
 
Example usage: The check contains(String) calls failWithActual("expected to
 contain", string).
protected final void failWithActual(Fact first, Fact... rest)
If you have only one fact to report (and it's a key-value fact), prefer the simpler overload.
Example usage: The check isEmpty() calls failWithActual(simpleFact("expected
 to be empty")).
protected final void failWithoutActual(Fact first, Fact... rest)
Most failure messages should report the actual value, so most checks should call failWithActual instead. However, failWithoutActual is
 useful in some cases:
 
isNotEmpty() calls failWithoutActual(simpleFact("expected not to be empty").
   isNotWithin(...).of(...) calls failWithoutActual so that it can put the expected and actual values together, followed
       by the tolerance.
 Example usage: The check isEmpty() calls failWithActual(simpleFact("expected
 to be empty")).
@Deprecated public final boolean equals(@NullableDecl Object o)
Object.equals(Object) is not supported on Truth subjects. If you meant to
     test object equality between an expected and the actual value, use isEqualTo(Object) instead.equals in class ObjectUnsupportedOperationException - always@Deprecated public final int hashCode()
Object.hashCode() is not supported on Truth subjects.hashCode in class ObjectUnsupportedOperationException - alwaysCopyright © 2019. All rights reserved.