Replace com.google.common.base.Function with java.util.function.Function

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179249159
This commit is contained in:
guyben 2017-12-15 15:41:05 -08:00 committed by Ben McIlwain
parent d538dca2e0
commit 8157928a35
53 changed files with 424 additions and 399 deletions

View file

@ -18,7 +18,6 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EntityClasses.ALL_CLASSES;
import static google.registry.util.TypeUtils.hasAnnotation;
import static java.util.stream.Collectors.toSet;
import com.google.common.collect.Ordering;
import com.googlecode.objectify.Key;
@ -63,13 +62,13 @@ public class EntityClassesTest {
.stream()
.filter(hasAnnotation(Entity.class))
.map(Key::getKind)
.collect(toSet());
.collect(toImmutableSet());
Set<String> entitySubclassKinds =
ALL_CLASSES
.stream()
.filter(hasAnnotation(EntitySubclass.class))
.map(Key::getKind)
.collect(toSet());
.collect(toImmutableSet());
assertThat(baseEntityKinds).named("base entity kinds").containsAllIn(entitySubclassKinds);
}

View file

@ -251,6 +251,27 @@ public class ImmutableObjectTest {
assertThat(cloned.heterogenousMap).containsEntry("b", "");
}
/** Subclass of ImmutableObject with fields that are containers containing null values. */
public static class NullInContainersObject extends ImmutableObject {
Object[] array = new Object[] {null};
List<?> list = newArrayList((Object) null);
Set<?> set = newHashSet((Object) null);
Map<String, ?> map = newHashMap();
public NullInContainersObject() {
map.put("a", null);
}
}
@Test
public void testToDiffableFieldMap_withEmptyAndNulls() {
Map<String, Object> diffableFieldMap = new NullInContainersObject().toDiffableFieldMap();
assertThat((List<?>) diffableFieldMap.get("array")).containsExactly((Object) null);
assertThat((List<?>) diffableFieldMap.get("list")).containsExactly((Object) null);
assertThat((Set<?>) diffableFieldMap.get("set")).containsExactly((Object) null);
assertThat((Map<?, ?>) diffableFieldMap.get("map")).containsExactly("a", (Object) null);
}
/** Subclass of ImmutableObject with keys to other objects. */
public static class RootObject extends ImmutableObject {

View file

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

View file

@ -36,11 +36,9 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key;
import google.registry.model.ofy.Ofy;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
@ -585,7 +583,4 @@ public class ReservedListTest {
.contains(
"List 'blah' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
}
/** Gets the name of a reserved list. */
public static final Function<Key<ReservedList>, String> GET_NAME_FUNCTION = Key::getName;
}