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 41622a4de0
commit 8c78719cfa
11 changed files with 40 additions and 34 deletions

View file

@ -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);
}
}
}

View file

@ -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();
}
}

View file

@ -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

View file

@ -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))))