mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 00:42:12 +02:00
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:
parent
d538dca2e0
commit
8157928a35
53 changed files with 424 additions and 399 deletions
|
@ -15,7 +15,6 @@
|
|||
package google.registry.backup;
|
||||
|
||||
import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService;
|
||||
import static com.google.common.base.Functions.constant;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.toMap;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
@ -247,7 +246,7 @@ public class RestoreCommitLogsActionTest {
|
|||
}
|
||||
|
||||
private CommitLogCheckpoint createCheckpoint(DateTime now) {
|
||||
return CommitLogCheckpoint.create(now, toMap(getBucketIds(), constant(now)));
|
||||
return CommitLogCheckpoint.create(now, toMap(getBucketIds(), x -> now));
|
||||
}
|
||||
|
||||
private Iterable<ImmutableObject> saveDiffFile(
|
||||
|
|
|
@ -16,23 +16,24 @@ package google.registry.flows;
|
|||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
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 google.registry.flows.EppXmlTransformer.marshal;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.BILLING_EVENT_ID_STRIPPER;
|
||||
import static google.registry.testing.DatastoreHelper.POLL_MESSAGE_ID_STRIPPER;
|
||||
import static google.registry.testing.DatastoreHelper.getPollMessages;
|
||||
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.flows.picker.FlowPicker;
|
||||
|
@ -58,8 +59,10 @@ import google.registry.tmch.TmchCertificateAuthority;
|
|||
import google.registry.tmch.TmchXmlSignature;
|
||||
import google.registry.util.TypeUtils.TypeInstantiator;
|
||||
import google.registry.xml.ValidationMode;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -217,6 +220,18 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
private static BillingEvent expandGracePeriod(GracePeriod gracePeriod) {
|
||||
assertThat(gracePeriod.hasBillingEvent())
|
||||
.named("Billing event is present for grace period: " + gracePeriod)
|
||||
.isTrue();
|
||||
return ofy()
|
||||
.load()
|
||||
.key(
|
||||
firstNonNull(
|
||||
gracePeriod.getOneTimeBillingEvent(), gracePeriod.getRecurringBillingEvent()))
|
||||
.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the actual grace periods and the corresponding billing events referenced from
|
||||
* their keys match the expected map of grace periods to billing events. For the expected map,
|
||||
|
@ -225,19 +240,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
public void assertGracePeriods(
|
||||
Iterable<GracePeriod> actual,
|
||||
ImmutableMap<GracePeriod, ? extends BillingEvent> expected) {
|
||||
Function<GracePeriod, BillingEvent> gracePeriodExpander =
|
||||
gracePeriod -> {
|
||||
assertThat(gracePeriod.hasBillingEvent())
|
||||
.named("Billing event is present for grace period: " + gracePeriod)
|
||||
.isTrue();
|
||||
return ofy()
|
||||
.load()
|
||||
.key(
|
||||
firstNonNull(
|
||||
gracePeriod.getOneTimeBillingEvent(), gracePeriod.getRecurringBillingEvent()))
|
||||
.now();
|
||||
};
|
||||
assertThat(canonicalizeGracePeriods(Maps.toMap(actual, gracePeriodExpander)))
|
||||
assertThat(canonicalizeGracePeriods(Maps.toMap(actual, FlowTestCase::expandGracePeriod)))
|
||||
.isEqualTo(canonicalizeGracePeriods(expected));
|
||||
}
|
||||
|
||||
|
@ -261,12 +264,11 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
|
|||
/** Assert that the list matches all the poll messages in the fake Datastore. */
|
||||
public void assertPollMessagesHelper(Iterable<PollMessage> pollMessages, PollMessage... expected)
|
||||
throws Exception {
|
||||
// To facilitate comparison, remove the ids.
|
||||
Function<PollMessage, PollMessage> idStripper =
|
||||
pollMessage -> pollMessage.asBuilder().setId(1L).build();
|
||||
// Ordering is irrelevant but duplicates should be considered independently.
|
||||
assertThat(FluentIterable.from(pollMessages).transform(idStripper))
|
||||
.containsExactlyElementsIn(FluentIterable.from(expected).transform(idStripper));
|
||||
assertThat(
|
||||
Streams.stream(pollMessages).map(POLL_MESSAGE_ID_STRIPPER).collect(toImmutableList()))
|
||||
.containsExactlyElementsIn(
|
||||
Arrays.stream(expected).map(POLL_MESSAGE_ID_STRIPPER).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
private EppOutput runFlowInternal(CommitMode commitMode, UserPrivileges userPrivileges)
|
||||
|
|
|
@ -37,8 +37,6 @@ import static google.registry.testing.JUnitBackports.expectThrows;
|
|||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
|
@ -72,6 +70,8 @@ import google.registry.model.reporting.HistoryEntry;
|
|||
import google.registry.model.transfer.TransferData;
|
||||
import google.registry.model.transfer.TransferResponse.DomainTransferResponse;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
|
@ -262,22 +262,21 @@ public class DomainTransferApproveFlowTest
|
|||
.build();
|
||||
assertBillingEventsForResource(
|
||||
domain,
|
||||
FluentIterable.from(expectedCancellationBillingEvents)
|
||||
.transform(
|
||||
(Function<BillingEvent.Cancellation.Builder, BillingEvent>)
|
||||
builder -> builder.setParent(historyEntryTransferApproved).build())
|
||||
.append(
|
||||
transferBillingEvent,
|
||||
getLosingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setRecurrenceEndTime(clock.nowUtc())
|
||||
.build(),
|
||||
getGainingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setEventTime(domain.getRegistrationExpirationTime())
|
||||
.setParent(historyEntryTransferApproved)
|
||||
.build())
|
||||
.toArray(BillingEvent.class));
|
||||
Stream.concat(
|
||||
Arrays.stream(expectedCancellationBillingEvents)
|
||||
.map(builder -> builder.setParent(historyEntryTransferApproved).build()),
|
||||
Stream.of(
|
||||
transferBillingEvent,
|
||||
getLosingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setRecurrenceEndTime(clock.nowUtc())
|
||||
.build(),
|
||||
getGainingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setEventTime(domain.getRegistrationExpirationTime())
|
||||
.setParent(historyEntryTransferApproved)
|
||||
.build()))
|
||||
.toArray(size -> new BillingEvent[size]));
|
||||
// There should be a grace period for the new transfer billing event.
|
||||
assertGracePeriods(
|
||||
domain.getGracePeriods(),
|
||||
|
@ -299,21 +298,20 @@ public class DomainTransferApproveFlowTest
|
|||
// for the gaining client that begins at the new expiration time.
|
||||
assertBillingEventsForResource(
|
||||
domain,
|
||||
FluentIterable.from(expectedCancellationBillingEvents)
|
||||
.transform(
|
||||
(Function<BillingEvent.Cancellation.Builder, BillingEvent>)
|
||||
builder -> builder.setParent(historyEntryTransferApproved).build())
|
||||
.append(
|
||||
getLosingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setRecurrenceEndTime(clock.nowUtc())
|
||||
.build(),
|
||||
getGainingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setEventTime(domain.getRegistrationExpirationTime())
|
||||
.setParent(historyEntryTransferApproved)
|
||||
.build())
|
||||
.toArray(BillingEvent.class));
|
||||
Stream.concat(
|
||||
Arrays.stream(expectedCancellationBillingEvents)
|
||||
.map(builder -> builder.setParent(historyEntryTransferApproved).build()),
|
||||
Stream.of(
|
||||
getLosingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setRecurrenceEndTime(clock.nowUtc())
|
||||
.build(),
|
||||
getGainingClientAutorenewEvent()
|
||||
.asBuilder()
|
||||
.setEventTime(domain.getRegistrationExpirationTime())
|
||||
.setParent(historyEntryTransferApproved)
|
||||
.build()))
|
||||
.toArray(size -> new BillingEvent[size]));
|
||||
// There should be no grace period.
|
||||
assertGracePeriods(domain.getGracePeriods(), ImmutableMap.of());
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -37,12 +38,10 @@ import static google.registry.testing.HostResourceSubject.assertAboutHosts;
|
|||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.joda.money.CurrencyUnit.EUR;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.appengine.repackaged.com.google.common.collect.Sets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -91,7 +90,6 @@ import google.registry.model.transfer.TransferResponse;
|
|||
import google.registry.model.transfer.TransferStatus;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -257,6 +255,11 @@ public class DomainTransferRequestFlowTest
|
|||
expectedExpirationTime, implicitTransferTime, Period.create(1, Unit.YEARS));
|
||||
}
|
||||
|
||||
/** Implements the missing Optional.stream function that is added in Java 9. */
|
||||
private static <T> Stream<T> optionalToStream(Optional<T> optional) {
|
||||
return optional.map(Stream::of).orElseGet(Stream::empty);
|
||||
}
|
||||
|
||||
private void assertHistoryEntriesContainBillingEventsAndGracePeriods(
|
||||
DateTime expectedExpirationTime,
|
||||
DateTime implicitTransferTime,
|
||||
|
@ -304,16 +307,16 @@ public class DomainTransferRequestFlowTest
|
|||
BillingEvent.Recurring gainingClientAutorenew =
|
||||
getGainingClientAutorenewEvent().asBuilder().setEventTime(expectedExpirationTime).build();
|
||||
// Construct extra billing events expected by the specific test.
|
||||
Set<BillingEvent> extraBillingEvents =
|
||||
ImmutableSet<BillingEvent> extraBillingEvents =
|
||||
Stream.of(extraExpectedBillingEvents)
|
||||
.map(
|
||||
(Function<BillingEvent.Cancellation.Builder, BillingEvent>)
|
||||
builder -> builder.setParent(historyEntryTransferRequest).build())
|
||||
.collect(toSet());
|
||||
.map(builder -> builder.setParent(historyEntryTransferRequest).build())
|
||||
.collect(toImmutableSet());
|
||||
// Assert that the billing events we constructed above actually exist in Datastore.
|
||||
Set<BillingEvent> expectedBillingEvents =
|
||||
Sets.newHashSet(losingClientAutorenew, gainingClientAutorenew);
|
||||
optionalTransferBillingEvent.ifPresent(expectedBillingEvents::add);
|
||||
ImmutableSet<BillingEvent> expectedBillingEvents =
|
||||
Stream.concat(
|
||||
Stream.of(losingClientAutorenew, gainingClientAutorenew),
|
||||
optionalToStream(optionalTransferBillingEvent))
|
||||
.collect(toImmutableSet());
|
||||
assertBillingEvents(Sets.union(expectedBillingEvents, extraBillingEvents));
|
||||
// Assert that the domain's TransferData server-approve billing events match the above.
|
||||
if (expectTransferBillingEvent) {
|
||||
|
@ -328,8 +331,10 @@ public class DomainTransferRequestFlowTest
|
|||
gainingClientAutorenew);
|
||||
// Assert that the full set of server-approve billing events is exactly the extra ones plus
|
||||
// the transfer billing event (if present) and the gaining client autorenew.
|
||||
Set<BillingEvent> expectedServeApproveBillingEvents = Sets.newHashSet(gainingClientAutorenew);
|
||||
optionalTransferBillingEvent.ifPresent(expectedServeApproveBillingEvents::add);
|
||||
ImmutableSet<BillingEvent> expectedServeApproveBillingEvents =
|
||||
Stream.concat(
|
||||
Stream.of(gainingClientAutorenew), optionalToStream(optionalTransferBillingEvent))
|
||||
.collect(toImmutableSet());
|
||||
assertBillingEventsEqual(
|
||||
Iterables.filter(
|
||||
ofy()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ import static com.google.common.truth.Truth8.assertThat;
|
|||
import static google.registry.request.auth.Auth.AUTH_INTERNAL_ONLY;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
|
|
@ -43,10 +43,8 @@ import static java.util.Arrays.asList;
|
|||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -103,6 +101,7 @@ import google.registry.tmch.LordnTask;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -669,8 +668,9 @@ public class DatastoreHelper {
|
|||
/** Assert that the actual billing events match the expected ones, ignoring IDs and order. */
|
||||
public static void assertBillingEventsEqual(
|
||||
Iterable<BillingEvent> actual, Iterable<BillingEvent> expected) {
|
||||
assertThat(Iterables.transform(actual, BILLING_EVENT_ID_STRIPPER))
|
||||
.containsExactlyElementsIn(Iterables.transform(expected, BILLING_EVENT_ID_STRIPPER));
|
||||
assertThat(Streams.stream(actual).map(BILLING_EVENT_ID_STRIPPER).collect(toImmutableList()))
|
||||
.containsExactlyElementsIn(
|
||||
Streams.stream(expected).map(BILLING_EVENT_ID_STRIPPER).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
/** Assert that the expected billing events are exactly the ones found in the fake Datastore. */
|
||||
|
@ -688,9 +688,12 @@ public class DatastoreHelper {
|
|||
*/
|
||||
public static void assertBillingEventsForResource(
|
||||
EppResource resource, BillingEvent... expected) throws Exception {
|
||||
assertThat(FluentIterable.from(getBillingEvents(resource)).transform(BILLING_EVENT_ID_STRIPPER))
|
||||
assertThat(
|
||||
Streams.stream(getBillingEvents(resource))
|
||||
.map(BILLING_EVENT_ID_STRIPPER)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactlyElementsIn(
|
||||
FluentIterable.from(expected).transform(BILLING_EVENT_ID_STRIPPER));
|
||||
Arrays.stream(expected).map(BILLING_EVENT_ID_STRIPPER).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
/** Assert that there are no billing events. */
|
||||
|
@ -711,15 +714,20 @@ public class DatastoreHelper {
|
|||
/** Assert that the actual poll messages match the expected ones, ignoring IDs and order. */
|
||||
public static void assertPollMessagesEqual(
|
||||
Iterable<PollMessage> actual, Iterable<PollMessage> expected) {
|
||||
assertThat(Iterables.transform(actual, POLL_MESSAGE_ID_STRIPPER))
|
||||
.containsExactlyElementsIn(Iterables.transform(expected, POLL_MESSAGE_ID_STRIPPER));
|
||||
assertThat(Streams.stream(actual).map(POLL_MESSAGE_ID_STRIPPER).collect(toImmutableList()))
|
||||
.containsExactlyElementsIn(
|
||||
Streams.stream(expected).map(POLL_MESSAGE_ID_STRIPPER).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
public static void assertPollMessagesForResource(EppResource resource, PollMessage... expected)
|
||||
throws Exception {
|
||||
assertThat(FluentIterable.from(getPollMessages(resource)).transform(POLL_MESSAGE_ID_STRIPPER))
|
||||
assertThat(
|
||||
getPollMessages(resource)
|
||||
.stream()
|
||||
.map(POLL_MESSAGE_ID_STRIPPER)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactlyElementsIn(
|
||||
FluentIterable.from(expected).transform(POLL_MESSAGE_ID_STRIPPER));
|
||||
Arrays.stream(expected).map(POLL_MESSAGE_ID_STRIPPER).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
/** Helper to effectively erase the poll message ID to facilitate comparison. */
|
||||
|
|
|
@ -18,8 +18,8 @@ import static com.google.appengine.tools.development.testing.LocalTaskQueueTestC
|
|||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Predicates.in;
|
||||
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.transform;
|
||||
import static com.google.common.collect.Multisets.containsOccurrences;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
|
@ -32,7 +32,6 @@ import com.google.appengine.api.taskqueue.dev.QueueStateInfo;
|
|||
import com.google.appengine.api.taskqueue.dev.QueueStateInfo.HeaderWrapper;
|
||||
import com.google.appengine.api.taskqueue.dev.QueueStateInfo.TaskStateInfo;
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
|
@ -55,6 +54,7 @@ import java.util.LinkedList;
|
|||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
|
@ -196,7 +196,12 @@ public class TaskQueueHelper {
|
|||
Function<TaskStateInfo, String> propertyGetter,
|
||||
String... expectedTaskProperties) throws Exception {
|
||||
// Ordering is irrelevant but duplicates should be considered independently.
|
||||
assertThat(transform(getQueueInfo(queueName).getTaskInfo(), propertyGetter))
|
||||
assertThat(
|
||||
getQueueInfo(queueName)
|
||||
.getTaskInfo()
|
||||
.stream()
|
||||
.map(propertyGetter)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactly((Object[]) expectedTaskProperties);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
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 google.registry.model.registry.label.ReservedListTest.GET_NAME_FUNCTION;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
|
@ -31,6 +30,7 @@ import static org.joda.time.Duration.standardMinutes;
|
|||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Range;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -283,7 +283,12 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
|||
"--roid_suffix=Q9JYB4C",
|
||||
"--dns_writers=VoidDnsWriter",
|
||||
"xn--q9jyb4c");
|
||||
assertThat(transform(Registry.get("xn--q9jyb4c").getReservedLists(), GET_NAME_FUNCTION))
|
||||
assertThat(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.getReservedLists()
|
||||
.stream()
|
||||
.map(Key::getName)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactly("xn--q9jyb4c_abuse", "common_abuse");
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
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 google.registry.model.registry.label.ReservedListTest.GET_NAME_FUNCTION;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
|
@ -282,7 +281,12 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
|||
public void testSuccess_setReservedLists() throws Exception {
|
||||
runCommandForced("--reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c");
|
||||
|
||||
assertThat(transform(Registry.get("xn--q9jyb4c").getReservedLists(), GET_NAME_FUNCTION))
|
||||
assertThat(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.getReservedLists()
|
||||
.stream()
|
||||
.map(Key::getName)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2");
|
||||
}
|
||||
|
||||
|
@ -292,7 +296,12 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
|||
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
|
||||
.build());
|
||||
runCommandForced("--reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c");
|
||||
assertThat(transform(Registry.get("xn--q9jyb4c").getReservedLists(), GET_NAME_FUNCTION))
|
||||
assertThat(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.getReservedLists()
|
||||
.stream()
|
||||
.map(Key::getName)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactly("xn--q9jyb4c_r2");
|
||||
}
|
||||
|
||||
|
@ -302,7 +311,12 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
|||
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1"))
|
||||
.build());
|
||||
runCommandForced("--add_reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c");
|
||||
assertThat(transform(Registry.get("xn--q9jyb4c").getReservedLists(), GET_NAME_FUNCTION))
|
||||
assertThat(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.getReservedLists()
|
||||
.stream()
|
||||
.map(Key::getName)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2");
|
||||
}
|
||||
|
||||
|
@ -321,7 +335,12 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
|||
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
|
||||
.build());
|
||||
runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c");
|
||||
assertThat(transform(Registry.get("xn--q9jyb4c").getReservedLists(), GET_NAME_FUNCTION))
|
||||
assertThat(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.getReservedLists()
|
||||
.stream()
|
||||
.map(Key::getName)
|
||||
.collect(toImmutableList()))
|
||||
.containsExactly("xn--q9jyb4c_r2");
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -36,6 +34,7 @@ import com.google.common.testing.NullPointerTester;
|
|||
import com.google.re2j.Pattern;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
@ -241,7 +240,7 @@ public class FormFieldTest {
|
|||
assertThat(
|
||||
FormField.named("lol")
|
||||
.transform(Object.class, Integer::parseInt)
|
||||
.transform(String.class, Functions.toStringFunction())
|
||||
.transform(String.class, Object::toString)
|
||||
.build()
|
||||
.convert("123"))
|
||||
.hasValue("123");
|
||||
|
@ -484,11 +483,12 @@ public class FormFieldTest {
|
|||
|
||||
@Test
|
||||
public void testNullness() {
|
||||
NullPointerTester tester = new NullPointerTester()
|
||||
.setDefault(Class.class, Object.class)
|
||||
.setDefault(Function.class, Functions.identity())
|
||||
.setDefault(Pattern.class, Pattern.compile("."))
|
||||
.setDefault(String.class, "hello.com");
|
||||
NullPointerTester tester =
|
||||
new NullPointerTester()
|
||||
.setDefault(Class.class, Object.class)
|
||||
.setDefault(Function.class, x -> x)
|
||||
.setDefault(Pattern.class, Pattern.compile("."))
|
||||
.setDefault(String.class, "hello.com");
|
||||
tester.testAllPublicStaticMethods(FormField.class);
|
||||
tester.testAllPublicInstanceMethods(FormField.named("lol"));
|
||||
tester.testAllPublicInstanceMethods(FormField.named("lol").build());
|
||||
|
|
|
@ -17,12 +17,11 @@ package google.registry.util;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.testing.NullPointerTester;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import java.util.function.Function;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -39,7 +38,7 @@ public class ConcurrentTest {
|
|||
|
||||
@Test
|
||||
public void testTransform_emptyList_returnsEmptyList() throws Exception {
|
||||
assertThat(Concurrent.transform(ImmutableList.of(), Functions.identity())).isEmpty();
|
||||
assertThat(Concurrent.transform(ImmutableList.of(), x -> x)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -66,8 +65,7 @@ public class ConcurrentTest {
|
|||
|
||||
@Test
|
||||
public void testNullness() throws Exception {
|
||||
NullPointerTester tester = new NullPointerTester()
|
||||
.setDefault(Function.class, Functions.identity());
|
||||
NullPointerTester tester = new NullPointerTester().setDefault(Function.class, x -> x);
|
||||
tester.testAllPublicStaticMethods(Concurrent.class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue