diff --git a/javatests/google/registry/flows/FlowRunnerTest.java b/javatests/google/registry/flows/FlowRunnerTest.java index ac0db7275..95696c8c3 100644 --- a/javatests/google/registry/flows/FlowRunnerTest.java +++ b/javatests/google/registry/flows/FlowRunnerTest.java @@ -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 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); } diff --git a/javatests/google/registry/flows/FlowTestCase.java b/javatests/google/registry/flows/FlowTestCase.java index 40a7497a7..692b0f4ae 100644 --- a/javatests/google/registry/flows/FlowTestCase.java +++ b/javatests/google/registry/flows/FlowTestCase.java @@ -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 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 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() diff --git a/javatests/google/registry/model/EntityClassesTest.java b/javatests/google/registry/model/EntityClassesTest.java index 423170946..d678a38dc 100644 --- a/javatests/google/registry/model/EntityClassesTest.java +++ b/javatests/google/registry/model/EntityClassesTest.java @@ -15,8 +15,9 @@ package google.registry.model; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.truth.StreamSubject.streams; import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth8.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.EntityClasses.ALL_CLASSES; import static google.registry.util.TypeUtils.hasAnnotation; @@ -46,8 +47,9 @@ public class EntityClassesTest { @Test public void testEntityClasses_baseEntitiesHaveUniqueKinds() { - assertThat(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind)) - .named("base entity kinds") + assertWithMessage("base entity kinds") + .about(streams()) + .that(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind)) .containsNoDuplicates(); } @@ -65,7 +67,7 @@ public class EntityClassesTest { .filter(hasAnnotation(EntitySubclass.class)) .map(Key::getKind) .collect(toImmutableSet()); - assertThat(baseEntityKinds).named("base entity kinds").containsAllIn(entitySubclassKinds); + assertWithMessage("base entity kinds").that(baseEntityKinds).containsAllIn(entitySubclassKinds); } @Test @@ -73,8 +75,8 @@ public class EntityClassesTest { for (Class clazz : ALL_CLASSES) { boolean isEntityXorEntitySubclass = clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class); - assertThat(isEntityXorEntitySubclass) - .named("class " + clazz.getSimpleName() + " is @Entity or @EntitySubclass") + assertWithMessage("class " + clazz.getSimpleName() + " is @Entity or @EntitySubclass") + .that(isEntityXorEntitySubclass) .isTrue(); } } diff --git a/javatests/google/registry/rde/DomainBaseToXjcConverterTest.java b/javatests/google/registry/rde/DomainBaseToXjcConverterTest.java index 9dd8102e5..660cbdedd 100644 --- a/javatests/google/registry/rde/DomainBaseToXjcConverterTest.java +++ b/javatests/google/registry/rde/DomainBaseToXjcConverterTest.java @@ -16,6 +16,7 @@ package google.registry.rde; import static com.google.common.io.BaseEncoding.base16; 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.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainBase; @@ -147,9 +148,9 @@ public class DomainBaseToXjcConverterTest { assertThat(bean.getRgpStatuses().stream().map(XjcRgpStatusType::getS)) .containsExactly(TRANSFER_PERIOD, RENEW_PERIOD); - assertThat(bean.getSecDNS()).named("secdns").isNotNull(); - assertThat(bean.getSecDNS().getDsDatas()).named("secdns dsdata").isNotNull(); - assertThat(bean.getSecDNS().getDsDatas()).named("secdns dsdata").hasSize(1); + assertWithMessage("secdns").that(bean.getSecDNS()).isNotNull(); + assertWithMessage("secdns dsdata").that(bean.getSecDNS().getDsDatas()).isNotNull(); + assertWithMessage("secdns dsdata").that(bean.getSecDNS().getDsDatas()).hasSize(1); XjcSecdnsDsDataType dsData = bean.getSecDNS().getDsDatas().get(0); assertThat(dsData.getAlg()).isEqualTo((short) 200); assertThat(dsData.getDigest()).isEqualTo(base16().decode("1234567890")); diff --git a/javatests/google/registry/testing/AbstractEppResourceSubject.java b/javatests/google/registry/testing/AbstractEppResourceSubject.java index 4e3fc8adb..def0e5bf8 100644 --- a/javatests/google/registry/testing/AbstractEppResourceSubject.java +++ b/javatests/google/registry/testing/AbstractEppResourceSubject.java @@ -159,7 +159,6 @@ abstract class AbstractEppResourceSubject .equals(ImmutableSet.copyOf(statusValues))) { check("getStatusValues()") .that(actual().getStatusValues()) - .named("status values for " + actualAsString()) .containsExactly((Object[]) statusValues); } return andChainer(); diff --git a/javatests/google/registry/testing/LogsSubject.java b/javatests/google/registry/testing/LogsSubject.java index 8e74f1ecc..9794159a7 100644 --- a/javatests/google/registry/testing/LogsSubject.java +++ b/javatests/google/registry/testing/LogsSubject.java @@ -15,7 +15,7 @@ package google.registry.testing; import static com.google.common.truth.Truth.assertAbout; -import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import com.google.common.collect.ImmutableList; import com.google.common.testing.TestLogHandler; @@ -76,8 +76,9 @@ public class LogsSubject extends Subject { .contains(message); for (String messageCandidate : messagesAtLevel) { if (messageCandidate.contains(message)) { - return new Which<>(assertThat(messageCandidate) - .named(String.format("log message at %s matching '%s'", level, message))); + return new Which<>( + assertWithMessage(String.format("log message at %s matching '%s'", level, message)) + .that(messageCandidate)); } } throw new AssertionError("Message check passed yet matching message not found"); diff --git a/javatests/google/registry/tools/GetSchemaTreeCommandTest.java b/javatests/google/registry/tools/GetSchemaTreeCommandTest.java index f04753029..299fed880 100644 --- a/javatests/google/registry/tools/GetSchemaTreeCommandTest.java +++ b/javatests/google/registry/tools/GetSchemaTreeCommandTest.java @@ -14,7 +14,7 @@ package google.registry.tools; -import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import com.google.re2j.Matcher; import com.google.re2j.Pattern; @@ -34,7 +34,7 @@ public class GetSchemaTreeCommandTest extends CommandTestCase commandMapClasses = ImmutableSet.copyOf(RegistryTool.COMMAND_MAP.values()); ImmutableSet classLoaderClasses = getAllCommandClasses(); // Not using plain old containsExactlyElementsIn() since it produces a huge unreadable blob. - assertThat( - Sets.difference(commandMapClasses, classLoaderClasses)) - .named("command classes in RegistryTool.COMMAND_MAP but not found by class loader") - .isEmpty(); - assertThat( - Sets.difference(classLoaderClasses, commandMapClasses)) - .named("command classes found by class loader but not in RegistryTool.COMMAND_MAP") - .isEmpty(); + assertWithMessage("command classes in RegistryTool.COMMAND_MAP but not found by class loader") + .that(Sets.difference(commandMapClasses, classLoaderClasses)) + .isEmpty(); + assertWithMessage("command classes found by class loader but not in RegistryTool.COMMAND_MAP") + .that(Sets.difference(classLoaderClasses, commandMapClasses)) + .isEmpty(); } @Test diff --git a/javatests/google/registry/tools/server/KillAllCommitLogsActionTest.java b/javatests/google/registry/tools/server/KillAllCommitLogsActionTest.java index 1c86efe7c..1c7dddc5a 100644 --- a/javatests/google/registry/tools/server/KillAllCommitLogsActionTest.java +++ b/javatests/google/registry/tools/server/KillAllCommitLogsActionTest.java @@ -19,6 +19,7 @@ import static com.google.common.base.Predicates.not; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.Iterables.filter; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newContactResource; @@ -79,7 +80,7 @@ public class KillAllCommitLogsActionTest extends MapreduceTestCase clazz : AFFECTED_TYPES) { - assertThat(ofy().load().type(clazz)).named("entities of type " + clazz).isNotEmpty(); + assertWithMessage("entities of type " + clazz).that(ofy().load().type(clazz)).isNotEmpty(); } ImmutableList otherStuff = Streams.stream(ofy().load()) @@ -88,7 +89,7 @@ public class KillAllCommitLogsActionTest extends MapreduceTestCase clazz : AFFECTED_TYPES) { - assertThat(ofy().load().type(clazz)).named("entities of type " + clazz).isEmpty(); + assertWithMessage("entities of type " + clazz).that(ofy().load().type(clazz)).isEmpty(); } // Filter out raw Entity objects created by the mapreduce. assertThat(filter(ofy().load(), not(instanceOf(Entity.class)))) diff --git a/javatests/google/registry/util/PosixTarHeaderSystemTest.java b/javatests/google/registry/util/PosixTarHeaderSystemTest.java index 7581fd788..0c3178338 100644 --- a/javatests/google/registry/util/PosixTarHeaderSystemTest.java +++ b/javatests/google/registry/util/PosixTarHeaderSystemTest.java @@ -136,8 +136,8 @@ public class PosixTarHeaderSystemTest { for (String name : files.keySet()) { File file = new File(folder.getRoot(), name); - assertThat(file.exists()).named(name + " exists").isTrue(); - assertThat(file.isFile()).named(name + " is a file").isTrue(); + assertWithMessage(name + " exists").that(file.exists()).isTrue(); + assertWithMessage(name + " is a file").that(file.isFile()).isTrue(); byte[] data = files.get(name).getBytes(UTF_8); assertThat(Files.asByteSource(file).read()).isEqualTo(data); }