Class Fact

    • Method Detail

      • fact

        public static Fact fact​(String key,
                                @Nullable Object value)
        Creates a fact with the given key and value, which will be printed in a format like "key: value." The value is converted to a string by calling String.valueOf on it.
      • simpleFact

        public static Fact simpleFact​(String key)
        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: ..."
      • toString

        public String toString()
        Returns a simple string representation for the fact. While this is used in the output of TruthFailureSubject, it's not used in normal failure messages, which automatically align facts horizontally and indent multiline values.
        toString in class Object