mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
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:
parent
de5f3e6177
commit
124d7375c3
11 changed files with 40 additions and 34 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<LogsSubject, TestLogHandler> {
|
|||
.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");
|
||||
|
|
|
@ -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<GetSchemaTreeComma
|
|||
while (matcher.find()) {
|
||||
count++;
|
||||
}
|
||||
assertThat(count).named(printableName + " occurences").isEqualTo(1);
|
||||
assertWithMessage(printableName + " occurences").that(count).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import google.registry.testing.SystemPropertyRule;
|
||||
|
@ -42,8 +43,8 @@ public class GtechToolTest {
|
|||
|
||||
@Test
|
||||
public void test_commandSet_namesAreSubsetOfRegistryToolCommands() {
|
||||
assertThat(Sets.difference(GtechTool.COMMAND_SET, RegistryTool.COMMAND_MAP.keySet()))
|
||||
.named("commands in GtechTool.COMMAND_SET but not in RegistryTool.COMMAND_MAP")
|
||||
assertWithMessage("commands in GtechTool.COMMAND_SET but not in RegistryTool.COMMAND_MAP")
|
||||
.that(Sets.difference(GtechTool.COMMAND_SET, RegistryTool.COMMAND_MAP.keySet()))
|
||||
.isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import static com.google.common.base.CaseFormat.LOWER_UNDERSCORE;
|
|||
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
|
||||
import static com.google.common.reflect.Reflection.getPackageName;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -59,14 +60,12 @@ public class RegistryToolTest {
|
|||
ImmutableSet<?> 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
|
||||
|
|
|
@ -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<KillAllCommit
|
|||
START_OF_TIME.plusDays(1),
|
||||
ImmutableMap.of(1, bucketTime, 2, bucketTime, 3, bucketTime)));
|
||||
for (Class<?> 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<KillAllCommit
|
|||
assertThat(otherStuff).isNotEmpty();
|
||||
runMapreduce();
|
||||
for (Class<?> 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))))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue