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 or check(), but it's always a migration from named(...) to [assert]WithMessage(...).)

named(...) is being removed.

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

More information:
  []

Tested:
    TAP --sample for global presubmit queue
    []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=245762634
This commit is contained in:
cpovirk 2019-04-29 09:38:14 -07:00 committed by jianglai
parent de5f3e6177
commit 124d7375c3
11 changed files with 40 additions and 34 deletions

View file

@ -15,6 +15,7 @@
package google.registry.flows;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.TestDataHelper.loadFile;
import static google.registry.testing.TestLogHandlerUtils.findFirstLogMessageByPrefix;
@ -170,7 +171,7 @@ public class FlowRunnerTest extends ShardableTestCase {
flowRunner.run(eppMetricBuilder);
String logMessage = findFirstLogMessageByPrefix(handler, "EPP Command\n\t");
List<String> lines = Splitter.on("\n\t").splitToList(logMessage);
assertThat(lines.size()).named("number of lines in log message").isAtLeast(9);
assertWithMessage("number of lines in log message").that(lines.size()).isAtLeast(9);
String xml = Joiner.on('\n').join(lines.subList(3, lines.size() - 4));
assertThat(xml).isEqualTo(sanitizedDomainCreateXml);
}

View file

@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Sets.difference;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.model.eppcommon.EppXmlTransformer.marshal;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.POLL_MESSAGE_ID_STRIPPER;
@ -161,8 +162,8 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
assertThat(flowClass).isAssignableTo(TransactionalFlow.class);
} else {
// There's no "isNotAssignableTo" in Truth.
assertThat(TransactionalFlow.class.isAssignableFrom(flowClass))
.named(flowClass.getSimpleName() + " implements TransactionalFlow")
assertWithMessage(flowClass.getSimpleName() + " implements TransactionalFlow")
.that(TransactionalFlow.class.isAssignableFrom(flowClass))
.isFalse();
}
}
@ -193,8 +194,8 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
}
private static BillingEvent expandGracePeriod(GracePeriod gracePeriod) {
assertThat(gracePeriod.hasBillingEvent())
.named("Billing event is present for grace period: " + gracePeriod)
assertWithMessage("Billing event is present for grace period: " + gracePeriod)
.that(gracePeriod.hasBillingEvent())
.isTrue();
return ofy()
.load()