Refactor lenientFormat usages for improved failure messages This commit modernizes failure messages in Truth by replacing several usages of `com.google.common.base.Strings.lenientFormat` with direct `String.format` calls or by restructuring messages to use `Fact` objects, aiming for more helpful and structured output for you. Key changes include: - In `Subject.java`, deprecated failure methods (`failWithBadResults`, `failWithCustomSubject`, `failWithoutSubject`) were updated to use `Fact` objects or direct string concatenation, removing `lenientFormat`. - In `LiteProtoSubject.java`, failure messages for `isEqualTo` (class mismatch), `isNotEqualTo`, `isEqualToDefaultInstance`, and `isNotEqualToDefaultInstance` were refactored to use `Fact`-based constructions. - In various helper methods within `IterableSubject.java`, `MapSubject.java`, `MultimapSubject.java` (partial), `SubjectUtils.java`, and `LazyMessage.java`, `lenientFormat` was replaced with `String.format` for consistency in message and component formatting. - Usages of `lenientFormat` in `Correspondence.java` and parts of `MultimapSubject.java` that were for internal descriptive strings, not directly for user-facing Fact messages, were left unchanged based on your feedback. - Test files were not modified as the existing core tests passed after these changes. The goal of this refactoring was to improve the clarity and utility of failure messages by adopting more structured `Fact` instances where appropriate and ensuring consistent string formatting.
Truth makes your test assertions and failure messages more readable. Similar to AssertJ, it natively supports many JDK and Guava types, and it is extensible to others.
Truth is owned and maintained by the Guava team. It is used in the majority of the tests in Google’s own codebase.
Read more at the main website.