You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We'd already been using Truth a lot, so many of the examples here are just to use `assertThat(x).isTrue()` instead of `assertTrue(x)` (or similarly for "false" assertions). It's reasonable to debate whether that's an improvement. I will say that I've been surprised multiple times recently by `assertFalse` assertions, similar to how it's unfortunate to have `if (!some.very().long(EXPRESSION).afterWhich(youHaveForgottenAboutTheNegation)`, so I'm more a fan of using Truth there than I used to be.
The possibility of using Truth more came to my attention during cl/810738337 because of the `Optional` assertions in `GraphsTest` (and `ValueGraphTest`), where Truth provides clearer value.
I noticed that `containsExactlySanityCheck` was doing [the kind of thing we discourage](google/truth#268), in which it calls methods like `hasSize` and `contains` with the apparently intention of testing our implementations of `size()` and `contains(...)`, rather than verifying that some _earlier_ step had produced the right answer. I've migrated it to direct calls to `Collection` methods. Arguably the best approach would be to have one such test and then to use Truth's usual methods (with their superior failure messages) for "normal" tests.
Finally, in `TraverserTest`, I suspect that we were copying to an `ImmutableList` in order to be sure that we got a good failure message even in the absence of an implementation of `Traverser.toString()`. I verified that we do get a good message even without the copy because [Truth has our backs](https://github.com/google/truth/blob/22a4601c3c6b79b285740d37e82ec8dc56d2344d/core/src/main/java/com/google/common/truth/IterableSubject.java#L107-L119):
```
unexpected (1): b
---
expected : [a]
but was : [a, b]
```
RELNOTES=n/a
PiperOrigin-RevId: 813317064
0 commit comments