Class Fact
java.lang.Object
com.google.common.truth.Fact
- All Implemented Interfaces:
Serializable
A string key-value pair in a failure message, such as "expected: abc" or "but was: xyz."
Most Truth users will never interact with this type. It appears in the Truth API only as a
parameter to methods like Subject.failWithActual(Fact, Fact...)
, which are used only by
custom Subject
implementations.
If you are writing a custom Subject
, see our tips on writing failure messages.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Fact
Creates a fact with the given key and value, which will be printed in a format like "key: value."static Fact
simpleFact
(String key) Creates a fact with no value, which will be printed in the format "key" (with no colon or value).toString()
Returns a simple string representation for the fact.
-
Method Details
-
fact
-
simpleFact
Creates a fact with no value, which will be printed in the format "key" (with no colon or value).In most cases, prefer key-value facts, which give Truth more flexibility in how to format the fact for display.
simpleFact
is useful primarily for:- messages from no-arg assertions. For example,
isNotEmpty()
would generate the fact "expected not to be empty" - prose that is part of a larger message. For example,
contains()
sometimes displays facts like "expected to contain: ..." "but did not" "though it did contain: ..."
- messages from no-arg assertions. For example,
-
toString
-