Switch from Guava Optionals to Java 8 Optionals

This was a surprisingly involved change. Some of the difficulties included
java.util.Optional purposely not being Serializable (so I had to move a
few Optionals in mapreduce classes to @Nullable) and having to add the Truth
Java8 extension library for assertion support.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171863777
This commit is contained in:
mcilwain 2017-10-11 13:09:26 -07:00 committed by jianglai
parent 184b2b56ac
commit c0f8da0c6e
581 changed files with 1325 additions and 932 deletions

View file

@ -28,7 +28,6 @@ java_library(
"//javatests/google/registry/testing",
"//javatests/google/registry/testing/mapreduce",
"//third_party/java/objectify:objectify-v4_1",
"//third_party/java/truth",
"@com_google_apis_google_api_services_bigquery",
"@com_google_apis_google_api_services_drive",
"@com_google_appengine_api_1_0_sdk//:testonly",
@ -39,6 +38,8 @@ java_library(
"@com_google_guava",
"@com_google_http_client",
"@com_google_re2j",
"@com_google_truth",
"@com_google_truth_extensions_truth_java8_extension",
"@javax_servlet_api",
"@joda_time",
"@junit",

View file

@ -18,6 +18,7 @@ import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.logging.Level.INFO;

View file

@ -15,6 +15,7 @@
package google.registry.export;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.export.CheckSnapshotAction.CHECK_SNAPSHOT_KINDS_TO_LOAD_PARAM;
import static google.registry.export.CheckSnapshotAction.CHECK_SNAPSHOT_NAME_PARAM;
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
@ -23,7 +24,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.request.Action.Method;
@ -36,6 +36,7 @@ import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.testing.InjectRule;
import google.registry.testing.TaskQueueHelper.TaskMatcher;
import java.util.Optional;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
@ -88,7 +89,7 @@ public class CheckSnapshotActionTest {
new DatastoreBackupInfo(
backupInfo.getName(),
backupInfo.getStartTime(),
Optional.<DateTime>absent(),
Optional.<DateTime>empty(),
backupInfo.getKinds(),
backupInfo.getGcsFilename());

View file

@ -16,6 +16,7 @@ package google.registry.export;
import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
@ -77,8 +78,8 @@ public class DatastoreBackupInfoTest {
assertThat(backup.getName()).isEqualTo("backup1");
assertThat(backup.getKinds()).containsExactly("one", "two", "three");
assertThat(backup.getStartTime()).isEqualTo(startTime);
assertThat(backup.getCompleteTime()).isAbsent();
assertThat(backup.getGcsFilename()).isAbsent();
assertThat(backup.getCompleteTime()).isEmpty();
assertThat(backup.getGcsFilename()).isEmpty();
assertThat(backup.getStatus()).isEqualTo(BackupStatus.PENDING);
clock.setTo(startTime.plusMinutes(1));

View file

@ -17,6 +17,7 @@ package google.registry.export;
import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View file

@ -19,6 +19,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.io.Resources.getResource;
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.export.ExportConstants.getBackupKinds;
import static google.registry.export.ExportConstants.getReportingKinds;
import static google.registry.util.ResourceUtils.readResourceUtf8;

View file

@ -17,6 +17,7 @@ package google.registry.export;
import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService;
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.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;

View file

@ -16,6 +16,7 @@ package google.registry.export;
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.export.ExportReservedTermsAction.EXPORT_MIME_TYPE;
import static google.registry.export.ExportReservedTermsAction.RESERVED_TERMS_FILENAME;
import static google.registry.testing.DatastoreHelper.createTld;

View file

@ -15,6 +15,7 @@
package google.registry.export;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.export.CheckSnapshotAction.CHECK_SNAPSHOT_KINDS_TO_LOAD_PARAM;
import static google.registry.export.CheckSnapshotAction.CHECK_SNAPSHOT_NAME_PARAM;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;

View file

@ -15,6 +15,7 @@
package google.registry.export;
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.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource;

View file

@ -16,6 +16,7 @@ package google.registry.export;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.export.LoadSnapshotAction.LOAD_SNAPSHOT_FILE_PARAM;
import static google.registry.export.LoadSnapshotAction.LOAD_SNAPSHOT_ID_PARAM;
import static google.registry.export.LoadSnapshotAction.LOAD_SNAPSHOT_KINDS_PARAM;

View file

@ -15,6 +15,7 @@
package google.registry.export;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.export.PublishDetailReportAction.DETAIL_REPORT_NAME_PARAM;
import static google.registry.export.PublishDetailReportAction.GCS_BUCKET_PARAM;
import static google.registry.export.PublishDetailReportAction.GCS_FOLDER_PREFIX_PARAM;

View file

@ -15,6 +15,7 @@
package google.registry.export;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.export.SyncGroupMembersAction.getGroupEmailAddressForContactType;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registrar.RegistrarContact.Type.ADMIN;

View file

@ -16,6 +16,7 @@ package google.registry.export;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.export.UpdateSnapshotViewAction.QUEUE;
import static google.registry.export.UpdateSnapshotViewAction.UPDATE_SNAPSHOT_DATASET_ID_PARAM;
import static google.registry.export.UpdateSnapshotViewAction.UPDATE_SNAPSHOT_KIND_PARAM;

View file

@ -14,10 +14,11 @@ java_library(
"//java/google/registry/model",
"//javatests/google/registry/testing",
"//third_party/java/objectify:objectify-v4_1",
"//third_party/java/truth",
"@com_google_apis_google_api_services_sheets",
"@com_google_code_findbugs_jsr305",
"@com_google_guava",
"@com_google_truth",
"@com_google_truth_extensions_truth_java8_extension",
"@javax_servlet_api",
"@joda_time",
"@junit",

View file

@ -16,6 +16,7 @@ package google.registry.export.sheet;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@ -23,10 +24,10 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeLockHandler;
import google.registry.testing.FakeResponse;
import java.util.Optional;
import javax.annotation.Nullable;
import org.joda.time.Duration;
import org.junit.Before;
@ -51,8 +52,8 @@ public class SyncRegistrarsSheetActionTest {
private SyncRegistrarsSheetAction action;
private void runAction(@Nullable String idConfig, @Nullable String idParam) {
action.idConfig = Optional.fromNullable(idConfig);
action.idParam = Optional.fromNullable(idParam);
action.idConfig = Optional.ofNullable(idConfig);
action.idParam = Optional.ofNullable(idParam);
action.run();
}

View file

@ -16,6 +16,7 @@ package google.registry.export.sheet;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl;
import static google.registry.config.RegistryConfig.getDefaultRegistrarWhoisServer;
import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET;