Assertions made inside the implementation of another Truth assertion should use check, not assertThat.
Before:
class MyProtoSubject extends Subject {
...
public void hasFoo(Foo expected) {
assertThat(actual.foo()).isEqualTo(expected);
}
}
After:
class MyProtoSubject extends Subject {
...
public void hasFoo(Foo expected) {
check("foo()").that(actual.foo()).isEqualTo(expected);
}
}
Benefits of check include:
myProto.foo(), and it includes the full value of myProto for reference.assertWithMessage, that message, which is lost in the assertThat version, is shown by the check version.check makes it possible to test the assertion with ExpectFailure and to use Expect or assume. assertThat, by contrast, overrides any user-specified failure behavior.