Migrate from assertThat(foo).named("foo") to assertWithMessage("foo").that(foo).

(The exact change is slightly different in some cases, like when using custom subjects, but it's still a migration from named(...) to assertWithMessage(...).)

Or, in one case, migrate from calling this.named(...) to overriding actualCustomStringRepresentation().

named(...) is being removed.

This CL may modify the failure messages produced, but all the old information will still be present.

Change-Id: I02219e5c502193e02e2c0abbf8eb9d73c406b0ee
This commit is contained in:
Chris Povirk
2019-05-16 13:00:08 -04:00
parent c01ea3f85b
commit eda92e08c3
4 changed files with 20 additions and 14 deletions

View File

@@ -73,7 +73,11 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
}
protected static FakeEmailSenderSubject assertThat(FakeEmailSender sender) {
return assertAbout(FakeEmailSenderSubject::new).that(sender);
return assertAbout(fakeEmailSenders()).that(sender);
}
protected static Subject.Factory<FakeEmailSenderSubject, FakeEmailSender> fakeEmailSenders() {
return FakeEmailSenderSubject::new;
}
protected void setEmailStrategy(TestAccount account, EmailStrategy strategy) throws Exception {
@@ -142,9 +146,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
: header));
}
// Return a named subject that displays a human-readable table of
// recipients.
return named(recipientMapToString(recipients, users::emailToName));
return this;
}
private static String recipientMapToString(
@@ -205,8 +207,9 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
if (recipients.get(type).contains(email) != expected) {
failWithoutActual(
fact(
expected ? "should notify" : "shouldn't notify",
type + ": " + users.emailToName(email)));
expected ? "expected to notify" : "expected not to notify",
type + ": " + users.emailToName(email)),
fact("but notified", recipientMapToString(recipients, users::emailToName)));
}
if (expected) {
accountedFor.add(email);