Replace assertThat(stream.collect(toImmutableList())) with assertThat(stream)

In Truth8, we can do assertThat(stream) directly. It's less verbose and clearer
in most cases.

Note that for the "finishers" (e.g. "containsExactyElementsIn") - streams are
still not allowed. So when there is:
assertThat(stream.map(someTransformation).collect(toList()))
.containsExactlyElementsIn(expecteStream.map(someTransformation).collect(toList()));

I kept the .collect in the assertThat to preserve the symmetry with the
finisher.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179697587
This commit is contained in:
guyben 2017-12-20 09:48:20 -08:00 committed by Ben McIlwain
parent 50998136b1
commit 7d165a08cf
5 changed files with 14 additions and 48 deletions

View file

@ -16,6 +16,7 @@ package google.registry.model;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EntityClasses.ALL_CLASSES; import static google.registry.model.EntityClasses.ALL_CLASSES;
import static google.registry.util.TypeUtils.hasAnnotation; import static google.registry.util.TypeUtils.hasAnnotation;
@ -45,12 +46,7 @@ public class EntityClassesTest {
@Test @Test
public void testEntityClasses_baseEntitiesHaveUniqueKinds() throws Exception { public void testEntityClasses_baseEntitiesHaveUniqueKinds() throws Exception {
assertThat( assertThat(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind))
ALL_CLASSES
.stream()
.filter(hasAnnotation(Entity.class))
.map(Key::getKind)
.collect(toImmutableSet()))
.named("base entity kinds") .named("base entity kinds")
.containsNoDuplicates(); .containsNoDuplicates();
} }

View file

@ -14,9 +14,9 @@
package google.registry.model.registry; package google.registry.model.registry;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -141,7 +141,7 @@ public class RegistryTest extends EntityTestCase {
"mouse,FULLY_BLOCKED"); "mouse,FULLY_BLOCKED");
Registry r = Registry.get("tld") Registry r = Registry.get("tld")
.asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build(); .asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build();
assertThat(r.getReservedLists().stream().map(Key::getName).collect(toImmutableList())) assertThat(r.getReservedLists().stream().map(Key::getName))
.containsExactly("tld-reserved5", "tld-reserved6"); .containsExactly("tld-reserved5", "tld-reserved6");
r = Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of()).build(); r = Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of()).build();
assertThat(r.getReservedLists()).isEmpty(); assertThat(r.getReservedLists()).isEmpty();
@ -162,7 +162,7 @@ public class RegistryTest extends EntityTestCase {
.asBuilder() .asBuilder()
.setReservedListsByName(ImmutableSet.of("tld-reserved24", "tld-reserved25")) .setReservedListsByName(ImmutableSet.of("tld-reserved24", "tld-reserved25"))
.build(); .build();
assertThat(r.getReservedLists().stream().map(Key::getName).collect(toImmutableList())) assertThat(r.getReservedLists().stream().map(Key::getName))
.containsExactly("tld-reserved24", "tld-reserved25"); .containsExactly("tld-reserved24", "tld-reserved25");
r = Registry.get("tld").asBuilder().setReservedListsByName(ImmutableSet.of()).build(); r = Registry.get("tld").asBuilder().setReservedListsByName(ImmutableSet.of()).build();
assertThat(r.getReservedLists()).isEmpty(); assertThat(r.getReservedLists()).isEmpty();

View file

@ -18,11 +18,11 @@ import static com.google.appengine.tools.development.testing.LocalTaskQueueTestC
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getFirst; import static com.google.common.collect.Iterables.getFirst;
import static com.google.common.collect.Multisets.containsOccurrences; import static com.google.common.collect.Multisets.containsOccurrences;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_; import static com.google.common.truth.Truth.assert_;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff; import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
@ -195,12 +195,7 @@ public class TaskQueueHelper {
Function<TaskStateInfo, String> propertyGetter, Function<TaskStateInfo, String> propertyGetter,
String... expectedTaskProperties) throws Exception { String... expectedTaskProperties) throws Exception {
// Ordering is irrelevant but duplicates should be considered independently. // Ordering is irrelevant but duplicates should be considered independently.
assertThat( assertThat(getQueueInfo(queueName).getTaskInfo().stream().map(propertyGetter))
getQueueInfo(queueName)
.getTaskInfo()
.stream()
.map(propertyGetter)
.collect(toImmutableList()))
.containsExactly((Object[]) expectedTaskProperties); .containsExactly((Object[]) expectedTaskProperties);
} }

View file

@ -14,8 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
@ -283,12 +283,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--roid_suffix=Q9JYB4C", "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter", "--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"); "xn--q9jyb4c");
assertThat( assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName))
Registry.get("xn--q9jyb4c")
.getReservedLists()
.stream()
.map(Key::getName)
.collect(toImmutableList()))
.containsExactly("xn--q9jyb4c_abuse", "common_abuse"); .containsExactly("xn--q9jyb4c_abuse", "common_abuse");
} }

View file

@ -14,8 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
@ -281,12 +281,7 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
public void testSuccess_setReservedLists() throws Exception { public void testSuccess_setReservedLists() throws Exception {
runCommandForced("--reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat( assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName))
Registry.get("xn--q9jyb4c")
.getReservedLists()
.stream()
.map(Key::getName)
.collect(toImmutableList()))
.containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2");
} }
@ -296,12 +291,7 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
runCommandForced("--reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat( assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName))
Registry.get("xn--q9jyb4c")
.getReservedLists()
.stream()
.map(Key::getName)
.collect(toImmutableList()))
.containsExactly("xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r2");
} }
@ -311,12 +301,7 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1"))
.build()); .build());
runCommandForced("--add_reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--add_reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat( assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName))
Registry.get("xn--q9jyb4c")
.getReservedLists()
.stream()
.map(Key::getName)
.collect(toImmutableList()))
.containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2");
} }
@ -335,12 +320,7 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"); runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c");
assertThat( assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName))
Registry.get("xn--q9jyb4c")
.getReservedLists()
.stream()
.map(Key::getName)
.collect(toImmutableList()))
.containsExactly("xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r2");
} }