From 9edb43f3e44134713d5c609439f745f17aaee0e7 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Mon, 20 Jul 2020 20:45:52 -0400 Subject: [PATCH] Upgrade command test classes from JUnit 4 to JUnit 5 (#700) * Convert first batch of command tests to JUnit 5 * Upgrade rest of command tests to JUnit 5 * Migrate the last few test classes --- .../writer/dnsupdate/DnsUpdateWriterTest.java | 4 +- .../export/ExportPremiumTermsActionTest.java | 10 +- .../export/sheet/SheetSynchronizerTest.java | 24 +-- .../sheet/SyncRegistrarsSheetActionTest.java | 6 +- .../registry/flows/EppControllerTest.java | 4 +- .../billing/CopyDetailReportsActionTest.java | 6 +- .../registry/request/RequestHandlerTest.java | 4 +- .../AuthenticatedRegistrarAccessorTest.java | 20 +- .../auth/RequestAuthenticatorTest.java | 10 +- .../tools/AckPollMessagesCommandTest.java | 24 +-- .../tools/AppEngineConnectionTest.java | 34 ++-- .../google/registry/tools/AuthModuleTest.java | 46 ++--- .../tools/CheckDomainClaimsCommandTest.java | 24 +-- .../tools/CheckDomainCommandTest.java | 26 +-- .../registry/tools/CommandTestCase.java | 59 +++--- .../registry/tools/CompareDbBackupsTest.java | 29 ++- .../tools/CountDomainsCommandTest.java | 16 +- .../tools/CreateAnchorTenantCommandTest.java | 35 ++-- .../registry/tools/CreateCdnsTldTest.java | 19 +- .../tools/CreateContactCommandTest.java | 22 +-- .../tools/CreateDomainCommandTest.java | 54 +++--- .../registry/tools/CreateHostCommandTest.java | 12 +- ...ateOrUpdatePremiumListCommandTestCase.java | 8 +- ...teOrUpdateReservedListCommandTestCase.java | 22 +-- .../tools/CreatePremiumListCommandTest.java | 28 +-- .../tools/CreateRegistrarCommandTest.java | 176 ++++++++--------- .../CreateRegistrarGroupsCommandTest.java | 15 +- .../tools/CreateReservedListCommandTest.java | 60 +++--- .../registry/tools/CreateTldCommandTest.java | 104 +++++----- .../registry/tools/CurlCommandTest.java | 33 ++-- .../DeleteAllocationTokensCommandTest.java | 35 ++-- .../tools/DeleteDomainCommandTest.java | 24 +-- .../registry/tools/DeleteHostCommandTest.java | 22 +-- .../tools/DeletePremiumListCommandTest.java | 10 +- .../tools/DeleteReservedListCommandTest.java | 18 +- .../registry/tools/DeleteTldCommandTest.java | 20 +- .../registry/tools/DomainLockUtilsTest.java | 82 ++++---- .../tools/DumpGoldenSchemaCommandTest.java | 22 +-- .../EncryptEscrowDepositCommandTest.java | 38 ++-- .../registry/tools/EntityWrapperTest.java | 18 +- .../registry/tools/EppToolCommandTest.java | 8 +- .../tools/EppToolCommandTestCase.java | 12 +- .../registry/tools/EppToolVerifier.java | 10 +- .../registry/tools/ExecuteEppCommandTest.java | 26 +-- .../GenerateAllocationTokensCommandTest.java | 62 +++--- .../tools/GenerateDnsReportCommandTest.java | 36 ++-- .../GenerateEscrowDepositCommandTest.java | 43 +++-- .../tools/GenerateSqlSchemaCommandTest.java | 58 +++--- .../tools/GetAllocationTokenCommandTest.java | 14 +- .../tools/GetClaimsListCommandTest.java | 12 +- .../registry/tools/GetContactCommandTest.java | 26 +-- .../registry/tools/GetDomainCommandTest.java | 30 +-- .../tools/GetHistoryEntriesCommandTest.java | 14 +- .../registry/tools/GetHostCommandTest.java | 30 +-- .../tools/GetOperationStatusCommandTest.java | 20 +- .../tools/GetRegistrarCommandTest.java | 14 +- .../tools/GetResourceByKeyCommandTest.java | 50 ++--- .../tools/GetSchemaTreeCommandTest.java | 7 +- .../registry/tools/GetTldCommandTest.java | 15 +- .../registry/tools/GhostrydeCommandTest.java | 66 ++++--- .../tools/ImportDatastoreCommandTest.java | 28 +-- .../registry/tools/LevelDbFileBuilder.java | 1 + .../tools/LevelDbFileBuilderTest.java | 32 ++-- .../registry/tools/LevelDbLogReaderTest.java | 10 +- .../google/registry/tools/LevelDbUtil.java | 2 +- .../tools/ListCursorsCommandTest.java | 22 +-- .../ListDatastoreOperationsCommandTest.java | 23 +-- .../tools/ListDomainsCommandTest.java | 11 +- .../registry/tools/ListHostsCommandTest.java | 2 +- .../tools/ListObjectsCommandTestCase.java | 28 ++- .../tools/ListPremiumListsCommandTest.java | 3 +- .../tools/ListRegistrarsCommandTest.java | 3 +- .../tools/ListReservedListsCommandTest.java | 3 +- .../registry/tools/ListTldsCommandTest.java | 2 +- .../registry/tools/LoadTestCommandTest.java | 85 ++++----- .../registry/tools/LockDomainCommandTest.java | 24 +-- .../registry/tools/MutatingCommandTest.java | 63 +++---- .../tools/MutatingEppToolCommandTest.java | 6 +- .../tools/NonMutatingEppToolCommandTest.java | 9 +- .../registry/tools/RecordAccumulatorTest.java | 23 +-- .../tools/RegistrarContactCommandTest.java | 52 ++--- .../tools/RegistryToolEnvironmentTest.java | 58 +++--- .../tools/RenewDomainCommandTest.java | 28 +-- .../tools/RequestFactoryModuleTest.java | 32 ++-- .../tools/ResaveEntitiesCommandTest.java | 6 +- .../ResaveEnvironmentEntitiesCommandTest.java | 8 +- .../tools/ResaveEppResourcesCommandTest.java | 6 +- .../tools/SetNumInstancesCommandTest.java | 46 +++-- .../registry/tools/SetupOteCommandTest.java | 50 ++--- .../registry/tools/ShellCommandTest.java | 104 +++++----- .../UniformRapidSuspensionCommandTest.java | 40 ++-- .../tools/UnlockDomainCommandTest.java | 24 +-- .../tools/UnrenewDomainCommandTest.java | 22 +-- .../UpdateAllocationTokensCommandTest.java | 31 ++- .../tools/UpdateCursorsCommandTest.java | 28 +-- .../tools/UpdateDomainCommandTest.java | 66 +++---- .../tools/UpdatePremiumListCommandTest.java | 18 +- .../tools/UpdateRegistrarCommandTest.java | 142 +++++++------- .../tools/UpdateReservedListCommandTest.java | 28 +-- .../tools/UpdateServerLocksCommandTest.java | 32 ++-- .../registry/tools/UpdateTldCommandTest.java | 178 +++++++++--------- .../tools/UploadClaimsListCommandTest.java | 30 +-- .../ValidateEscrowDepositCommandTest.java | 14 +- .../ValidateLoginCredentialsCommandTest.java | 34 ++-- .../registry/tools/VerifyOteCommandTest.java | 20 +- .../BackfillRegistryLocksCommandTest.java | 26 ++- .../registrar/RegistryLockPostActionTest.java | 12 +- .../handler/FrontendMetricsHandlerTest.java | 4 +- 108 files changed, 1626 insertions(+), 1669 deletions(-) diff --git a/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java b/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java index 40892593b..909164cd2 100644 --- a/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java +++ b/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java @@ -29,7 +29,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.google.common.base.VerifyException; @@ -141,7 +141,7 @@ public class DnsUpdateWriterTest { writer.publishDomain("example1.tld"); writer.publishDomain("example2.tld"); - verifyZeroInteractions(mockResolver); + verifyNoInteractions(mockResolver); } @Test diff --git a/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java b/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java index e9915d038..33ef34da5 100644 --- a/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java +++ b/core/src/test/java/google/registry/export/ExportPremiumTermsActionTest.java @@ -31,8 +31,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; @@ -132,7 +132,7 @@ public class ExportPremiumTermsActionTest { persistResource(Registry.get("tld").asBuilder().setPremiumList(null).build()); runAction("tld"); - verifyZeroInteractions(driveConnection); + verifyNoInteractions(driveConnection); verify(response).setStatus(SC_OK); verify(response).setPayload("No premium lists configured"); verify(response).setContentType(PLAIN_TEXT_UTF_8); @@ -144,7 +144,7 @@ public class ExportPremiumTermsActionTest { persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build()); runAction("tld"); - verifyZeroInteractions(driveConnection); + verifyNoInteractions(driveConnection); verify(response).setStatus(SC_OK); verify(response) .setPayload("Skipping export because no Drive folder is associated with this TLD"); @@ -157,7 +157,7 @@ public class ExportPremiumTermsActionTest { deleteTld("tld"); assertThrows(RuntimeException.class, () -> runAction("tld")); - verifyZeroInteractions(driveConnection); + verifyNoInteractions(driveConnection); verify(response).setStatus(SC_INTERNAL_SERVER_ERROR); verify(response).setPayload(anyString()); verify(response).setContentType(PLAIN_TEXT_UTF_8); @@ -169,7 +169,7 @@ public class ExportPremiumTermsActionTest { deletePremiumList(new PremiumList.Builder().setName("pl-name").build()); assertThrows(RuntimeException.class, () -> runAction("tld")); - verifyZeroInteractions(driveConnection); + verifyNoInteractions(driveConnection); verify(response).setStatus(SC_INTERNAL_SERVER_ERROR); verify(response).setPayload("Could not load premium list for " + "tld"); verify(response).setContentType(PLAIN_TEXT_UTF_8); diff --git a/core/src/test/java/google/registry/export/sheet/SheetSynchronizerTest.java b/core/src/test/java/google/registry/export/sheet/SheetSynchronizerTest.java index f24ca8af6..08639ee63 100644 --- a/core/src/test/java/google/registry/export/sheet/SheetSynchronizerTest.java +++ b/core/src/test/java/google/registry/export/sheet/SheetSynchronizerTest.java @@ -18,7 +18,7 @@ import static com.google.common.collect.Lists.newArrayList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.google.api.services.sheets.v4.Sheets; @@ -91,9 +91,9 @@ public class SheetSynchronizerTest { public void testSynchronize_dataAndSheetEmpty_doNothing() throws Exception { existingSheet.add(createRow("a", "b")); sheetSynchronizer.synchronize("aSheetId", data); - verifyZeroInteractions(appendReq); - verifyZeroInteractions(clearReq); - verifyZeroInteractions(updateReq); + verifyNoInteractions(appendReq); + verifyNoInteractions(clearReq); + verifyNoInteractions(updateReq); } @Test @@ -103,8 +103,8 @@ public class SheetSynchronizerTest { data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2")); sheetSynchronizer.synchronize("aSheetId", data); - verifyZeroInteractions(appendReq); - verifyZeroInteractions(clearReq); + verifyNoInteractions(appendReq); + verifyNoInteractions(clearReq); BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest(); List> expectedVals = newArrayList(); @@ -122,8 +122,8 @@ public class SheetSynchronizerTest { data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2", "d", "val3")); sheetSynchronizer.synchronize("aSheetId", data); - verifyZeroInteractions(appendReq); - verifyZeroInteractions(clearReq); + verifyNoInteractions(appendReq); + verifyNoInteractions(clearReq); BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest(); List> expectedVals = newArrayList(); @@ -141,8 +141,8 @@ public class SheetSynchronizerTest { data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "paddedVal", "d", "val3")); sheetSynchronizer.synchronize("aSheetId", data); - verifyZeroInteractions(appendReq); - verifyZeroInteractions(clearReq); + verifyNoInteractions(appendReq); + verifyNoInteractions(clearReq); BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest(); List> expectedVals = newArrayList(); @@ -162,7 +162,7 @@ public class SheetSynchronizerTest { ImmutableMap.of("a", "val3", "b", "val4")); sheetSynchronizer.synchronize("aSheetId", data); - verifyZeroInteractions(clearReq); + verifyNoInteractions(clearReq); BatchUpdateValuesRequest expectedRequest = new BatchUpdateValuesRequest(); List> updatedVals = newArrayList(); @@ -188,6 +188,6 @@ public class SheetSynchronizerTest { sheetSynchronizer.synchronize("aSheetId", data); verify(values).clear("aSheetId", "Registrars!3:4", new ClearValuesRequest()); - verifyZeroInteractions(updateReq); + verifyNoInteractions(updateReq); } } diff --git a/core/src/test/java/google/registry/export/sheet/SyncRegistrarsSheetActionTest.java b/core/src/test/java/google/registry/export/sheet/SyncRegistrarsSheetActionTest.java index 1d96ee524..bfc13b8e1 100644 --- a/core/src/test/java/google/registry/export/sheet/SyncRegistrarsSheetActionTest.java +++ b/core/src/test/java/google/registry/export/sheet/SyncRegistrarsSheetActionTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import google.registry.testing.AppEngineRule; @@ -67,7 +67,7 @@ public class SyncRegistrarsSheetActionTest { public void testPost_withoutParamsOrSystemProperty_dropsTask() { runAction(null, null); assertThat(response.getPayload()).startsWith("MISSINGNO"); - verifyZeroInteractions(syncRegistrarsSheet); + verifyNoInteractions(syncRegistrarsSheet); } @Test @@ -104,6 +104,6 @@ public class SyncRegistrarsSheetActionTest { action.lockHandler = new FakeLockHandler(false); runAction(null, "foobar"); assertThat(response.getPayload()).startsWith("LOCKED"); - verifyZeroInteractions(syncRegistrarsSheet); + verifyNoInteractions(syncRegistrarsSheet); } } diff --git a/core/src/test/java/google/registry/flows/EppControllerTest.java b/core/src/test/java/google/registry/flows/EppControllerTest.java index dae08eafb..72e3d2e51 100644 --- a/core/src/test/java/google/registry/flows/EppControllerTest.java +++ b/core/src/test/java/google/registry/flows/EppControllerTest.java @@ -26,7 +26,7 @@ import static java.util.logging.Level.INFO; import static java.util.logging.Level.SEVERE; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.google.common.base.Splitter; @@ -163,7 +163,7 @@ public class EppControllerTest { true, true, domainCreateXml.getBytes(UTF_8)); - verifyZeroInteractions(eppMetrics); + verifyNoInteractions(eppMetrics); } @Test diff --git a/core/src/test/java/google/registry/reporting/billing/CopyDetailReportsActionTest.java b/core/src/test/java/google/registry/reporting/billing/CopyDetailReportsActionTest.java index d05e8c868..9f4e6e8a1 100644 --- a/core/src/test/java/google/registry/reporting/billing/CopyDetailReportsActionTest.java +++ b/core/src/test/java/google/registry/reporting/billing/CopyDetailReportsActionTest.java @@ -25,8 +25,8 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import com.google.appengine.tools.cloudstorage.GcsFilename; @@ -208,7 +208,7 @@ public class CopyDetailReportsActionTest { new GcsFilename("test-bucket", "results/invoice_details_2017-10_notExistent_hello.csv"), "hola,mundo\n3,4".getBytes(UTF_8)); action.run(); - verifyZeroInteractions(driveConnection); + verifyNoInteractions(driveConnection); } @Test @@ -220,6 +220,6 @@ public class CopyDetailReportsActionTest { "test-bucket", "results/invoice_details_2017-10_TheRegistrar_hello.csv"), "hola,mundo\n3,4".getBytes(UTF_8)); action.run(); - verifyZeroInteractions(driveConnection); + verifyNoInteractions(driveConnection); } } diff --git a/core/src/test/java/google/registry/request/RequestHandlerTest.java b/core/src/test/java/google/registry/request/RequestHandlerTest.java index f9d989f22..1f7c59b72 100644 --- a/core/src/test/java/google/registry/request/RequestHandlerTest.java +++ b/core/src/test/java/google/registry/request/RequestHandlerTest.java @@ -24,8 +24,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import com.google.appengine.api.users.User; @@ -245,7 +245,7 @@ public final class RequestHandlerTest { handler.handleRequest(req, rsp); - verifyZeroInteractions(rsp); + verifyNoInteractions(rsp); verify(bumblebeeTask).run(); assertMetric("/bumblebee", GET, AuthLevel.NONE, true); } diff --git a/core/src/test/java/google/registry/request/auth/AuthenticatedRegistrarAccessorTest.java b/core/src/test/java/google/registry/request/auth/AuthenticatedRegistrarAccessorTest.java index 4c1ba8325..705e65b8c 100644 --- a/core/src/test/java/google/registry/request/auth/AuthenticatedRegistrarAccessorTest.java +++ b/core/src/test/java/google/registry/request/auth/AuthenticatedRegistrarAccessorTest.java @@ -24,7 +24,7 @@ import static google.registry.testing.LogsSubject.assertAboutLogs; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.google.appengine.api.users.User; @@ -150,7 +150,7 @@ public class AuthenticatedRegistrarAccessorTest { NO_USER, ADMIN_CLIENT_ID, SUPPORT_GROUP, lazyGroupsConnection); assertThat(registrarAccessor.getAllClientIdWithRoles()).isEmpty(); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** @@ -182,7 +182,7 @@ public class AuthenticatedRegistrarAccessorTest { ADMIN_CLIENT_ID, ADMIN, ADMIN_CLIENT_ID, OWNER); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** @@ -228,7 +228,7 @@ public class AuthenticatedRegistrarAccessorTest { assertThat(registrarAccessor.getAllClientIdWithRoles()) .containsExactly(CLIENT_ID_WITH_CONTACT, OWNER); // Make sure we didn't instantiate the lazyGroupsConnection - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** Support group check throws - continue anyway. */ @@ -287,7 +287,7 @@ public class AuthenticatedRegistrarAccessorTest { CLIENT_ID_WITH_CONTACT, NO_USER, " doesn't have access to registrar TheRegistrar"); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** Succeed loading registrar if user has access to it. */ @@ -307,7 +307,7 @@ public class AuthenticatedRegistrarAccessorTest { CLIENT_ID_WITH_CONTACT, GAE_ADMIN, "admin admin@gmail.com has [OWNER, ADMIN] access to registrar TheRegistrar"); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** Succeed loading registrar for admin even if they aren't on the approved contacts list. */ @@ -317,7 +317,7 @@ public class AuthenticatedRegistrarAccessorTest { REAL_CLIENT_ID_WITHOUT_CONTACT, GAE_ADMIN, "admin admin@gmail.com has [ADMIN] access to registrar NewRegistrar."); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } @Test @@ -332,7 +332,7 @@ public class AuthenticatedRegistrarAccessorTest { REAL_CLIENT_ID_WITHOUT_CONTACT, GAE_ADMIN, "admin admin@gmail.com has [OWNER, ADMIN] access to registrar NewRegistrar."); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** Succeed loading non-REAL registrar for admin. */ @@ -342,7 +342,7 @@ public class AuthenticatedRegistrarAccessorTest { OTE_CLIENT_ID_WITHOUT_CONTACT, GAE_ADMIN, "admin admin@gmail.com has [OWNER, ADMIN] access to registrar OteRegistrar."); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } /** Fail loading registrar even if admin, if registrar doesn't exist. */ @@ -352,7 +352,7 @@ public class AuthenticatedRegistrarAccessorTest { "BadClientId", GAE_ADMIN, "Registrar BadClientId does not exist"); - verifyZeroInteractions(lazyGroupsConnection); + verifyNoInteractions(lazyGroupsConnection); } private void expectGetRegistrarSuccess(String clientId, AuthResult authResult, String message) diff --git a/core/src/test/java/google/registry/request/auth/RequestAuthenticatorTest.java b/core/src/test/java/google/registry/request/auth/RequestAuthenticatorTest.java index 8535f03ea..42b108599 100644 --- a/core/src/test/java/google/registry/request/auth/RequestAuthenticatorTest.java +++ b/core/src/test/java/google/registry/request/auth/RequestAuthenticatorTest.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.google.appengine.api.users.User; @@ -138,7 +138,7 @@ public class RequestAuthenticatorTest { public void testNoAuthNeeded_noneFound() { Optional authResult = runTest(mockUserService, AUTH_NONE); - verifyZeroInteractions(mockUserService); + verifyNoInteractions(mockUserService); assertThat(authResult).isPresent(); assertThat(authResult.get().authLevel()).isEqualTo(AuthLevel.NONE); } @@ -149,7 +149,7 @@ public class RequestAuthenticatorTest { Optional authResult = runTest(mockUserService, AUTH_NONE); - verifyZeroInteractions(mockUserService); + verifyNoInteractions(mockUserService); assertThat(authResult).isPresent(); assertThat(authResult.get().authLevel()).isEqualTo(AuthLevel.APP); assertThat(authResult.get().userAuthInfo()).isEmpty(); @@ -159,7 +159,7 @@ public class RequestAuthenticatorTest { public void testInternalAuth_notInvokedInternally() { Optional authResult = runTest(mockUserService, AUTH_INTERNAL_OR_ADMIN); - verifyZeroInteractions(mockUserService); + verifyNoInteractions(mockUserService); assertThat(authResult).isEmpty(); } @@ -169,7 +169,7 @@ public class RequestAuthenticatorTest { Optional authResult = runTest(mockUserService, AUTH_INTERNAL_OR_ADMIN); - verifyZeroInteractions(mockUserService); + verifyNoInteractions(mockUserService); assertThat(authResult).isPresent(); assertThat(authResult.get().authLevel()).isEqualTo(AuthLevel.APP); assertThat(authResult.get().userAuthInfo()).isEmpty(); diff --git a/core/src/test/java/google/registry/tools/AckPollMessagesCommandTest.java b/core/src/test/java/google/registry/tools/AckPollMessagesCommandTest.java index fe858465b..62d63f556 100644 --- a/core/src/test/java/google/registry/tools/AckPollMessagesCommandTest.java +++ b/core/src/test/java/google/registry/tools/AckPollMessagesCommandTest.java @@ -31,25 +31,25 @@ import google.registry.persistence.VKey; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link AckPollMessagesCommand}. */ public class AckPollMessagesCommandTest extends CommandTestCase { private FakeClock clock = new FakeClock(DateTime.parse("2015-02-04T08:16:32.064Z")); - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); - @Before - public final void before() { + @BeforeEach + final void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); command.clock = clock; } @Test - public void testSuccess_doesntDeletePollMessagesInFuture() throws Exception { + void testSuccess_doesntDeletePollMessagesInFuture() throws Exception { VKey pm1 = persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar").createVKey(); VKey pm2 = @@ -70,7 +70,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase pm1 = persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar").createVKey(); VKey pm2 = @@ -98,7 +98,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase pm1 = persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "foobar").createVKey(); VKey pm2 = @@ -125,7 +125,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase pm1 = persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "food is good") .createVKey(); @@ -143,7 +143,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase pm1 = persistPollMessage(316L, DateTime.parse("2014-01-01T22:33:44Z"), "food is good") .createVKey(); @@ -167,7 +167,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase dataStore = mock(DataStore.class); + @Mock DataStore dataStore; class FakeDataStoreFactory extends AbstractDataStoreFactory { @Override @@ -89,14 +91,15 @@ public class AuthModuleTest { } } - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { fakeCredential.setRefreshToken(REFRESH_TOKEN); when(dataStore.get(CLIENT_ID + " scope1")).thenReturn(new StoredCredential(fakeCredential)); } @Test - public void test_clientScopeQualifier() { + @MockitoSettings(strictness = Strictness.LENIENT) + void test_clientScopeQualifier() { String simpleQualifier = AuthModule.provideClientScopeQualifier("client-id", ImmutableList.of("foo", "bar")); @@ -161,7 +164,7 @@ public class AuthModuleTest { } @Test - public void test_provideLocalCredentialJson() { + void test_provideLocalCredentialJson() { String credentialJson = AuthModule.provideLocalCredentialJson(this::getSecrets, this::getCredential, null); Map jsonMap = @@ -173,8 +176,9 @@ public class AuthModuleTest { } @Test - public void test_provideExternalCredentialJson() throws Exception { - File credentialFile = folder.newFile("credential.json"); + @MockitoSettings(strictness = Strictness.LENIENT) + void test_provideExternalCredentialJson() throws Exception { + File credentialFile = folder.resolve("credential.json").toFile(); Files.write(credentialFile.toPath(), "{some_field: some_value}".getBytes(UTF_8)); String credentialJson = AuthModule.provideLocalCredentialJson( @@ -183,7 +187,7 @@ public class AuthModuleTest { } @Test - public void test_provideCredential() { + void test_provideCredential() { Credential cred = getCredential(); assertThat(cred.getAccessToken()).isEqualTo(fakeCredential.getAccessToken()); assertThat(cred.getRefreshToken()).isEqualTo(fakeCredential.getRefreshToken()); @@ -192,7 +196,7 @@ public class AuthModuleTest { } @Test - public void test_provideCredential_notStored() throws IOException { + void test_provideCredential_notStored() throws IOException { when(dataStore.get(CLIENT_ID + " scope1")).thenReturn(null); assertThrows(AuthModule.LoginRequiredException.class, this::getCredential); } diff --git a/core/src/test/java/google/registry/tools/CheckDomainClaimsCommandTest.java b/core/src/test/java/google/registry/tools/CheckDomainClaimsCommandTest.java index 4a6c733e7..098c2678e 100644 --- a/core/src/test/java/google/registry/tools/CheckDomainClaimsCommandTest.java +++ b/core/src/test/java/google/registry/tools/CheckDomainClaimsCommandTest.java @@ -19,26 +19,26 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import google.registry.model.registrar.Registrar.Type; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link CheckDomainClaimsCommand}. */ -public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase { +class CheckDomainClaimsCommandTest extends EppToolCommandTestCase { - @Before - public void before() { + @BeforeEach + void beforeEach() { persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L); command.registryAdminClientId = "adminreg"; } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "example.tld"); eppVerifier.expectDryRun().verifySent("domain_check_claims.xml"); } @Test - public void testSuccess_multipleTlds() throws Exception { + void testSuccess_multipleTlds() throws Exception { runCommand("--client=NewRegistrar", "example.tld", "example.tld2"); eppVerifier .expectDryRun() @@ -47,7 +47,7 @@ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase runCommand("--client=NewRegistrar")); } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "example.tld")); diff --git a/core/src/test/java/google/registry/tools/CheckDomainCommandTest.java b/core/src/test/java/google/registry/tools/CheckDomainCommandTest.java index 8854bd325..986fe67da 100644 --- a/core/src/test/java/google/registry/tools/CheckDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/CheckDomainCommandTest.java @@ -19,26 +19,26 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import google.registry.model.registrar.Registrar.Type; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link CheckDomainCommand}. */ -public class CheckDomainCommandTest extends EppToolCommandTestCase { +class CheckDomainCommandTest extends EppToolCommandTestCase { - @Before - public void before() { + @BeforeEach + void beforeEach() { persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L); command.registryAdminClientId = "adminreg"; } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "example.tld"); eppVerifier.expectDryRun().verifySent("domain_check_fee.xml"); } @Test - public void testSuccess_multipleTlds() throws Exception { + void testSuccess_multipleTlds() throws Exception { runCommand("--client=NewRegistrar", "example.tld", "example.tld2"); eppVerifier .expectDryRun() @@ -47,7 +47,7 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase runCommand("--client=NewRegistrar")); } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "example.tld")); diff --git a/core/src/test/java/google/registry/tools/CommandTestCase.java b/core/src/test/java/google/registry/tools/CommandTestCase.java index f09ec760a..4de24b55f 100644 --- a/core/src/test/java/google/registry/tools/CommandTestCase.java +++ b/core/src/test/java/google/registry/tools/CommandTestCase.java @@ -35,27 +35,25 @@ import google.registry.testing.FakeClock; import google.registry.testing.SystemPropertyRule; import google.registry.tools.params.ParameterFactory; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.nio.file.Path; import java.util.List; import java.util.concurrent.locks.ReentrantLock; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.junit.jupiter.MockitoExtension; /** * Base class for all command tests. * * @param the command type */ -@RunWith(JUnit4.class) +@ExtendWith(MockitoExtension.class) public abstract class CommandTestCase { // Lock for stdout/stderr. Note that this is static: since we're dealing with globals, we need @@ -70,7 +68,7 @@ public abstract class CommandTestCase { public final FakeClock fakeClock = new FakeClock(); - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() @@ -78,15 +76,12 @@ public abstract class CommandTestCase { .withTaskQueue() .build(); - @Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); + @RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); - @Rule public final MockitoRule mocks = MockitoJUnit.rule(); + @TempDir public Path tmpDir; - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); - - @Before - public final void beforeCommandTestCase() throws Exception { + @BeforeEach + public final void beforeEachCommandTestCase() throws Exception { // Ensure the UNITTEST environment has been set before constructing a new command instance. RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule); command = newCommandInstance(); @@ -101,8 +96,8 @@ public abstract class CommandTestCase { System.setErr(new PrintStream(new OutputSplitter(System.err, stderr))); } - @After - public final void afterCommandTestCase() throws Exception { + @AfterEach + public final void afterEachCommandTestCase() { System.setOut(oldStdout); System.setErr(oldStderr); streamsLock.unlock(); @@ -144,10 +139,10 @@ public abstract class CommandTestCase { } /** Writes the data to a named temporary file and then returns a path to the file. */ - String writeToNamedTmpFile(String filename, byte[] data) throws IOException { - File tmpFile = tmpDir.newFile(filename); - Files.write(data, tmpFile); - return tmpFile.getPath(); + private String writeToNamedTmpFile(String filename, byte[] data) throws IOException { + Path tmpFile = tmpDir.resolve(filename); + Files.write(data, tmpFile.toFile()); + return tmpFile.toString(); } /** Writes the data to a named temporary file and then returns a path to the file. */ @@ -199,7 +194,7 @@ public abstract class CommandTestCase { .isEqualTo(stripImmutableObjectHashCodes(expected).trim()); } - protected void assertStdoutIs(String expected) { + void assertStdoutIs(String expected) { assertThat(getStdoutAsString()).isEqualTo(expected); } @@ -210,34 +205,34 @@ public abstract class CommandTestCase { } } - protected void assertInStderr(String... expected) { + void assertInStderr(String... expected) { String stderror = new String(stderr.toByteArray(), UTF_8); for (String line : expected) { assertThat(stderror).contains(line); } } - protected void assertNotInStdout(String expected) { + void assertNotInStdout(String expected) { assertThat(getStdoutAsString()).doesNotContain(expected); } - protected void assertNotInStderr(String expected) { + void assertNotInStderr(String expected) { assertThat(getStderrAsString()).doesNotContain(expected); } - protected String getStdoutAsString() { + String getStdoutAsString() { return new String(stdout.toByteArray(), UTF_8); } - protected String getStderrAsString() { + String getStderrAsString() { return new String(stderr.toByteArray(), UTF_8); } - protected List getStdoutAsLines() { + List getStdoutAsLines() { return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(getStdoutAsString()); } - protected String stripImmutableObjectHashCodes(String string) { + private String stripImmutableObjectHashCodes(String string) { return string.replaceAll("\\(@\\d+\\)", "(@)"); } diff --git a/core/src/test/java/google/registry/tools/CompareDbBackupsTest.java b/core/src/test/java/google/registry/tools/CompareDbBackupsTest.java index 1a7a4aa83..083d56149 100644 --- a/core/src/test/java/google/registry/tools/CompareDbBackupsTest.java +++ b/core/src/test/java/google/registry/tools/CompareDbBackupsTest.java @@ -22,14 +22,15 @@ import google.registry.testing.DatastoreEntityExtension; import google.registry.tools.EntityWrapper.Property; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.IOException; import java.io.PrintStream; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; public class CompareDbBackupsTest { @@ -39,26 +40,24 @@ public class CompareDbBackupsTest { private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); private PrintStream orgStdout; - public final TemporaryFolder tempFs = new TemporaryFolder(); + @TempDir Path tmpDir; @RegisterExtension public DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension(); @BeforeEach - public void before() throws IOException { + void beforeEach() { orgStdout = System.out; System.setOut(new PrintStream(stdout)); - tempFs.create(); } @AfterEach - public void after() { + void afterEach() { System.setOut(orgStdout); - tempFs.delete(); } @Test - public void testLoadBackup() { + void testLoadBackup() { URL backupRootFolder = Resources.getResource("google/registry/tools/datastore-export"); CompareDbBackups.main(new String[] {backupRootFolder.getPath(), backupRootFolder.getPath()}); String output = new String(stdout.toByteArray(), UTF_8); @@ -66,11 +65,12 @@ public class CompareDbBackupsTest { } @Test - public void testCompareBackups() throws Exception { - + void testCompareBackups() throws Exception { // Create two directories corresponding to data dumps. - File dump1 = tempFs.newFolder("dump1"); - LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(dump1, "output-data1")); + Path dump1 = Files.createDirectory(tmpDir.resolve("dump1")); + Path dump2 = Files.createDirectory(tmpDir.resolve("dump2")); + + LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(dump1.toFile(), "output-data1")); builder.addEntity( EntityWrapper.from( BASE_ID, @@ -87,8 +87,7 @@ public class CompareDbBackupsTest { .getEntity()); builder.build(); - File dump2 = tempFs.newFolder("dump2"); - builder = new LevelDbFileBuilder(new File(dump2, "output-data2")); + builder = new LevelDbFileBuilder(new File(dump2.toFile(), "output-data2")); builder.addEntity( EntityWrapper.from( BASE_ID + 1, @@ -105,7 +104,7 @@ public class CompareDbBackupsTest { .getEntity()); builder.build(); - CompareDbBackups.main(new String[] {dump1.getCanonicalPath(), dump2.getCanonicalPath()}); + CompareDbBackups.main(new String[] {dump1.toString(), dump2.toString()}); String output = new String(stdout.toByteArray(), UTF_8); assertThat(output) .containsMatch("(?s)1 records were removed.*eeny.*1 records were added.*blutzy"); diff --git a/core/src/test/java/google/registry/tools/CountDomainsCommandTest.java b/core/src/test/java/google/registry/tools/CountDomainsCommandTest.java index f8c4f86e2..570c62620 100644 --- a/core/src/test/java/google/registry/tools/CountDomainsCommandTest.java +++ b/core/src/test/java/google/registry/tools/CountDomainsCommandTest.java @@ -23,26 +23,26 @@ import google.registry.model.ofy.Ofy; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link CountDomainsCommand}. */ public class CountDomainsCommandTest extends CommandTestCase { protected FakeClock clock = new FakeClock(DateTime.now(UTC)); - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); - @Before - public final void before() { + @BeforeEach + final void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); command.clock = clock; createTlds("foo", "bar", "baz", "qux"); } @Test - public void testSuccess_singleTld() throws Exception { + void testSuccess_singleTld() throws Exception { for (int i = 0; i < 51; i++) { persistActiveDomain(String.format("test-%d.foo", i)); if (i > 31) { @@ -54,7 +54,7 @@ public class CountDomainsCommandTest extends CommandTestCase { +class CreateAnchorTenantCommandTest extends EppToolCommandTestCase { - @Before - public void initCommand() { + @BeforeEach + void beforeEach() { command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz"); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommandForced("--client=NewRegistrar", "--superuser", "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant.xml"); } @Test - public void testSuccess_suppliedPassword() throws Exception { + void testSuccess_suppliedPassword() throws Exception { runCommandForced("--client=NewRegistrar", "--superuser", "--password=foo", "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant_password.xml"); } @Test - public void testSuccess_multipleWordReason() throws Exception { + void testSuccess_multipleWordReason() throws Exception { runCommandForced("--client=NewRegistrar", "--superuser", "--reason=\"anchor tenant test\"", "--contact=jd1234", "--domain_name=example.tld"); eppVerifier @@ -58,21 +57,21 @@ public class CreateAnchorTenantCommandTest } @Test - public void testSuccess_noReason() throws Exception { + void testSuccess_noReason() throws Exception { runCommandForced("--client=NewRegistrar", "--superuser", "--contact=jd1234", "--domain_name=example.tld"); eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant_no_reason.xml"); } @Test - public void testSuccess_feeStandard() throws Exception { + void testSuccess_feeStandard() throws Exception { runCommandForced("--client=NewRegistrar", "--superuser", "--fee", "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); eppVerifier.expectSuperuser().verifySent("domain_create_anchor_tenant_fee_standard.xml"); } @Test - public void testSuccess_feePremium() throws Exception { + void testSuccess_feePremium() throws Exception { createTld("tld"); persistResource( Registry.get("tld") @@ -85,7 +84,7 @@ public class CreateAnchorTenantCommandTest } @Test - public void testFailure_mainParameter() { + void testFailure_mainParameter() { assertThrows( ParameterException.class, () -> @@ -100,7 +99,7 @@ public class CreateAnchorTenantCommandTest } @Test - public void testFailure_missingClientId() { + void testFailure_missingClientId() { assertThrows( ParameterException.class, () -> @@ -112,7 +111,7 @@ public class CreateAnchorTenantCommandTest } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> @@ -126,7 +125,7 @@ public class CreateAnchorTenantCommandTest } @Test - public void testFailure_missingDomainName() { + void testFailure_missingDomainName() { assertThrows( ParameterException.class, () -> @@ -139,7 +138,7 @@ public class CreateAnchorTenantCommandTest } @Test - public void testFailure_missingContact() { + void testFailure_missingContact() { assertThrows( ParameterException.class, () -> @@ -152,7 +151,7 @@ public class CreateAnchorTenantCommandTest } @Test - public void testFailure_notAsSuperuser() { + void testFailure_notAsSuperuser() { assertThrows( IllegalArgumentException.class, () -> diff --git a/core/src/test/java/google/registry/tools/CreateCdnsTldTest.java b/core/src/test/java/google/registry/tools/CreateCdnsTldTest.java index 478d8454a..ed3f68c96 100644 --- a/core/src/test/java/google/registry/tools/CreateCdnsTldTest.java +++ b/core/src/test/java/google/registry/tools/CreateCdnsTldTest.java @@ -22,14 +22,16 @@ import static org.mockito.Mockito.when; import com.google.api.services.dns.Dns; import com.google.api.services.dns.model.ManagedZone; import com.google.api.services.dns.model.ManagedZoneDnsSecConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link CreateCdnsTld}. */ -public class CreateCdnsTldTest extends CommandTestCase { +class CreateCdnsTldTest extends CommandTestCase { @Mock Dns dnsService; @Mock Dns.ManagedZones managedZones; @@ -37,8 +39,8 @@ public class CreateCdnsTldTest extends CommandTestCase { @Captor ArgumentCaptor projectId; @Captor ArgumentCaptor requestBody; - @Before - public void setUp() throws Exception { + @BeforeEach + void beforeEach() throws Exception { when(dnsService.managedZones()).thenReturn(managedZones); when(managedZones.create(projectId.capture(), requestBody.capture())).thenReturn(request); command = new CreateCdnsTld(); @@ -57,7 +59,7 @@ public class CreateCdnsTldTest extends CommandTestCase { } @Test - public void testBasicFunctionality() throws Exception { + void testBasicFunctionality() throws Exception { runCommand("--dns_name=tld.", "--name=tld", "--description=test run", "--force"); verify(request).execute(); assertThat(projectId.getValue()).isEqualTo("test-project"); @@ -66,14 +68,15 @@ public class CreateCdnsTldTest extends CommandTestCase { } @Test - public void testNameDefault() throws Exception { + void testNameDefault() throws Exception { runCommand("--dns_name=tld.", "--description=test run", "--force"); ManagedZone zone = requestBody.getValue(); assertThat(zone).isEqualTo(createZone("cloud-dns-registry-test", "test run", "tld.", "tld.")); } @Test - public void testSandboxTldRestrictions() throws Exception { + @MockitoSettings(strictness = Strictness.LENIENT) + void testSandboxTldRestrictions() throws Exception { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/CreateContactCommandTest.java b/core/src/test/java/google/registry/tools/CreateContactCommandTest.java index b6527477a..04c23d618 100644 --- a/core/src/test/java/google/registry/tools/CreateContactCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateContactCommandTest.java @@ -18,19 +18,19 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import google.registry.testing.DeterministicStringGenerator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link CreateContactCommand}. */ -public class CreateContactCommandTest extends EppToolCommandTestCase { +class CreateContactCommandTest extends EppToolCommandTestCase { - @Before - public void initCommand() { + @BeforeEach + void beforeEach() { command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz"); } @Test - public void testSuccess_complete() throws Exception { + void testSuccess_complete() throws Exception { runCommandForced( "--client=NewRegistrar", "--id=sh8013", @@ -51,7 +51,7 @@ public class CreateContactCommandTest extends EppToolCommandTestCase @@ -77,13 +77,13 @@ public class CreateContactCommandTest extends EppToolCommandTestCase runCommandForced("--client=NewRegistrar", "--phone=3")); } @Test - public void testFailure_badFax() { + void testFailure_badFax() { assertThrows( ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--fax=3")); } diff --git a/core/src/test/java/google/registry/tools/CreateDomainCommandTest.java b/core/src/test/java/google/registry/tools/CreateDomainCommandTest.java index bf7762eca..374b6a2a5 100644 --- a/core/src/test/java/google/registry/tools/CreateDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateDomainCommandTest.java @@ -24,19 +24,19 @@ import com.beust.jcommander.ParameterException; import google.registry.model.registry.Registry; import google.registry.model.registry.label.PremiumList; import google.registry.testing.DeterministicStringGenerator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link CreateDomainCommand}. */ -public class CreateDomainCommandTest extends EppToolCommandTestCase { +class CreateDomainCommandTest extends EppToolCommandTestCase { - @Before - public void initCommand() { + @BeforeEach + void beforeEach() { command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz"); } @Test - public void testSuccess_complete() throws Exception { + void testSuccess_complete() throws Exception { runCommandForced( "--client=NewRegistrar", "--period=1", @@ -52,7 +52,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase { +class CreateHostCommandTest extends EppToolCommandTestCase { @Test - public void testSuccess_complete() throws Exception { + void testSuccess_complete() throws Exception { createTld("tld"); runCommandForced( "--client=NewRegistrar", @@ -35,7 +35,7 @@ public class CreateHostCommandTest extends EppToolCommandTestCase runCommandForced("--client=NewRegistrar")); } @Test - public void testFailure_invalidIpAddress() { + void testFailure_invalidIpAddress() { createTld("tld"); IllegalArgumentException thrown = assertThrows( diff --git a/core/src/test/java/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java b/core/src/test/java/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java index a046c5fe1..af18bdec6 100644 --- a/core/src/test/java/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java +++ b/core/src/test/java/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java @@ -28,11 +28,9 @@ import java.nio.charset.StandardCharsets; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -/** - * Base class for common testing setup for create and update commands for Premium Lists. - */ -public abstract class CreateOrUpdatePremiumListCommandTestCase< - T extends CreateOrUpdatePremiumListCommand> extends CommandTestCase { +/** Base class for common testing setup for create and update commands for Premium Lists. */ +abstract class CreateOrUpdatePremiumListCommandTestCase + extends CommandTestCase { @Captor ArgumentCaptor> urlParamCaptor; diff --git a/core/src/test/java/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java b/core/src/test/java/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java index 5f6c3da0a..b1f94abe0 100644 --- a/core/src/test/java/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java +++ b/core/src/test/java/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java @@ -32,25 +32,25 @@ import java.io.File; import java.io.IOException; import javax.persistence.EntityManager; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Base class for common testing setup for create and update commands for Reserved Lists. * * @param command type */ -public abstract class CreateOrUpdateReservedListCommandTestCase< +abstract class CreateOrUpdateReservedListCommandTestCase< T extends CreateOrUpdateReservedListCommand> extends CommandTestCase { String reservedTermsPath; - String invalidReservedTermsPath; + private String invalidReservedTermsPath; - @Before - public void init() throws IOException { - File reservedTermsFile = tmpDir.newFile("xn--q9jyb4c_common-reserved.txt"); - File invalidReservedTermsFile = tmpDir.newFile("reserved-terms-wontparse.csv"); + @BeforeEach + void beforeEachCreateOrUpdateReservedListCommandTestCase() throws IOException { + File reservedTermsFile = tmpDir.resolve("xn--q9jyb4c_common-reserved.txt").toFile(); + File invalidReservedTermsFile = tmpDir.resolve("reserved-terms-wontparse.csv").toFile(); String reservedTermsCsv = loadFile(CreateOrUpdateReservedListCommandTestCase.class, "example_reserved_terms.csv"); Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv); @@ -61,7 +61,7 @@ public abstract class CreateOrUpdateReservedListCommandTestCase< } @Test - public void testFailure_fileDoesntExist() { + void testFailure_fileDoesntExist() { assertThat( assertThrows( ParameterException.class, @@ -74,7 +74,7 @@ public abstract class CreateOrUpdateReservedListCommandTestCase< } @Test - public void testFailure_fileDoesntParse() { + void testFailure_fileDoesntParse() { assertThat( assertThrows( IllegalArgumentException.class, @@ -87,7 +87,7 @@ public abstract class CreateOrUpdateReservedListCommandTestCase< } @Test - public void testFailure_invalidLabel_includesFullDomainName() throws Exception { + void testFailure_invalidLabel_includesFullDomainName() throws Exception { Files.asCharSink(new File(invalidReservedTermsPath), UTF_8) .write("example.tld,FULLY_BLOCKED\n\n"); assertThat( diff --git a/core/src/test/java/google/registry/tools/CreatePremiumListCommandTest.java b/core/src/test/java/google/registry/tools/CreatePremiumListCommandTest.java index 4ee2f11ca..5fc81668f 100644 --- a/core/src/test/java/google/registry/tools/CreatePremiumListCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreatePremiumListCommandTest.java @@ -29,23 +29,25 @@ import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import google.registry.tools.server.CreatePremiumListAction; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link CreatePremiumListCommand}. */ -public class CreatePremiumListCommandTest +class CreatePremiumListCommandTest extends CreateOrUpdatePremiumListCommandTestCase { @Mock AppEngineConnection connection; - String premiumTermsPath; + private String premiumTermsPath; String premiumTermsCsv; - String servletPath; + private String servletPath; - @Before - public void init() throws Exception { + @BeforeEach + void beforeEach() throws Exception { command.setConnection(connection); premiumTermsPath = writeToNamedTmpFile( @@ -61,7 +63,7 @@ public class CreatePremiumListCommandTest } @Test - public void testRun() throws Exception { + void testRun() throws Exception { runCommandForced("-i=" + premiumTermsPath, "-n=foo"); assertInStdout("Successfully"); verifySentParams( @@ -71,7 +73,7 @@ public class CreatePremiumListCommandTest } @Test - public void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception { + void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception { runCommandForced("-i=" + premiumTermsPath); assertInStdout("Successfully"); verifySentParams( @@ -82,7 +84,7 @@ public class CreatePremiumListCommandTest } @Test - public void testRun_errorResponse() throws Exception { + void testRun_errorResponse() throws Exception { reset(connection); command.setConnection(connection); when(connection.sendPostRequest( @@ -95,13 +97,15 @@ public class CreatePremiumListCommandTest } @Test - public void testRun_noInputFileSpecified_throwsException() { + @MockitoSettings(strictness = Strictness.LENIENT) + void testRun_noInputFileSpecified_throwsException() { ParameterException thrown = assertThrows(ParameterException.class, this::runCommand); assertThat(thrown).hasMessageThat().contains("The following option is required"); } @Test - public void testRun_invalidInputData() throws Exception { + @MockitoSettings(strictness = Strictness.LENIENT) + void testRun_invalidInputData() throws Exception { premiumTermsPath = writeToNamedTmpFile( "tmp_file2", diff --git a/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java b/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java index 0f2834ce6..e5d379e62 100644 --- a/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java @@ -26,7 +26,7 @@ import static org.joda.time.DateTimeZone.UTC; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import com.beust.jcommander.ParameterException; @@ -39,23 +39,23 @@ import java.io.IOException; import java.util.Optional; import org.joda.money.CurrencyUnit; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; /** Unit tests for {@link CreateRegistrarCommand}. */ -public class CreateRegistrarCommandTest extends CommandTestCase { +class CreateRegistrarCommandTest extends CommandTestCase { @Mock private AppEngineConnection connection; - @Before - public void init() { + @BeforeEach + void beforeEach() { command.setConnection(connection); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { DateTime before = DateTime.now(UTC); runCommandForced( "--name=blobio", @@ -102,7 +102,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -940,7 +940,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -961,7 +961,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -982,7 +982,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1029,7 +1029,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1050,7 +1050,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1071,7 +1071,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1092,7 +1092,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1114,7 +1114,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1244,7 +1244,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1264,7 +1264,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1284,7 +1284,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1303,7 +1303,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1324,7 +1324,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1345,7 +1345,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1366,7 +1366,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1387,7 +1387,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1409,7 +1409,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1432,7 +1432,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1452,7 +1452,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1471,7 +1471,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1491,7 +1491,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1511,7 +1511,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1532,7 +1532,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1553,7 +1553,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1572,7 +1572,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1613,7 +1613,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1633,7 +1633,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1653,7 +1653,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1674,7 +1674,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1695,7 +1695,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1818,7 +1818,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase @@ -1839,7 +1839,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase { +class CreateRegistrarGroupsCommandTest extends CommandTestCase { @Mock private AppEngineConnection connection; - @Before - public void init() { + @BeforeEach + void beforeEach() { command.setConnection(connection); } @Test - public void test_createGroupsForTwoRegistrars() throws Exception { + void test_createGroupsForTwoRegistrars() throws Exception { runCommandForced("NewRegistrar", "TheRegistrar"); verify(connection) .sendPostRequest( @@ -55,7 +54,7 @@ public class CreateRegistrarGroupsCommandTest extends } @Test - public void test_throwsExceptionForNonExistentRegistrar() { + void test_throwsExceptionForNonExistentRegistrar() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java b/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java index e79f3180a..88eb36f49 100644 --- a/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java @@ -30,20 +30,20 @@ import google.registry.model.registry.label.ReservedList; import google.registry.model.registry.label.ReservedList.ReservedListEntry; import google.registry.model.registry.label.ReservedListSqlDao; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link CreateReservedListCommand}. */ -public class CreateReservedListCommandTest extends - CreateOrUpdateReservedListCommandTestCase { +class CreateReservedListCommandTest + extends CreateOrUpdateReservedListCommandTestCase { - @Before - public void initTest() { + @BeforeEach + void beforeEach() { createTlds("xn--q9jyb4c", "soy"); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); ReservedList reservedList = ReservedList.get("xn--q9jyb4c_common-reserved").get(); @@ -53,13 +53,13 @@ public class CreateReservedListCommandTest extends } @Test - public void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception { + void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception { runCommandForced("--input=" + reservedTermsPath); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); } @Test - public void testSuccess_timestampsSetCorrectly() throws Exception { + void testSuccess_timestampsSetCorrectly() throws Exception { DateTime before = DateTime.now(UTC); runCommandForced("--input=" + reservedTermsPath); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); @@ -69,28 +69,28 @@ public class CreateReservedListCommandTest extends } @Test - public void testSuccess_shouldPublishDefaultsToTrue() throws Exception { + void testSuccess_shouldPublishDefaultsToTrue() throws Exception { runCommandForced("--input=" + reservedTermsPath); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved").get().getShouldPublish()).isTrue(); } @Test - public void testSuccess_shouldPublishSetToTrue_works() throws Exception { + void testSuccess_shouldPublishSetToTrue_works() throws Exception { runCommandForced("--input=" + reservedTermsPath, "--should_publish=true"); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved").get().getShouldPublish()).isTrue(); } @Test - public void testSuccess_shouldPublishSetToFalse_works() throws Exception { + void testSuccess_shouldPublishSetToFalse_works() throws Exception { runCommandForced("--input=" + reservedTermsPath, "--should_publish=false"); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved").get().getShouldPublish()).isFalse(); } @Test - public void testFailure_reservedListWithThatNameAlreadyExists() { + void testFailure_reservedListWithThatNameAlreadyExists() { ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED"); persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build()); IllegalArgumentException thrown = @@ -101,90 +101,90 @@ public class CreateReservedListCommandTest extends } @Test - public void testNamingRules_commonReservedList() throws Exception { + void testNamingRules_commonReservedList() throws Exception { runCommandForced("--name=common_abuse-list", "--input=" + reservedTermsPath); assertThat(ReservedList.get("common_abuse-list")).isPresent(); } @Test - public void testNamingRules_tldThatDoesNotExist_succeedsWithOverride() throws Exception { + void testNamingRules_tldThatDoesNotExist_succeedsWithOverride() throws Exception { runNameTestWithOverride("footld_reserved-list"); } @Test - public void testNamingRules_tldThatDoesNotExist_failsWithoutOverride() { + void testNamingRules_tldThatDoesNotExist_failsWithoutOverride() { runNameTestExpectedFailure("footld_reserved-list", "TLD footld does not exist"); } @Test - public void testNamingRules_underscoreIsMissing_succeedsWithOverride() throws Exception { + void testNamingRules_underscoreIsMissing_succeedsWithOverride() throws Exception { runNameTestWithOverride("random-reserved-list"); } @Test - public void testNamingRules_underscoreIsMissing_failsWithoutOverride() { + void testNamingRules_underscoreIsMissing_failsWithoutOverride() { runNameTestExpectedFailure("random-reserved-list", INVALID_FORMAT_ERROR_MESSAGE); } @Test - public void testNamingRules_secondHalfOfNameIsMissing_succeedsWithOverride() throws Exception { + void testNamingRules_secondHalfOfNameIsMissing_succeedsWithOverride() throws Exception { runNameTestWithOverride("soy_"); } @Test - public void testNamingRules_secondHalfOfNameIsMissing_failsWithoutOverride() { + void testNamingRules_secondHalfOfNameIsMissing_failsWithoutOverride() { runNameTestExpectedFailure("soy_", INVALID_FORMAT_ERROR_MESSAGE); } @Test - public void testNamingRules_onlyTldIsSpecifiedAsName_succeedsWithOverride() throws Exception { + void testNamingRules_onlyTldIsSpecifiedAsName_succeedsWithOverride() throws Exception { runNameTestWithOverride("soy"); } @Test - public void testNamingRules_onlyTldIsSpecifiedAsName_failsWithoutOverride() { + void testNamingRules_onlyTldIsSpecifiedAsName_failsWithoutOverride() { runNameTestExpectedFailure("soy", INVALID_FORMAT_ERROR_MESSAGE); } @Test - public void testNamingRules_commonAsListName_succeedsWithOverride() throws Exception { + void testNamingRules_commonAsListName_succeedsWithOverride() throws Exception { runNameTestWithOverride("invalidtld_common"); } @Test - public void testNamingRules_commonAsListName_failsWithoutOverride() { + void testNamingRules_commonAsListName_failsWithoutOverride() { runNameTestExpectedFailure("invalidtld_common", "TLD invalidtld does not exist"); } @Test - public void testNamingRules_too_many_underscores_succeedsWithOverride() throws Exception { + void testNamingRules_too_many_underscores_succeedsWithOverride() throws Exception { runNameTestWithOverride("soy_buffalo_buffalo_buffalo"); } @Test - public void testNamingRules_too_many_underscores_failsWithoutOverride() { + void testNamingRules_too_many_underscores_failsWithoutOverride() { runNameTestExpectedFailure("soy_buffalo_buffalo_buffalo", INVALID_FORMAT_ERROR_MESSAGE); } @Test - public void testNamingRules_withWeirdCharacters_succeedsWithOverride() throws Exception { + void testNamingRules_withWeirdCharacters_succeedsWithOverride() throws Exception { runNameTestWithOverride("soy_$oy"); } @Test - public void testNamingRules_withWeirdCharacters_failsWithoutOverride() { + void testNamingRules_withWeirdCharacters_failsWithoutOverride() { runNameTestExpectedFailure("soy_$oy", INVALID_FORMAT_ERROR_MESSAGE); } @Test - public void testSaveToCloudSql_succeeds() throws Exception { + void testSaveToCloudSql_succeeds() throws Exception { runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath); verifyXnq9jyb4cInDatastore(); verifyXnq9jyb4cInCloudSql(); } @Test - public void testSaveToCloudSql_noExceptionThrownWhenSaveFail() throws Exception { + void testSaveToCloudSql_noExceptionThrownWhenSaveFail() throws Exception { // Note that, during the dual-write phase, we want to make sure that no exception will be // thrown if saving reserved list to Cloud SQL fails. ReservedListSqlDao.save( diff --git a/core/src/test/java/google/registry/tools/CreateTldCommandTest.java b/core/src/test/java/google/registry/tools/CreateTldCommandTest.java index 5839e52ca..6cbb4d558 100644 --- a/core/src/test/java/google/registry/tools/CreateTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateTldCommandTest.java @@ -38,14 +38,14 @@ import java.math.BigDecimal; import org.joda.money.Money; import org.joda.time.DateTime; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link CreateTldCommand}. */ -public class CreateTldCommandTest extends CommandTestCase { +class CreateTldCommandTest extends CommandTestCase { - @Before - public void init() { + @BeforeEach + void beforeEach() { persistReservedList("common_abuse", "baa,FULLY_BLOCKED"); persistReservedList("xn--q9jyb4c_abuse", "lamb,FULLY_BLOCKED"); persistReservedList("tld_banned", "kilo,FULLY_BLOCKED", "lima,FULLY_BLOCKED"); @@ -55,7 +55,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { DateTime before = DateTime.now(UTC); runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=FooDnsWriter"); DateTime after = DateTime.now(UTC); @@ -72,7 +72,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_multipleArguments() { + void testFailure_multipleArguments() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -83,7 +83,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_multipleDuplicateArguments() { + void testFailure_multipleDuplicateArguments() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -94,7 +94,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_initialTldStateFlag() throws Exception { + void testSuccess_initialTldStateFlag() throws Exception { runCommandForced( "--initial_tld_state=GENERAL_AVAILABILITY", "--roid_suffix=Q9JYB4C", @@ -105,7 +105,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_initialRenewBillingCostFlag() throws Exception { + void testSuccess_initialRenewBillingCostFlag() throws Exception { runCommandForced( "--initial_renew_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", @@ -116,7 +116,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_eapFeeSchedule() throws Exception { + void testSuccess_eapFeeSchedule() throws Exception { DateTime now = DateTime.now(UTC); DateTime tomorrow = now.plusDays(1); runCommandForced( @@ -137,7 +137,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_addGracePeriodFlag() throws Exception { + void testSuccess_addGracePeriodFlag() throws Exception { runCommandForced( "--add_grace_period=PT300S", "--roid_suffix=Q9JYB4C", @@ -147,27 +147,27 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_roidSuffixWorks() throws Exception { + void testSuccess_roidSuffixWorks() throws Exception { runCommandForced("--roid_suffix=RSUFFIX", "--dns_writers=VoidDnsWriter", "tld"); assertThat(Registry.get("tld").getRoidSuffix()).isEqualTo("RSUFFIX"); } @Test - public void testSuccess_escrow() throws Exception { + void testSuccess_escrow() throws Exception { runCommandForced( "--escrow=true", "--roid_suffix=Q9JYB4C", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getEscrowEnabled()).isTrue(); } @Test - public void testSuccess_noEscrow() throws Exception { + void testSuccess_noEscrow() throws Exception { runCommandForced( "--escrow=false", "--roid_suffix=Q9JYB4C", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getEscrowEnabled()).isFalse(); } @Test - public void testSuccess_redemptionGracePeriodFlag() throws Exception { + void testSuccess_redemptionGracePeriodFlag() throws Exception { runCommandForced( "--redemption_grace_period=PT300S", "--roid_suffix=Q9JYB4C", @@ -178,7 +178,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_pendingDeleteLengthFlag() throws Exception { + void testSuccess_pendingDeleteLengthFlag() throws Exception { runCommandForced( "--pending_delete_length=PT300S", "--roid_suffix=Q9JYB4C", @@ -188,7 +188,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_automaticTransferLengthFlag() throws Exception { + void testSuccess_automaticTransferLengthFlag() throws Exception { runCommandForced( "--automatic_transfer_length=PT300S", "--roid_suffix=Q9JYB4C", @@ -199,7 +199,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_createBillingCostFlag() throws Exception { + void testSuccess_createBillingCostFlag() throws Exception { runCommandForced( "--create_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", @@ -209,7 +209,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_restoreBillingCostFlag() throws Exception { + void testSuccess_restoreBillingCostFlag() throws Exception { runCommandForced( "--restore_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", @@ -220,7 +220,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_serverStatusChangeCostFlag() throws Exception { + void testSuccess_serverStatusChangeCostFlag() throws Exception { runCommandForced( "--server_status_change_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", @@ -231,7 +231,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_nonUsdBillingCostFlag() throws Exception { + void testSuccess_nonUsdBillingCostFlag() throws Exception { runCommandForced( "--create_billing_cost=\"JPY 12345\"", "--restore_billing_cost=\"JPY 67890\"", @@ -247,7 +247,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipartTld() throws Exception { + void testSuccess_multipartTld() throws Exception { runCommandForced("co.uk", "--roid_suffix=COUK", "--dns_writers=VoidDnsWriter"); Registry registry = Registry.get("co.uk"); @@ -259,7 +259,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setReservedLists() throws Exception { + void testSuccess_setReservedLists() throws Exception { runCommandForced( "--reserved_lists=xn--q9jyb4c_abuse,common_abuse", "--roid_suffix=Q9JYB4C", @@ -270,7 +270,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidAddGracePeriod() { + void testFailure_invalidAddGracePeriod() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -284,7 +284,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidRedemptionGracePeriod() { + void testFailure_invalidRedemptionGracePeriod() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -298,7 +298,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidPendingDeleteLength() { + void testFailure_invalidPendingDeleteLength() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -312,7 +312,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidTldState() { + void testFailure_invalidTldState() { ParameterException thrown = assertThrows( ParameterException.class, @@ -326,7 +326,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_bothTldStateFlags() { + void testFailure_bothTldStateFlags() { DateTime now = DateTime.now(UTC); IllegalArgumentException thrown = assertThrows( @@ -345,7 +345,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_negativeInitialRenewBillingCost() { + void testFailure_negativeInitialRenewBillingCost() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -359,7 +359,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidEapCurrency() { + void testFailure_invalidEapCurrency() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -373,7 +373,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_noTldName() { + void testFailure_noTldName() { ParameterException thrown = assertThrows(ParameterException.class, this::runCommandForced); assertThat(thrown) .hasMessageThat() @@ -381,7 +381,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_noDnsWriter() { + void testFailure_noDnsWriter() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -390,7 +390,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_alreadyExists() { + void testFailure_alreadyExists() { createTld("xn--q9jyb4c"); IllegalStateException thrown = assertThrows( @@ -402,7 +402,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_tldStartsWithDigit() { + void testFailure_tldStartsWithDigit() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -411,7 +411,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setAllowedRegistrants() throws Exception { + void testSuccess_setAllowedRegistrants() throws Exception { runCommandForced( "--allowed_registrants=alice,bob", "--roid_suffix=Q9JYB4C", @@ -422,7 +422,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setAllowedNameservers() throws Exception { + void testSuccess_setAllowedNameservers() throws Exception { runCommandForced( "--allowed_nameservers=ns1.example.com,ns2.example.com", "--roid_suffix=Q9JYB4C", @@ -433,22 +433,22 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setCommonReservedListOnTld() throws Exception { + void testSuccess_setCommonReservedListOnTld() throws Exception { runSuccessfulReservedListsTest("common_abuse"); } @Test - public void testSuccess_setTldSpecificReservedListOnTld() throws Exception { + void testSuccess_setTldSpecificReservedListOnTld() throws Exception { runSuccessfulReservedListsTest("xn--q9jyb4c_abuse"); } @Test - public void testSuccess_setCommonReservedListAndTldSpecificReservedListOnTld() throws Exception { + void testSuccess_setCommonReservedListAndTldSpecificReservedListOnTld() throws Exception { runSuccessfulReservedListsTest("common_abuse,xn--q9jyb4c_abuse"); } @Test - public void testFailure_setReservedListFromOtherTld() { + void testFailure_setReservedListFromOtherTld() { runFailureReservedListsTest( "tld_banned", IllegalArgumentException.class, @@ -456,12 +456,12 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setReservedListFromOtherTld_withOverride() throws Exception { + void testSuccess_setReservedListFromOtherTld_withOverride() throws Exception { runReservedListsTestOverride("tld_banned"); } @Test - public void testFailure_setCommonAndReservedListFromOtherTld() { + void testFailure_setCommonAndReservedListFromOtherTld() { runFailureReservedListsTest( "common_abuse,tld_banned", IllegalArgumentException.class, @@ -469,7 +469,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception { + void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception { runReservedListsTestOverride("common_abuse,tld_banned"); String errMsg = "Error overridden: The reserved list(s) tld_banned " @@ -478,7 +478,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setMultipleReservedListsFromOtherTld() { + void testFailure_setMultipleReservedListsFromOtherTld() { runFailureReservedListsTest( "tld_banned,soy_expurgated", IllegalArgumentException.class, @@ -486,12 +486,12 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setMultipleReservedListsFromOtherTld_withOverride() throws Exception { + void testSuccess_setMultipleReservedListsFromOtherTld_withOverride() throws Exception { runReservedListsTestOverride("tld_banned,soy_expurgated"); } @Test - public void testFailure_setNonExistentReservedLists() { + void testFailure_setNonExistentReservedLists() { runFailureReservedListsTest( "xn--q9jyb4c_asdf,common_asdsdgh", IllegalArgumentException.class, @@ -499,7 +499,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setPremiumList() throws Exception { + void testSuccess_setPremiumList() throws Exception { runCommandForced( "--premium_list=xn--q9jyb4c", "--roid_suffix=Q9JYB4C", @@ -509,7 +509,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setDriveFolderIdToValue() throws Exception { + void testSuccess_setDriveFolderIdToValue() throws Exception { runCommandForced( "--drive_folder_id=madmax2030", "--roid_suffix=Q9JYB4C", @@ -519,7 +519,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setDriveFolderIdToNull() throws Exception { + void testSuccess_setDriveFolderIdToNull() throws Exception { runCommandForced( "--drive_folder_id=null", "--roid_suffix=Q9JYB4C", @@ -529,7 +529,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setPremiumListThatDoesntExist() { + void testFailure_setPremiumListThatDoesntExist() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -543,7 +543,7 @@ public class CreateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_specifiedDnsWriters_dontExist() { + void testFailure_specifiedDnsWriters_dontExist() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/CurlCommandTest.java b/core/src/test/java/google/registry/tools/CurlCommandTest.java index 4f2a524e1..324faf2c1 100644 --- a/core/src/test/java/google/registry/tools/CurlCommandTest.java +++ b/core/src/test/java/google/registry/tools/CurlCommandTest.java @@ -29,19 +29,22 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link CurlCommand}. */ -public class CurlCommandTest extends CommandTestCase { +class CurlCommandTest extends CommandTestCase { + @Mock private AppEngineConnection connection; @Mock private AppEngineConnection connectionForService; - @Before - public void init() { + @BeforeEach + void beforeEach() { command.setConnection(connection); when(connection.withService(any())).thenReturn(connectionForService); } @@ -49,7 +52,7 @@ public class CurlCommandTest extends CommandTestCase { @Captor ArgumentCaptor> urlParamCaptor; @Test - public void testGetInvocation() throws Exception { + void testGetInvocation() throws Exception { runCommand("--path=/foo/bar?a=1&b=2", "--service=TOOLS"); verify(connection).withService(TOOLS); verifyNoMoreInteractions(connection); @@ -58,7 +61,7 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testExplicitGetInvocation() throws Exception { + void testExplicitGetInvocation() throws Exception { runCommand("--path=/foo/bar?a=1&b=2", "--request=GET", "--service=BACKEND"); verify(connection).withService(BACKEND); verifyNoMoreInteractions(connection); @@ -67,7 +70,7 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testPostInvocation() throws Exception { + void testPostInvocation() throws Exception { runCommand("--path=/foo/bar?a=1&b=2", "--data=some data", "--service=DEFAULT"); verify(connection).withService(DEFAULT); verifyNoMoreInteractions(connection); @@ -80,7 +83,7 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testPostInvocation_withContentType() throws Exception { + void testPostInvocation_withContentType() throws Exception { runCommand( "--path=/foo/bar?a=1&b=2", "--data=some data", @@ -97,7 +100,8 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testPostInvocation_badContentType() throws Exception { + @MockitoSettings(strictness = Strictness.LENIENT) + void testPostInvocation_badContentType() throws Exception { assertThrows( IllegalArgumentException.class, () -> @@ -111,7 +115,7 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testMultiDataPost() throws Exception { + void testMultiDataPost() throws Exception { runCommand( "--path=/foo/bar?a=1&b=2", "--data=first=100", "-d", "second=200", "--service=PUBAPI"); verify(connection).withService(PUBAPI); @@ -125,7 +129,7 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testDataDoesntSplit() throws Exception { + void testDataDoesntSplit() throws Exception { runCommand( "--path=/foo/bar?a=1&b=2", "--data=one,two", "--service=PUBAPI"); verify(connection).withService(PUBAPI); @@ -139,7 +143,7 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testExplicitPostInvocation() throws Exception { + void testExplicitPostInvocation() throws Exception { runCommand("--path=/foo/bar?a=1&b=2", "--request=POST", "--service=TOOLS"); verify(connection).withService(TOOLS); verifyNoMoreInteractions(connection); @@ -152,7 +156,8 @@ public class CurlCommandTest extends CommandTestCase { } @Test - public void testGetWithBody() throws Exception { + @MockitoSettings(strictness = Strictness.LENIENT) + void testGetWithBody() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/DeleteAllocationTokensCommandTest.java b/core/src/test/java/google/registry/tools/DeleteAllocationTokensCommandTest.java index 89580f1b6..664f5c907 100644 --- a/core/src/test/java/google/registry/tools/DeleteAllocationTokensCommandTest.java +++ b/core/src/test/java/google/registry/tools/DeleteAllocationTokensCommandTest.java @@ -27,12 +27,11 @@ import google.registry.model.domain.token.AllocationToken.TokenType; import google.registry.model.reporting.HistoryEntry; import java.util.Collection; import javax.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link DeleteAllocationTokensCommand}. */ -public class DeleteAllocationTokensCommandTest - extends CommandTestCase { +class DeleteAllocationTokensCommandTest extends CommandTestCase { private AllocationToken preRed1; private AllocationToken preRed2; @@ -41,8 +40,8 @@ public class DeleteAllocationTokensCommandTest private AllocationToken othrRed; private AllocationToken othrNot; - @Before - public void init() { + @BeforeEach + void beforeEach() { createTlds("foo", "bar"); preRed1 = persistToken("prefix12345AA", null, true); preRed2 = persistToken("prefixgh8907a", null, true); @@ -53,7 +52,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_deleteOnlyUnredeemedTokensWithPrefix() throws Exception { + void test_deleteOnlyUnredeemedTokensWithPrefix() throws Exception { runCommandForced("--prefix", "prefix"); assertThat(reloadTokens(preNot1, preNot2)).isEmpty(); assertThat(reloadTokens(preRed1, preRed2, othrRed, othrNot)) @@ -61,7 +60,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_deleteSingleAllocationToken() throws Exception { + void test_deleteSingleAllocationToken() throws Exception { runCommandForced("--prefix", "asdgfho7HASDS"); assertThat(reloadTokens(othrNot)).isEmpty(); assertThat(reloadTokens(preRed1, preRed2, preNot1, preNot2, othrRed)) @@ -69,7 +68,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_deleteParticularTokens() throws Exception { + void test_deleteParticularTokens() throws Exception { runCommandForced("--tokens", "prefix2978204,asdgfho7HASDS"); assertThat(reloadTokens(preNot1, othrNot)).isEmpty(); assertThat(reloadTokens(preRed1, preRed2, preNot2, othrRed)) @@ -77,14 +76,14 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_deleteTokensWithNonExistentPrefix_doesNothing() throws Exception { + void test_deleteTokensWithNonExistentPrefix_doesNothing() throws Exception { runCommandForced("--prefix", "nonexistent"); assertThat(reloadTokens(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot)) .containsExactly(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot); } @Test - public void test_dryRun_deletesNothing() throws Exception { + void test_dryRun_deletesNothing() throws Exception { runCommandForced("--prefix", "prefix", "--dry_run"); assertThat(reloadTokens(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot)) .containsExactly(preRed1, preRed2, preNot1, preNot2, othrRed, othrNot); @@ -92,7 +91,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_defaultOptions_doesntDeletePerDomainTokens() throws Exception { + void test_defaultOptions_doesntDeletePerDomainTokens() throws Exception { AllocationToken preDom1 = persistToken("prefixasdfg897as", "foo.bar", false); AllocationToken preDom2 = persistToken("prefix98HAZXadbn", "foo.bar", true); runCommandForced("--prefix", "prefix"); @@ -102,7 +101,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_withDomains_doesDeletePerDomainTokens() throws Exception { + void test_withDomains_doesDeletePerDomainTokens() throws Exception { AllocationToken preDom1 = persistToken("prefixasdfg897as", "foo.bar", false); AllocationToken preDom2 = persistToken("prefix98HAZXadbn", "foo.bar", true); runCommandForced("--prefix", "prefix", "--with_domains"); @@ -112,7 +111,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void testSkipUnlimitedUseTokens() throws Exception { + void testSkipUnlimitedUseTokens() throws Exception { AllocationToken unlimitedUseToken = persistResource( new AllocationToken.Builder() @@ -124,7 +123,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_batching() throws Exception { + void test_batching() throws Exception { for (int i = 0; i < 50; i++) { persistToken(String.format("batch%2d", i), null, i % 2 == 0); } @@ -134,7 +133,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void test_prefixIsRequired() { + void test_prefixIsRequired() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, this::runCommandForced); assertThat(thrown) @@ -143,7 +142,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void testFailure_bothPrefixAndTokens() { + void testFailure_bothPrefixAndTokens() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -154,7 +153,7 @@ public class DeleteAllocationTokensCommandTest } @Test - public void testFailure_emptyPrefix() { + void testFailure_emptyPrefix() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommandForced("--prefix", "")); assertThat(thrown).hasMessageThat().isEqualTo("Provided prefix should not be blank"); diff --git a/core/src/test/java/google/registry/tools/DeleteDomainCommandTest.java b/core/src/test/java/google/registry/tools/DeleteDomainCommandTest.java index 9909953d6..960308d87 100644 --- a/core/src/test/java/google/registry/tools/DeleteDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/DeleteDomainCommandTest.java @@ -17,39 +17,39 @@ package google.registry.tools; import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link DeleteDomainCommand}. */ -public class DeleteDomainCommandTest extends EppToolCommandTestCase { +class DeleteDomainCommandTest extends EppToolCommandTestCase { @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force", "--reason=Test"); eppVerifier.verifySent("domain_delete.xml"); } @Test - public void testSuccess_multipleWordReason() throws Exception { + void testSuccess_multipleWordReason() throws Exception { runCommandForced( "--client=NewRegistrar", "--domain_name=example.tld", "--reason=\"Test test\""); eppVerifier.verifySent("domain_delete_multiple_word_reason.xml"); } @Test - public void testSuccess_immediately() throws Exception { + void testSuccess_immediately() throws Exception { runCommandForced( "--client=NewRegistrar", "--domain_name=example.tld", "--immediately", "--reason=Test"); eppVerifier.expectSuperuser().verifySent("domain_delete_immediately.xml"); } @Test - public void testSuccess_requestedByRegistrarFalse() throws Exception { + void testSuccess_requestedByRegistrarFalse() throws Exception { runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--reason=Test"); eppVerifier.verifySent("domain_delete.xml"); } @Test - public void testSuccess_requestedByRegistrarTrue() throws Exception { + void testSuccess_requestedByRegistrarTrue() throws Exception { runCommandForced( "--client=NewRegistrar", "--domain_name=example.tld", @@ -59,28 +59,28 @@ public class DeleteDomainCommandTest extends EppToolCommandTestCase runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force")); } @Test - public void testFailure_missingClientId() { + void testFailure_missingClientId() { assertThrows( ParameterException.class, () -> runCommand("--domain_name=example.tld", "--force", "--reason=Test")); } @Test - public void testFailure_missingDomainName() { + void testFailure_missingDomainName() { assertThrows( ParameterException.class, () -> runCommand("--client=NewRegistrar", "--force", "--reason=Test")); } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> @@ -93,7 +93,7 @@ public class DeleteDomainCommandTest extends EppToolCommandTestCase diff --git a/core/src/test/java/google/registry/tools/DeleteHostCommandTest.java b/core/src/test/java/google/registry/tools/DeleteHostCommandTest.java index 621188d8d..5eb4df107 100644 --- a/core/src/test/java/google/registry/tools/DeleteHostCommandTest.java +++ b/core/src/test/java/google/registry/tools/DeleteHostCommandTest.java @@ -17,26 +17,26 @@ package google.registry.tools; import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link DeleteHostCommand}. */ -public class DeleteHostCommandTest extends EppToolCommandTestCase { +class DeleteHostCommandTest extends EppToolCommandTestCase { @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test"); eppVerifier.verifySent("host_delete.xml"); } @Test - public void testSuccess_multipleWordReason() throws Exception { + void testSuccess_multipleWordReason() throws Exception { runCommand( "--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=\"Test test\""); eppVerifier.verifySent("host_delete_multiple_word_reason.xml"); } @Test - public void testSuccess_requestedByRegistrarFalse() throws Exception { + void testSuccess_requestedByRegistrarFalse() throws Exception { runCommand( "--client=NewRegistrar", "--host=ns1.example.tld", @@ -47,7 +47,7 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force")); } @Test - public void testFailure_missingClientId() { + void testFailure_missingClientId() { assertThrows( ParameterException.class, () -> runCommand("--host=ns1.example.tld", "--force", "--reason=Test")); } @Test - public void testFailure_missingHostName() { + void testFailure_missingHostName() { assertThrows( ParameterException.class, () -> runCommand("--client=NewRegistrar", "--force", "--reason=Test")); } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> @@ -92,7 +92,7 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase diff --git a/core/src/test/java/google/registry/tools/DeletePremiumListCommandTest.java b/core/src/test/java/google/registry/tools/DeletePremiumListCommandTest.java index bb339ddbd..6b7d67742 100644 --- a/core/src/test/java/google/registry/tools/DeletePremiumListCommandTest.java +++ b/core/src/test/java/google/registry/tools/DeletePremiumListCommandTest.java @@ -26,13 +26,13 @@ import static org.junit.Assert.assertThrows; import google.registry.model.registry.Registry; import google.registry.model.registry.label.PremiumList; import google.registry.model.registry.label.PremiumList.PremiumListEntry; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link DeletePremiumListCommand}. */ -public class DeletePremiumListCommandTest extends CommandTestCase { +class DeletePremiumListCommandTest extends CommandTestCase { @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { PremiumList premiumList = persistPremiumList("xn--q9jyb4c", "blah,USD 100"); assertThat(loadPremiumListEntries(premiumList)).hasSize(1); runCommand("--force", "--name=xn--q9jyb4c"); @@ -47,7 +47,7 @@ public class DeletePremiumListCommandTest extends CommandTestCase runCommandForced("--name=foo")); assertThat(thrown) @@ -56,7 +56,7 @@ public class DeletePremiumListCommandTest extends CommandTestCase { +class DeleteReservedListCommandTest extends CommandTestCase { - ReservedList reservedList; + private ReservedList reservedList; - @Before - public void init() { + @BeforeEach + void beforeEach() { reservedList = persistReservedList("common", "blah,FULLY_BLOCKED"); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { assertThat(reservedList.getReservedListEntries()).hasSize(1); runCommandForced("--name=common"); assertThat(ReservedList.get("common")).isEmpty(); } @Test - public void testFailure_whenReservedListDoesNotExist() { + void testFailure_whenReservedListDoesNotExist() { String expectedError = "Cannot delete the reserved list doesntExistReservedList because it doesn't exist."; IllegalArgumentException thrown = @@ -55,7 +55,7 @@ public class DeleteReservedListCommandTest extends CommandTestCase { +class DeleteTldCommandTest extends CommandTestCase { private static final String TLD_REAL = "tldreal"; private static final String TLD_TEST = "tldtest"; - @Before - public void setUp() { + @BeforeEach + void beforeEach() { persistResource( newRegistry( TLD_REAL, @@ -54,7 +54,7 @@ public class DeleteTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_otherTldUnaffected() throws Exception { + void testSuccess_otherTldUnaffected() throws Exception { runCommandForced("--tld=" + TLD_TEST); Registry.get(TLD_REAL); @@ -62,24 +62,24 @@ public class DeleteTldCommandTest extends CommandTestCase { } @Test - public void testFailure_whenTldDoesNotExist() { + void testFailure_whenTldDoesNotExist() { assertThrows(RegistryNotFoundException.class, () -> runCommandForced("--tld=nonexistenttld")); } @Test - public void testFailure_whenTldIsReal() { + void testFailure_whenTldIsReal() { assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_REAL)); } @Test - public void testFailure_whenDomainsArePresent() { + void testFailure_whenDomainsArePresent() { persistDeletedDomain("domain." + TLD_TEST, DateTime.parse("2000-01-01TZ")); assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST)); } @Test - public void testFailure_whenRegistrarLinksToTld() { + void testFailure_whenRegistrarLinksToTld() { allowRegistrarAccess("TheRegistrar", TLD_TEST); assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST)); diff --git a/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java b/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java index 201f29bd4..1e286480f 100644 --- a/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java +++ b/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java @@ -58,14 +58,11 @@ import java.util.Set; import java.util.stream.Collectors; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link google.registry.tools.DomainLockUtils}. */ -@RunWith(JUnit4.class) public final class DomainLockUtilsTest { private static final String DOMAIN_NAME = "example.tld"; @@ -74,7 +71,7 @@ public final class DomainLockUtilsTest { private final FakeClock clock = new FakeClock(DateTime.now(DateTimeZone.UTC)); private DomainLockUtils domainLockUtils; - @Rule + @RegisterExtension public final AppEngineRule appEngineRule = AppEngineRule.builder() .withDatastoreAndCloudSql() @@ -85,23 +82,24 @@ public final class DomainLockUtilsTest { private DomainBase domain; - @Before - public void setup() { + @BeforeEach + void setup() { createTlds("tld", "net"); HostResource host = persistActiveHost("ns1.example.net"); domain = persistResource(newDomainBase(DOMAIN_NAME, host)); AppEngineServiceUtils appEngineServiceUtils = mock(AppEngineServiceUtils.class); when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake"); - domainLockUtils = new DomainLockUtils( - new DeterministicStringGenerator(Alphabets.BASE_58), - "adminreg", - AsyncTaskEnqueuerTest.createForTesting( - appEngineServiceUtils, clock, standardSeconds(90))); + domainLockUtils = + new DomainLockUtils( + new DeterministicStringGenerator(Alphabets.BASE_58), + "adminreg", + AsyncTaskEnqueuerTest.createForTesting( + appEngineServiceUtils, clock, standardSeconds(90))); } @Test - public void testSuccess_createLock() { + void testSuccess_createLock() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); assertNoDomainChanges(); @@ -109,7 +107,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_createUnlock() { + void testSuccess_createUnlock() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); RegistryLock lock = domainLockUtils.saveNewRegistryUnlockRequest( @@ -118,7 +116,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_createUnlock_adminUnlockingAdmin() { + void testSuccess_createUnlock_adminUnlockingAdmin() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", null, true); RegistryLock lock = domainLockUtils.saveNewRegistryUnlockRequest( @@ -127,7 +125,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_createLock_previousLockExpired() { + void testSuccess_createLock_previousLockExpired() { domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); clock.advanceBy(standardDays(1)); RegistryLock lock = @@ -137,7 +135,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_createUnlock_previousUnlockRequestExpired() { + void testSuccess_createUnlock_previousUnlockRequestExpired() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.saveNewRegistryUnlockRequest( DOMAIN_NAME, "TheRegistrar", false, Optional.empty()); @@ -150,7 +148,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_applyLockDomain() { + void testSuccess_applyLockDomain() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false); @@ -158,7 +156,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_applyUnlockDomain() { + void testSuccess_applyUnlockDomain() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); RegistryLock unlock = domainLockUtils.saveNewRegistryUnlockRequest( @@ -168,7 +166,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_applyAdminLock_onlyHistoryEntry() { + void testSuccess_applyAdminLock_onlyHistoryEntry() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true); @@ -176,7 +174,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_applyAdminUnlock_onlyHistoryEntry() { + void testSuccess_applyAdminUnlock_onlyHistoryEntry() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true); @@ -188,20 +186,20 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_administrativelyLock_nonAdmin() { + void testSuccess_administrativelyLock_nonAdmin() { domainLockUtils.administrativelyApplyLock( DOMAIN_NAME, "TheRegistrar", "Marla.Singer@crr.com", false); verifyProperlyLockedDomain(false); } @Test - public void testSuccess_administrativelyLock_admin() { + void testSuccess_administrativelyLock_admin() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", null, true); verifyProperlyLockedDomain(true); } @Test - public void testSuccess_administrativelyUnlock_nonAdmin() { + void testSuccess_administrativelyUnlock_nonAdmin() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false); @@ -211,7 +209,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_administrativelyUnlock_admin() { + void testSuccess_administrativelyUnlock_admin() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true); @@ -221,7 +219,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_regularLock_relockSet() { + void testSuccess_regularLock_relockSet() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); RegistryLock oldLock = domainLockUtils.administrativelyApplyUnlock( @@ -235,7 +233,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_administrativelyLock_relockSet() { + void testSuccess_administrativelyLock_relockSet() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); RegistryLock oldLock = domainLockUtils.administrativelyApplyUnlock( @@ -248,7 +246,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_createUnlock_relockDuration() { + void testSuccess_createUnlock_relockDuration() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); RegistryLock lock = domainLockUtils.saveNewRegistryUnlockRequest( @@ -257,7 +255,7 @@ public final class DomainLockUtilsTest { } @Test - public void testSuccess_unlock_relockSubmitted() { + void testSuccess_unlock_relockSubmitted() { domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, false); RegistryLock lock = domainLockUtils.saveNewRegistryUnlockRequest( @@ -278,7 +276,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_createUnlock_alreadyPendingUnlock() { + void testFailure_createUnlock_alreadyPendingUnlock() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false); @@ -296,7 +294,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_createUnlock_nonAdminUnlockingAdmin() { + void testFailure_createUnlock_nonAdminUnlockingAdmin() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true); @@ -311,7 +309,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_createLock_unknownDomain() { + void testFailure_createLock_unknownDomain() { assertThat( assertThrows( IllegalArgumentException.class, @@ -323,7 +321,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_createLock_alreadyPendingLock() { + void testFailure_createLock_alreadyPendingLock() { domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); assertThat( assertThrows( @@ -336,7 +334,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_createLock_alreadyLocked() { + void testFailure_createLock_alreadyLocked() { persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build()); assertThat( assertThrows( @@ -349,7 +347,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_createUnlock_alreadyUnlocked() { + void testFailure_createUnlock_alreadyUnlocked() { assertThat( assertThrows( IllegalArgumentException.class, @@ -361,7 +359,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_applyLock_alreadyApplied() { + void testFailure_applyLock_alreadyApplied() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false); @@ -376,7 +374,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_applyLock_expired() { + void testFailure_applyLock_expired() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); clock.advanceBy(standardDays(1)); @@ -390,7 +388,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_applyLock_nonAdmin_applyAdminLock() { + void testFailure_applyLock_nonAdmin_applyAdminLock() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); assertThat( @@ -403,7 +401,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_applyUnlock_alreadyUnlocked() { + void testFailure_applyUnlock_alreadyUnlocked() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false); @@ -422,7 +420,7 @@ public final class DomainLockUtilsTest { } @Test - public void testFailure_applyLock_alreadyLocked() { + void testFailure_applyLock_alreadyLocked() { RegistryLock lock = domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); String verificationCode = lock.getVerificationCode(); diff --git a/core/src/test/java/google/registry/tools/DumpGoldenSchemaCommandTest.java b/core/src/test/java/google/registry/tools/DumpGoldenSchemaCommandTest.java index e4326ef74..3905f37e2 100644 --- a/core/src/test/java/google/registry/tools/DumpGoldenSchemaCommandTest.java +++ b/core/src/test/java/google/registry/tools/DumpGoldenSchemaCommandTest.java @@ -17,23 +17,17 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; import java.io.File; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; -@RunWith(JUnit4.class) -public class DumpGoldenSchemaCommandTest extends CommandTestCase { +/** Unit tests for {@link google.registry.tools.DumpGoldenSchemaCommand}. */ +class DumpGoldenSchemaCommandTest extends CommandTestCase { - @Rule public TemporaryFolder tmp = new TemporaryFolder(); - - public DumpGoldenSchemaCommandTest() {} + DumpGoldenSchemaCommandTest() {} @Test - public void testSchemaGeneration() throws Exception { - runCommand( - "--output=" + tmp.getRoot() + File.separatorChar + "golden.sql", "--start_postgresql"); - assertThat(new File(tmp.getRoot(), "golden.sql").length()).isGreaterThan(1); + void testSchemaGeneration() throws Exception { + File schemaFile = tmpDir.resolve("golden.sql").toFile(); + runCommand("--output=" + schemaFile.toString(), "--start_postgresql"); + assertThat(schemaFile.length()).isGreaterThan(1); } } diff --git a/core/src/test/java/google/registry/tools/EncryptEscrowDepositCommandTest.java b/core/src/test/java/google/registry/tools/EncryptEscrowDepositCommandTest.java index b0f72517b..8335e80b5 100644 --- a/core/src/test/java/google/registry/tools/EncryptEscrowDepositCommandTest.java +++ b/core/src/test/java/google/registry/tools/EncryptEscrowDepositCommandTest.java @@ -22,17 +22,16 @@ import com.google.common.io.Files; import google.registry.rde.RdeTestData; import google.registry.testing.BouncyCastleProviderRule; import google.registry.testing.FakeKeyringModule; -import java.io.File; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import java.nio.file.Path; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link EncryptEscrowDepositCommand}. */ public class EncryptEscrowDepositCommandTest extends CommandTestCase { - @Rule - public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule(); + @RegisterExtension public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule(); private final ByteSource depositXml = loadBytes(RdeTestData.class, "deposit_full.xml"); @@ -43,23 +42,22 @@ public class EncryptEscrowDepositCommandTest return res; } - @Before - public void before() { + @BeforeEach + void beforeEach() { command.encryptor = createEncryptor(); } @Test - public void testSuccess() throws Exception { - File outDir = tmpDir.newFolder(); - File depositFile = tmpDir.newFile("deposit.xml"); - Files.write(depositXml.read(), depositFile); - runCommand( - "--tld=lol", - "--input=" + depositFile.getPath(), - "--outdir=" + outDir.getPath()); - assertThat(outDir.list()).asList().containsExactly( - "lol_2010-10-17_full_S1_R0.ryde", - "lol_2010-10-17_full_S1_R0.sig", - "lol.pub"); + void testSuccess() throws Exception { + Path depositFile = tmpDir.resolve("deposit.xml"); + Files.write(depositXml.read(), depositFile.toFile()); + runCommand("--tld=lol", "--input=" + depositFile, "--outdir=" + tmpDir.toString()); + assertThat(tmpDir.toFile().list()) + .asList() + .containsExactly( + "deposit.xml", + "lol_2010-10-17_full_S1_R0.ryde", + "lol_2010-10-17_full_S1_R0.sig", + "lol.pub"); } } diff --git a/core/src/test/java/google/registry/tools/EntityWrapperTest.java b/core/src/test/java/google/registry/tools/EntityWrapperTest.java index 16bfabb41..bf2b76979 100644 --- a/core/src/test/java/google/registry/tools/EntityWrapperTest.java +++ b/core/src/test/java/google/registry/tools/EntityWrapperTest.java @@ -22,22 +22,20 @@ import com.google.common.collect.ImmutableList; import com.google.storage.onestore.v3.OnestoreEntity.EntityProto; import com.google.storage.onestore.v3.OnestoreEntity.Property; import google.registry.testing.AppEngineRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@RunWith(JUnit4.class) +/** Unit tests for {@link EntityWrapper}. */ public final class EntityWrapperTest { private static final String TEST_ENTITY_KIND = "TestEntity"; private static final int ARBITRARY_KEY_ID = 1001; - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void testEquals() { + void testEquals() { // Create an entity with a key and some properties. Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID); // Note that we need to specify these as long for property comparisons to work because that's @@ -73,7 +71,7 @@ public final class EntityWrapperTest { } @Test - public void testDifferentPropertiesNotEqual() { + void testDifferentPropertiesNotEqual() { Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID); // Note that we need to specify these as long for property comparisons to work because that's // how they are deserialized from protos. @@ -98,7 +96,7 @@ public final class EntityWrapperTest { } @Test - public void testDifferentKeysNotEqual() { + void testDifferentKeysNotEqual() { EntityProto proto1 = EntityTranslator.convertToPb(new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID)); EntityProto proto2 = @@ -115,7 +113,7 @@ public final class EntityWrapperTest { } @Test - public void testComparisonAgainstNonComparableEntities() { + void testComparisonAgainstNonComparableEntities() { EntityWrapper ce = new EntityWrapper(new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID)); // Note: this has to be "isNotEqualTo()" and not isNotNull() because we want to test the // equals() method and isNotNull() just checks for "ce != null". diff --git a/core/src/test/java/google/registry/tools/EppToolCommandTest.java b/core/src/test/java/google/registry/tools/EppToolCommandTest.java index 57d8bc561..80589f88f 100644 --- a/core/src/test/java/google/registry/tools/EppToolCommandTest.java +++ b/core/src/test/java/google/registry/tools/EppToolCommandTest.java @@ -21,7 +21,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.tools.server.ToolsTestData; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link EppToolCommand}. */ public class EppToolCommandTest extends EppToolCommandTestCase { @@ -50,7 +50,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase { } @Test - public void testSuccess_singleXmlCommand() throws Exception { + void testSuccess_singleXmlCommand() throws Exception { // The choice of xml file is arbitrary. runCommandForced( "--client=NewRegistrar", @@ -59,7 +59,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase { } @Test - public void testSuccess_multipleXmlCommands() throws Exception { + void testSuccess_multipleXmlCommands() throws Exception { // The choice of xml files is arbitrary. runCommandForced( "--client=NewRegistrar", @@ -73,7 +73,7 @@ public class EppToolCommandTest extends EppToolCommandTestCase { } @Test - public void testFailure_nonexistentClientId() { + void testFailure_nonexistentClientId() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/EppToolCommandTestCase.java b/core/src/test/java/google/registry/tools/EppToolCommandTestCase.java index 91ef400cf..4764cda4f 100644 --- a/core/src/test/java/google/registry/tools/EppToolCommandTestCase.java +++ b/core/src/test/java/google/registry/tools/EppToolCommandTestCase.java @@ -16,8 +16,8 @@ package google.registry.tools; import static google.registry.testing.DatastoreHelper.createTlds; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; /** * Abstract class for commands that construct + send EPP commands. @@ -31,15 +31,15 @@ public abstract class EppToolCommandTestCase extends C EppToolVerifier eppVerifier; - @Before - public void init() { + @BeforeEach + public void beforeEachEppToolCommandTestCase() { // Create two TLDs for commands that allow multiple TLDs at once. createTlds("tld", "tld2"); eppVerifier = EppToolVerifier.create(command).expectClientId("NewRegistrar"); } - @After - public void cleanup() throws Exception { + @AfterEach + public void afterEachEppToolCommandTestCase() throws Exception { eppVerifier.verifyNoMoreSent(); } } diff --git a/core/src/test/java/google/registry/tools/EppToolVerifier.java b/core/src/test/java/google/registry/tools/EppToolVerifier.java index 866a1dc88..36ed4b9a6 100644 --- a/core/src/test/java/google/registry/tools/EppToolVerifier.java +++ b/core/src/test/java/google/registry/tools/EppToolVerifier.java @@ -71,7 +71,7 @@ public class EppToolVerifier { * *

Must be called at least once before any {@link #verifySent} calls. */ - public EppToolVerifier expectClientId(String clientId) { + EppToolVerifier expectClientId(String clientId) { this.clientId = clientId; return this; } @@ -81,7 +81,7 @@ public class EppToolVerifier { * *

If not called, {@link #verifySent} will expect the "superuser" flag to be false. */ - public EppToolVerifier expectSuperuser() { + EppToolVerifier expectSuperuser() { this.superuser = true; return this; } @@ -91,7 +91,7 @@ public class EppToolVerifier { * *

If not called, {@link #verifySent} will expect the "dryRun" flag to be false. */ - public EppToolVerifier expectDryRun() { + EppToolVerifier expectDryRun() { this.dryRun = true; return this; } @@ -141,7 +141,7 @@ public class EppToolVerifier { * *

If multiple EPPs are expected, the verifySent* call order must match the EPP order. */ - public EppToolVerifier verifySentAny() throws Exception { + EppToolVerifier verifySentAny() throws Exception { setArgumentsIfNeeded(); paramIndex++; assertThat(capturedParams.size()).isAtLeast(paramIndex); @@ -151,7 +151,7 @@ public class EppToolVerifier { /** * Test that no more EPPs were sent, after any that were expected in previous "verifySent" calls. */ - public void verifyNoMoreSent() throws Exception { + void verifyNoMoreSent() throws Exception { setArgumentsIfNeeded(); assertThat( capturedParams diff --git a/core/src/test/java/google/registry/tools/ExecuteEppCommandTest.java b/core/src/test/java/google/registry/tools/ExecuteEppCommandTest.java index effb7b85a..fa3b3281f 100644 --- a/core/src/test/java/google/registry/tools/ExecuteEppCommandTest.java +++ b/core/src/test/java/google/registry/tools/ExecuteEppCommandTest.java @@ -20,48 +20,48 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import google.registry.tools.server.ToolsTestData; import java.io.ByteArrayInputStream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link ExecuteEppCommand}. */ -public class ExecuteEppCommandTest extends EppToolCommandTestCase { +class ExecuteEppCommandTest extends EppToolCommandTestCase { private String xmlInput; private String eppFile; - @Before - public void initCommand() throws Exception { + @BeforeEach + void beforeEach() throws Exception { xmlInput = ToolsTestData.loadFile("contact_create.xml"); eppFile = writeToNamedTmpFile("eppFile", xmlInput); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "--force", eppFile); eppVerifier.verifySent("contact_create.xml"); } @Test - public void testSuccess_dryRun() throws Exception { + void testSuccess_dryRun() throws Exception { runCommand("--client=NewRegistrar", "--dry_run", eppFile); eppVerifier.expectDryRun().verifySent("contact_create.xml"); } @Test - public void testSuccess_withSuperuser() throws Exception { + void testSuccess_withSuperuser() throws Exception { runCommand("--client=NewRegistrar", "--superuser", "--force", eppFile); eppVerifier.expectSuperuser().verifySent("contact_create.xml"); } @Test - public void testSuccess_fromStdin() throws Exception { + void testSuccess_fromStdin() throws Exception { System.setIn(new ByteArrayInputStream(xmlInput.getBytes(UTF_8))); runCommand("--client=NewRegistrar", "--force"); eppVerifier.verifySent("contact_create.xml"); } @Test - public void testSuccess_multipleFiles() throws Exception { + void testSuccess_multipleFiles() throws Exception { String xmlInput2 = ToolsTestData.loadFile("domain_check.xml"); String eppFile2 = writeToNamedTmpFile("eppFile2", xmlInput2); runCommand("--client=NewRegistrar", "--force", eppFile, eppFile2); @@ -71,19 +71,19 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase runCommand("--force", "foo.xml")); } @Test - public void testFailure_forceAndDryRunIncompatible() { + void testFailure_forceAndDryRunIncompatible() { assertThrows( IllegalArgumentException.class, () -> runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile)); } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml")); diff --git a/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java b/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java index 6b77665de..e1318c72e 100644 --- a/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java @@ -26,6 +26,8 @@ import static org.joda.time.DateTimeZone.UTC; import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import com.beust.jcommander.ParameterException; import com.google.appengine.tools.remoteapi.RemoteApiException; @@ -50,30 +52,29 @@ import java.io.File; import java.util.Collection; import javax.annotation.Nullable; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; /** Unit tests for {@link GenerateAllocationTokensCommand}. */ -public class GenerateAllocationTokensCommandTest - extends CommandTestCase { +class GenerateAllocationTokensCommandTest extends CommandTestCase { - @Before - public void init() { + @BeforeEach + void beforeEach() { command.stringGenerator = new DeterministicStringGenerator(Alphabets.BASE_58); command.retrier = new Retrier(new FakeSleeper(new FakeClock(DateTime.parse("2000-01-01TZ"))), 3); } @Test - public void testSuccess_oneToken() throws Exception { + void testSuccess_oneToken() throws Exception { runCommand("--prefix", "blah", "--number", "1", "--length", "9"); assertAllocationTokens(createToken("blah123456789", null, null)); assertInStdout("blah123456789"); } @Test - public void testSuccess_threeTokens() throws Exception { + void testSuccess_threeTokens() throws Exception { runCommand("--prefix", "foo", "--number", "3", "--length", "10"); assertAllocationTokens( createToken("foo123456789A", null, null), @@ -83,28 +84,29 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testSuccess_defaults() throws Exception { + void testSuccess_defaults() throws Exception { runCommand("--number", "1"); assertAllocationTokens(createToken("123456789ABCDEFG", null, null)); assertInStdout("123456789ABCDEFG"); } @Test - public void testSuccess_retry() throws Exception { - GenerateAllocationTokensCommand spyCommand = spy(command); + void testSuccess_retry() throws Exception { + command = spy(command); RemoteApiException fakeException = new RemoteApiException("foo", "foo", "foo", new Exception()); doThrow(fakeException) .doThrow(fakeException) .doCallRealMethod() - .when(spyCommand) + .when(command) .saveTokens(ArgumentMatchers.any()); runCommand("--number", "1"); assertAllocationTokens(createToken("123456789ABCDEFG", null, null)); assertInStdout("123456789ABCDEFG"); + verify(command, times(3)).saveTokens(ArgumentMatchers.any()); } @Test - public void testSuccess_tokenCollision() throws Exception { + void testSuccess_tokenCollision() throws Exception { AllocationToken existingToken = persistResource( new AllocationToken.Builder() @@ -117,14 +119,14 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testSuccess_dryRun_outputsButDoesntSave() throws Exception { + void testSuccess_dryRun_outputsButDoesntSave() throws Exception { runCommand("--prefix", "foo", "--number", "2", "--length", "10", "--dry_run"); assertAllocationTokens(); assertInStdout("foo123456789A\nfooBCDEFGHJKL"); } @Test - public void testSuccess_largeNumberOfTokens() throws Exception { + void testSuccess_largeNumberOfTokens() throws Exception { command.stringGenerator = new DeterministicStringGenerator(Alphabets.BASE_58, Rule.PREPEND_COUNTER); runCommand("--prefix", "ooo", "--number", "100", "--length", "16"); @@ -134,9 +136,9 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testSuccess_domainNames() throws Exception { + void testSuccess_domainNames() throws Exception { createTld("tld"); - File domainNamesFile = tmpDir.newFile("domain_names.txt"); + File domainNamesFile = tmpDir.resolve("domain_names.txt").toFile(); Files.asCharSink(domainNamesFile, UTF_8).write("foo1.tld\nboo2.tld\nbaz9.tld\n"); runCommand("--domain_names_file", domainNamesFile.getPath()); assertAllocationTokens( @@ -148,7 +150,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testSuccess_promotionToken() throws Exception { + void testSuccess_promotionToken() throws Exception { DateTime promoStart = DateTime.now(UTC); DateTime promoEnd = promoStart.plusMonths(1); runCommand( @@ -178,14 +180,14 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testSuccess_specifyTokens() throws Exception { + void testSuccess_specifyTokens() throws Exception { runCommand("--tokens", "foobar,foobaz"); assertAllocationTokens(createToken("foobar", null, null), createToken("foobaz", null, null)); assertInStdout("foobar", "foobaz"); } @Test - public void testSuccess_specifyManyTokens() throws Exception { + void testSuccess_specifyManyTokens() throws Exception { command.stringGenerator = new DeterministicStringGenerator(Alphabets.BASE_58, Rule.PREPEND_COUNTER); Collection sampleTokens = command.stringGenerator.createStrings(13, 100); @@ -195,7 +197,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_mustSpecifyNumberOfTokensOrDomainsFile() { + void testFailure_mustSpecifyNumberOfTokensOrDomainsFile() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("--prefix", "FEET")); assertThat(thrown) @@ -204,7 +206,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_mustNotSpecifyBothNumberOfTokensAndDomainsFile() { + void testFailure_mustNotSpecifyBothNumberOfTokensAndDomainsFile() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -219,7 +221,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_mustNotSpecifyBothNumberOfTokensAndTokenStrings() { + void testFailure_mustNotSpecifyBothNumberOfTokensAndTokenStrings() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -234,7 +236,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_mustNotSpecifyBothTokenStringsAndDomainsFile() { + void testFailure_mustNotSpecifyBothTokenStringsAndDomainsFile() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -249,9 +251,9 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_specifiesAlreadyExistingToken() throws Exception { + void testFailure_specifiesAlreadyExistingToken() throws Exception { runCommand("--tokens", "foobar"); - beforeCommandTestCase(); // reset the command variables + beforeEachCommandTestCase(); // reset the command variables IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("--tokens", "foobar,foobaz")); assertThat(thrown) @@ -260,7 +262,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_invalidTokenType() { + void testFailure_invalidTokenType() { ParameterException thrown = assertThrows( ParameterException.class, @@ -271,7 +273,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_invalidTokenStatusTransition() { + void testFailure_invalidTokenStatusTransition() { assertThat( assertThrows( ParameterException.class, @@ -286,7 +288,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_lengthOfZero() { + void testFailure_lengthOfZero() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -298,7 +300,7 @@ public class GenerateAllocationTokensCommandTest } @Test - public void testFailure_unlimitedUseMustHaveTransitions() { + void testFailure_unlimitedUseMustHaveTransitions() { assertThat( assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java b/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java index f64eb765b..eb85102f1 100644 --- a/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java @@ -41,21 +41,15 @@ import java.io.IOException; import java.io.Reader; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import org.joda.time.DateTime; import org.json.simple.JSONValue; import org.json.simple.parser.ParseException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GenerateDnsReportCommand}. */ -public class GenerateDnsReportCommandTest extends CommandTestCase { - - @Rule - public final TemporaryFolder folder = new TemporaryFolder(); +class GenerateDnsReportCommandTest extends CommandTestCase { private final DateTime now = DateTime.now(UTC); private final FakeClock clock = new FakeClock(); @@ -120,9 +114,9 @@ public class GenerateDnsReportCommandTest extends CommandTestCase output = (Iterable) getOutputAsJson(); assertThat(output).containsAnyOf(DOMAIN1_OUTPUT, DOMAIN1_OUTPUT_ALT); @@ -173,7 +167,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase) getOutputAsJson()) @@ -181,7 +175,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase output = (Iterable) getOutputAsJson(); @@ -190,7 +184,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase) getOutputAsJson()) @@ -198,7 +192,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase) getOutputAsJson()) @@ -206,7 +200,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase) getOutputAsJson()) @@ -227,12 +221,12 @@ public class GenerateDnsReportCommandTest extends CommandTestCase runCommand("--tld=foobar")); } @Test - public void testFailure_missingTldParameter() { + void testFailure_missingTldParameter() { assertThrows(ParameterException.class, () -> runCommand("")); } } diff --git a/core/src/test/java/google/registry/tools/GenerateEscrowDepositCommandTest.java b/core/src/test/java/google/registry/tools/GenerateEscrowDepositCommandTest.java index d01ed3c04..8be94beec 100644 --- a/core/src/test/java/google/registry/tools/GenerateEscrowDepositCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateEscrowDepositCommandTest.java @@ -26,21 +26,24 @@ import google.registry.testing.InjectRule; import google.registry.testing.TaskQueueHelper.TaskMatcher; import google.registry.util.AppEngineServiceUtils; import java.util.Optional; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link GenerateEscrowDepositCommand}. */ +@MockitoSettings(strictness = Strictness.LENIENT) public class GenerateEscrowDepositCommandTest extends CommandTestCase { - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); @Mock AppEngineServiceUtils appEngineServiceUtils; - @Before - public void before() { + @BeforeEach + void beforeEach() { createTld("tld"); createTld("anothertld"); command = new GenerateEscrowDepositCommand(); @@ -52,7 +55,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_missingTld() { + void testCommand_missingTld() { ParameterException thrown = assertThrows( ParameterException.class, @@ -62,7 +65,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_emptyTld() { + void testCommand_emptyTld() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -77,7 +80,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_invalidTld() { + void testCommand_invalidTld() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -92,7 +95,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_missingWatermark() { + void testCommand_missingWatermark() { ParameterException thrown = assertThrows( ParameterException.class, @@ -103,7 +106,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_emptyWatermark() { + void testCommand_emptyWatermark() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -112,7 +115,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_missingOutdir() { + void testCommand_missingOutdir() { ParameterException thrown = assertThrows( ParameterException.class, @@ -123,7 +126,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_emptyOutdir() { + void testCommand_emptyOutdir() { ParameterException thrown = assertThrows( ParameterException.class, @@ -138,7 +141,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_invalidWatermark() { + void testCommand_invalidWatermark() { ParameterException thrown = assertThrows( ParameterException.class, @@ -153,7 +156,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_invalidMode() { + void testCommand_invalidMode() { ParameterException thrown = assertThrows( ParameterException.class, @@ -170,7 +173,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_invalidRevision() { + void testCommand_invalidRevision() { ParameterException thrown = assertThrows( ParameterException.class, @@ -185,7 +188,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_success() throws Exception { + void testCommand_success() throws Exception { runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); assertTasksEnqueued( @@ -202,7 +205,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_successWithDefaultRevision() throws Exception { + void testCommand_successWithDefaultRevision() throws Exception { runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-o test"); assertTasksEnqueued( @@ -218,7 +221,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_successWithDefaultMode() throws Exception { + void testCommand_successWithDefaultMode() throws Exception { runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "-r=42", "-o test"); assertTasksEnqueued( @@ -235,7 +238,7 @@ public class GenerateEscrowDepositCommandTest } @Test - public void testCommand_successWithMultipleArgumentValues() throws Exception { + void testCommand_successWithMultipleArgumentValues() throws Exception { runCommand( "--tld=tld,anothertld", "--watermark=2017-01-01T00:00:00Z,2017-01-02T00:00:00Z", diff --git a/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java b/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java index 79cddbcdc..59022027a 100644 --- a/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java @@ -22,60 +22,54 @@ import com.google.common.io.Files; import com.google.common.io.Resources; import google.registry.persistence.NomulusPostgreSql; import java.io.File; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import java.nio.file.Path; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; /** Unit tests for {@link GenerateSqlSchemaCommand}. */ -@RunWith(JUnit4.class) -public class GenerateSqlSchemaCommandTest extends CommandTestCase { +@Testcontainers +class GenerateSqlSchemaCommandTest extends CommandTestCase { private String containerHostName; private int containerPort; - @Rule public TemporaryFolder tmp = new TemporaryFolder(); - - @ClassRule - public static PostgreSQLContainer postgres = + @Container + private static PostgreSQLContainer postgres = new PostgreSQLContainer(NomulusPostgreSql.getDockerTag()) .withDatabaseName("postgres") .withUsername("postgres") .withPassword("domain-registry"); - public GenerateSqlSchemaCommandTest() {} - - @Before - public void setUp() { + @BeforeEach + void beforeEach() { containerHostName = postgres.getContainerIpAddress(); containerPort = postgres.getMappedPort(GenerateSqlSchemaCommand.POSTGRESQL_PORT); } @Test - public void testSchemaGeneration() throws Exception { + void testSchemaGeneration() throws Exception { runCommand( - "--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql", + "--out_file=" + tmpDir.resolve("schema.sql").toString(), "--db_host=" + containerHostName, "--db_port=" + containerPort); // We don't verify the exact contents of the result SQL file because that would be too brittle, // but we check to make sure that a couple parts of it are named as we expect them to be // TODO: try running the schema against the test database. - File sqlFile = new File(tmp.getRoot(), "schema.sql"); - assertThat(sqlFile.exists()).isTrue(); - String fileContent = Files.asCharSource(sqlFile, UTF_8).read(); + File schemaFile = tmpDir.resolve("schema.sql").toFile(); + assertThat(schemaFile.exists()).isTrue(); + String fileContent = Files.asCharSource(schemaFile, UTF_8).read(); assertThat(fileContent).contains("create table \"Domain\" ("); assertThat(fileContent).contains("repo_id text not null,"); } @Test - public void testIncompatibleFlags() throws Exception { + void testIncompatibleFlags() throws Exception { runCommand( - "--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql", + "--out_file=" + tmpDir.resolve("schema.sql").toString(), "--db_host=" + containerHostName, "--db_port=" + containerPort, "--start_postgresql"); @@ -83,17 +77,17 @@ public class GenerateSqlSchemaCommandTest extends CommandTestCase { +class GetAllocationTokenCommandTest extends CommandTestCase { @Test - public void testSuccess_oneToken() throws Exception { + void testSuccess_oneToken() throws Exception { createTlds("bar"); AllocationToken token = persistResource( @@ -49,7 +49,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase tokens = persistSimpleResources( @@ -73,7 +73,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase { +class GetClaimsListCommandTest extends CommandTestCase { @Test - public void testSuccess_getWorks() throws Exception { + void testSuccess_getWorks() throws Exception { ClaimsListShard.create(DateTime.now(UTC), ImmutableMap.of("a", "1", "b", "2")).save(); - File output = tmpDir.newFile(); + File output = tmpDir.resolve("claims.txt").toFile(); runCommand("--output=" + output.getAbsolutePath()); assertThat(readAllLines(output.toPath(), UTF_8)).containsExactly("a,1", "b,2"); } @Test - public void testSuccess_endsWithNewline() throws Exception { + void testSuccess_endsWithNewline() throws Exception { ClaimsListShard.create(DateTime.now(UTC), ImmutableMap.of("a", "1")).save(); - File output = tmpDir.newFile(); + File output = tmpDir.resolve("claims.txt").toFile(); runCommand("--output=" + output.getAbsolutePath()); assertThat(new String(Files.readAllBytes(output.toPath()), UTF_8)).endsWith("\n"); } diff --git a/core/src/test/java/google/registry/tools/GetContactCommandTest.java b/core/src/test/java/google/registry/tools/GetContactCommandTest.java index ffe4f1775..1f8f17002 100644 --- a/core/src/test/java/google/registry/tools/GetContactCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetContactCommandTest.java @@ -24,21 +24,21 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GetContactCommand}. */ -public class GetContactCommandTest extends CommandTestCase { +class GetContactCommandTest extends CommandTestCase { - DateTime now = DateTime.now(UTC); + private DateTime now = DateTime.now(UTC); - @Before - public void initialize() { + @BeforeEach + void beforeEach() { createTld("tld"); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { persistActiveContact("sh8013"); runCommand("sh8013"); assertInStdout("contactId=sh8013"); @@ -46,7 +46,7 @@ public class GetContactCommandTest extends CommandTestCase { } @Test - public void testSuccess_expand() throws Exception { + void testSuccess_expand() throws Exception { persistActiveContact("sh8013"); runCommand("sh8013", "--expand"); assertInStdout("contactId=sh8013"); @@ -55,7 +55,7 @@ public class GetContactCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipleArguments() throws Exception { + void testSuccess_multipleArguments() throws Exception { persistActiveContact("sh8013"); persistActiveContact("jd1234"); runCommand("sh8013", "jd1234"); @@ -66,25 +66,25 @@ public class GetContactCommandTest extends CommandTestCase { } @Test - public void testSuccess_deletedContact() throws Exception { + void testSuccess_deletedContact() throws Exception { persistDeletedContact("sh8013", now.minusDays(1)); runCommand("sh8013"); assertInStdout("Contact 'sh8013' does not exist or is deleted"); } @Test - public void testSuccess_contactDoesNotExist() throws Exception { + void testSuccess_contactDoesNotExist() throws Exception { runCommand("nope"); assertInStdout("Contact 'nope' does not exist or is deleted"); } @Test - public void testFailure_noContact() { + void testFailure_noContact() { assertThrows(ParameterException.class, this::runCommand); } @Test - public void testSuccess_contactDeletedInFuture() throws Exception { + void testSuccess_contactDeletedInFuture() throws Exception { persistResource( newContactResource("sh8013").asBuilder().setDeletionTime(now.plusDays(1)).build()); runCommand("sh8013", "--read_timestamp=" + now.plusMonths(1)); diff --git a/core/src/test/java/google/registry/tools/GetDomainCommandTest.java b/core/src/test/java/google/registry/tools/GetDomainCommandTest.java index 6cce0d209..04aa2548b 100644 --- a/core/src/test/java/google/registry/tools/GetDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetDomainCommandTest.java @@ -24,21 +24,21 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GetDomainCommand}. */ -public class GetDomainCommandTest extends CommandTestCase { +class GetDomainCommandTest extends CommandTestCase { - DateTime now = DateTime.now(UTC); + private DateTime now = DateTime.now(UTC); - @Before - public void initialize() { + @BeforeEach + void beforeEach() { createTld("tld"); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { persistActiveDomain("example.tld"); runCommand("example.tld"); assertInStdout("fullyQualifiedDomainName=example.tld"); @@ -47,7 +47,7 @@ public class GetDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_expand() throws Exception { + void testSuccess_expand() throws Exception { persistActiveDomain("example.tld"); runCommand("example.tld", "--expand"); assertInStdout("fullyQualifiedDomainName=example.tld"); @@ -57,7 +57,7 @@ public class GetDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipleArguments() throws Exception { + void testSuccess_multipleArguments() throws Exception { persistActiveDomain("example.tld"); persistActiveDomain("example2.tld"); runCommand("example.tld", "example2.tld"); @@ -68,7 +68,7 @@ public class GetDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_domainDeletedInFuture() throws Exception { + void testSuccess_domainDeletedInFuture() throws Exception { persistResource(newDomainBase("example.tld").asBuilder() .setDeletionTime(now.plusDays(1)).build()); runCommand("example.tld", "--read_timestamp=" + now.plusMonths(1)); @@ -76,31 +76,31 @@ public class GetDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_deletedDomain() throws Exception { + void testSuccess_deletedDomain() throws Exception { persistDeletedDomain("example.tld", now.minusDays(1)); runCommand("example.tld"); assertInStdout("Domain 'example.tld' does not exist or is deleted"); } @Test - public void testSuccess_domainDoesNotExist() throws Exception { + void testSuccess_domainDoesNotExist() throws Exception { runCommand("something.tld"); assertInStdout("Domain 'something.tld' does not exist or is deleted"); } @Test - public void testFailure_tldDoesNotExist() throws Exception { + void testFailure_tldDoesNotExist() throws Exception { runCommand("example.foo"); assertInStdout("Domain 'example.foo' does not exist or is deleted"); } @Test - public void testFailure_noDomainName() { + void testFailure_noDomainName() { assertThrows(ParameterException.class, this::runCommand); } @Test - public void testSuccess_oneDomainDoesNotExist() throws Exception { + void testSuccess_oneDomainDoesNotExist() throws Exception { persistActiveDomain("example.tld"); createTld("com"); runCommand("example.com", "example.tld"); diff --git a/core/src/test/java/google/registry/tools/GetHistoryEntriesCommandTest.java b/core/src/test/java/google/registry/tools/GetHistoryEntriesCommandTest.java index d002ba916..b1947c74f 100644 --- a/core/src/test/java/google/registry/tools/GetHistoryEntriesCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetHistoryEntriesCommandTest.java @@ -24,24 +24,24 @@ import google.registry.model.domain.Period; import google.registry.model.reporting.HistoryEntry; import google.registry.testing.FakeClock; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GetClaimsListCommand}. */ -public class GetHistoryEntriesCommandTest extends CommandTestCase { +class GetHistoryEntriesCommandTest extends CommandTestCase { private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z")); private DomainBase domain; - @Before - public void setup() { + @BeforeEach + void beforeEach() { createTld("tld"); domain = persistActiveDomain("example.tld"); } @Test - public void testSuccess_works() throws Exception { + void testSuccess_works() throws Exception { persistResource( makeHistoryEntry( domain, @@ -61,7 +61,7 @@ public class GetHistoryEntriesCommandTest extends CommandTestCase { +class GetHostCommandTest extends CommandTestCase { - DateTime now = DateTime.now(UTC); + private DateTime now = DateTime.now(UTC); - @Before - public void initialize() { + @BeforeEach + void beforeEach() { createTld("tld"); } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { persistActiveHost("ns1.example.tld"); runCommand("ns1.example.tld"); assertInStdout("fullyQualifiedHostName=ns1.example.tld"); @@ -46,7 +46,7 @@ public class GetHostCommandTest extends CommandTestCase { } @Test - public void testSuccess_expand() throws Exception { + void testSuccess_expand() throws Exception { persistActiveHost("ns1.example.tld"); runCommand("ns1.example.tld", "--expand"); assertInStdout("fullyQualifiedHostName=ns1.example.tld"); @@ -55,7 +55,7 @@ public class GetHostCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipleArguments() throws Exception { + void testSuccess_multipleArguments() throws Exception { persistActiveHost("ns1.example.tld"); persistActiveHost("ns2.example.tld"); runCommand("ns1.example.tld", "ns2.example.tld"); @@ -66,7 +66,7 @@ public class GetHostCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipleTlds() throws Exception { + void testSuccess_multipleTlds() throws Exception { persistActiveHost("ns1.example.tld"); createTld("tld2"); persistActiveHost("ns1.example.tld2"); @@ -76,20 +76,20 @@ public class GetHostCommandTest extends CommandTestCase { } @Test - public void testSuccess_deletedHost() throws Exception { + void testSuccess_deletedHost() throws Exception { persistDeletedHost("ns1.example.tld", now.minusDays(1)); runCommand("ns1.example.tld"); assertInStdout("Host 'ns1.example.tld' does not exist or is deleted"); } @Test - public void testSuccess_hostDoesNotExist() throws Exception { + void testSuccess_hostDoesNotExist() throws Exception { runCommand("foo.example.tld"); assertInStdout("Host 'foo.example.tld' does not exist or is deleted"); } @Test - public void testSuccess_hostDeletedInFuture() throws Exception { + void testSuccess_hostDeletedInFuture() throws Exception { persistResource( newHostResource("ns1.example.tld").asBuilder() .setDeletionTime(now.plusDays(1)) @@ -99,14 +99,14 @@ public class GetHostCommandTest extends CommandTestCase { } @Test - public void testSuccess_externalHost() throws Exception { + void testSuccess_externalHost() throws Exception { persistActiveHost("ns1.example.foo"); runCommand("ns1.example.foo"); assertInStdout("fullyQualifiedHostName=ns1.example.foo"); } @Test - public void testFailure_noHostName() { + void testFailure_noHostName() { assertThrows(ParameterException.class, this::runCommand); } } diff --git a/core/src/test/java/google/registry/tools/GetOperationStatusCommandTest.java b/core/src/test/java/google/registry/tools/GetOperationStatusCommandTest.java index ee5a93f53..8358eae97 100644 --- a/core/src/test/java/google/registry/tools/GetOperationStatusCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetOperationStatusCommandTest.java @@ -22,24 +22,23 @@ import google.registry.export.datastore.DatastoreAdmin; import google.registry.export.datastore.DatastoreAdmin.Get; import google.registry.export.datastore.Operation; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link GetOperationStatusCommand}. */ -@RunWith(JUnit4.class) -public class GetOperationStatusCommandTest extends CommandTestCase { +class GetOperationStatusCommandTest extends CommandTestCase { @Mock private DatastoreAdmin datastoreAdmin; @Mock private Get getRequest; @Captor ArgumentCaptor operationName; - @Before - public void setup() throws IOException { + @BeforeEach + void beforeEach() throws IOException { command.datastoreAdmin = datastoreAdmin; when(datastoreAdmin.get(operationName.capture())).thenReturn(getRequest); @@ -47,13 +46,14 @@ public class GetOperationStatusCommandTest extends CommandTestCase runCommand("a", "b")); } } diff --git a/core/src/test/java/google/registry/tools/GetRegistrarCommandTest.java b/core/src/test/java/google/registry/tools/GetRegistrarCommandTest.java index 4d2e67b5b..f70eadb65 100644 --- a/core/src/test/java/google/registry/tools/GetRegistrarCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetRegistrarCommandTest.java @@ -18,37 +18,37 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GetRegistrarCommand}. */ -public class GetRegistrarCommandTest extends CommandTestCase { +class GetRegistrarCommandTest extends CommandTestCase { @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { // This registrar is created by AppEngineRule. runCommand("NewRegistrar"); } @Test - public void testSuccess_multipleArguments() throws Exception { + void testSuccess_multipleArguments() throws Exception { // Registrars are created by AppEngineRule. runCommand("NewRegistrar", "TheRegistrar"); } @Test - public void testFailure_registrarDoesNotExist() { + void testFailure_registrarDoesNotExist() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("ClientZ")); assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist"); } @Test - public void testFailure_noRegistrarName() { + void testFailure_noRegistrarName() { assertThrows(ParameterException.class, this::runCommand); } @Test - public void testFailure_oneRegistrarDoesNotExist() { + void testFailure_oneRegistrarDoesNotExist() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("NewRegistrar", "ClientZ")); assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist"); diff --git a/core/src/test/java/google/registry/tools/GetResourceByKeyCommandTest.java b/core/src/test/java/google/registry/tools/GetResourceByKeyCommandTest.java index 1dabe2ac5..9bf649247 100644 --- a/core/src/test/java/google/registry/tools/GetResourceByKeyCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetResourceByKeyCommandTest.java @@ -27,21 +27,21 @@ import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GetResourceByKeyCommand}. */ -public class GetResourceByKeyCommandTest extends CommandTestCase { +class GetResourceByKeyCommandTest extends CommandTestCase { - DateTime now = DateTime.now(UTC); + private DateTime now = DateTime.now(UTC); - @Before - public void initialize() { + @BeforeEach + void beforeEach() { createTld("tld"); } @Test - public void testSuccess_domain() throws Exception { + void testSuccess_domain() throws Exception { persistActiveDomain("example.tld"); runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw"); assertInStdout("fullyQualifiedDomainName=example.tld"); @@ -49,7 +49,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase runCommand("agR0ZXN0chULEgpEb21haW5CYXN")); @@ -222,7 +222,7 @@ public class GetResourceByKeyCommandTest extends CommandTestCase { +class GetSchemaTreeCommandTest extends CommandTestCase { + @Test - public void testAllClassesPrintedExactlyOnce() throws Exception { + void testAllClassesPrintedExactlyOnce() throws Exception { runCommand(); String stdout = getStdoutAsString(); for (Class clazz : EntityClasses.ALL_CLASSES) { diff --git a/core/src/test/java/google/registry/tools/GetTldCommandTest.java b/core/src/test/java/google/registry/tools/GetTldCommandTest.java index 06071a53c..82dc63a43 100644 --- a/core/src/test/java/google/registry/tools/GetTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetTldCommandTest.java @@ -19,36 +19,35 @@ import static google.registry.testing.DatastoreHelper.createTlds; import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link GetTldCommand}. */ -public class GetTldCommandTest extends CommandTestCase { +class GetTldCommandTest extends CommandTestCase { @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { createTld("xn--q9jyb4c"); runCommand("xn--q9jyb4c"); } @Test - public void testSuccess_multipleArguments() throws Exception { + void testSuccess_multipleArguments() throws Exception { createTlds("xn--q9jyb4c", "example"); runCommand("xn--q9jyb4c", "example"); } - @Test - public void testFailure_tldDoesNotExist() { + void testFailure_tldDoesNotExist() { assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c")); } @Test - public void testFailure_noTldName() { + void testFailure_noTldName() { assertThrows(ParameterException.class, this::runCommand); } @Test - public void testFailure_oneTldDoesNotExist() { + void testFailure_oneTldDoesNotExist() { createTld("xn--q9jyb4c"); assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "example")); } diff --git a/core/src/test/java/google/registry/tools/GhostrydeCommandTest.java b/core/src/test/java/google/registry/tools/GhostrydeCommandTest.java index 49c3af328..7471b270f 100644 --- a/core/src/test/java/google/registry/tools/GhostrydeCommandTest.java +++ b/core/src/test/java/google/registry/tools/GhostrydeCommandTest.java @@ -25,12 +25,12 @@ import google.registry.testing.FakeKeyringModule; import google.registry.testing.InjectRule; import java.nio.file.Files; import java.nio.file.Path; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link GhostrydeCommand}. */ -public class GhostrydeCommandTest extends CommandTestCase { +class GhostrydeCommandTest extends CommandTestCase { private static final byte[] SONG_BY_CHRISTINA_ROSSETTI = ("" + "When I am dead, my dearest, \n" @@ -51,50 +51,50 @@ public class GhostrydeCommandTest extends CommandTestCase { + "Haply I may remember, \n" + " And haply may forget. \n").getBytes(UTF_8); - @Rule - public final InjectRule inject = new InjectRule(); + @RegisterExtension final InjectRule inject = new InjectRule(); - @Rule - public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule(); + @RegisterExtension final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule(); private Keyring keyring; - @Before - public void before() { + @BeforeEach + void beforeEach() { keyring = new FakeKeyringModule().get(); command.rdeStagingDecryptionKey = keyring::getRdeStagingDecryptionKey; command.rdeStagingEncryptionKey = keyring::getRdeStagingEncryptionKey; } @Test - public void testParameters_cantSpecifyBothEncryptAndDecrypt() { + void testParameters_cantSpecifyBothEncryptAndDecrypt() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("--encrypt", "--decrypt")); assertThat(thrown).hasMessageThat().isEqualTo("Please specify either --encrypt or --decrypt"); } @Test - public void testParameters_mustSpecifyOneOfEncryptOrDecrypt() { + void testParameters_mustSpecifyOneOfEncryptOrDecrypt() throws Exception { + Path inputFile = Files.createFile(tmpDir.resolve("foo.dat")); IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, - () -> runCommand("--input=" + tmpDir.newFile(), "--output=" + tmpDir.newFile())); + () -> runCommand("--input=" + inputFile.toString(), "--output=bar.dat")); assertThat(thrown).hasMessageThat().isEqualTo("Please specify either --encrypt or --decrypt"); } @Test - public void testEncrypt_outputPathIsRequired() { + void testEncrypt_outputPathIsRequired() throws Exception { + Path inputFile = Files.createFile(tmpDir.resolve("foo.dat")); IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, - () -> runCommand("--encrypt", "--input=" + tmpDir.newFile())); + () -> runCommand("--encrypt", "--input=" + inputFile.toString())); assertThat(thrown).hasMessageThat().isEqualTo("--output path is required in --encrypt mode"); } @Test - public void testEncrypt_outputIsAFile_writesToFile() throws Exception { - Path inFile = tmpDir.newFile("atrain.txt").toPath(); - Path outFile = tmpDir.newFile().toPath(); + void testEncrypt_outputIsAFile_writesToFile() throws Exception { + Path inFile = tmpDir.resolve("atrain.txt"); + Path outFile = tmpDir.resolve("out.dat"); Files.write(inFile, SONG_BY_CHRISTINA_ROSSETTI); runCommand("--encrypt", "--input=" + inFile, "--output=" + outFile); byte[] decoded = @@ -103,24 +103,23 @@ public class GhostrydeCommandTest extends CommandTestCase { } @Test - public void testEncrypt_outputIsADirectory_appendsGhostrydeExtension() throws Exception { - Path inFile = tmpDir.newFile("atrain.txt").toPath(); - Path outDir = tmpDir.newFolder().toPath(); + void testEncrypt_outputIsADirectory_appendsGhostrydeExtension() throws Exception { + Path inFile = tmpDir.resolve("atrain.txt"); Files.write(inFile, SONG_BY_CHRISTINA_ROSSETTI); - runCommand("--encrypt", "--input=" + inFile, "--output=" + outDir); - Path lenOutFile = outDir.resolve("atrain.txt.length"); + runCommand("--encrypt", "--input=" + inFile, "--output=" + tmpDir.toString()); + Path lenOutFile = tmpDir.resolve("atrain.txt.length"); assertThat(Ghostryde.readLength(Files.newInputStream(lenOutFile))) .isEqualTo(SONG_BY_CHRISTINA_ROSSETTI.length); - Path outFile = outDir.resolve("atrain.txt.ghostryde"); + Path outFile = tmpDir.resolve("atrain.txt.ghostryde"); byte[] decoded = Ghostryde.decode(Files.readAllBytes(outFile), keyring.getRdeStagingDecryptionKey()); assertThat(decoded).isEqualTo(SONG_BY_CHRISTINA_ROSSETTI); } @Test - public void testDecrypt_outputIsAFile_writesToFile() throws Exception { - Path inFile = tmpDir.newFile().toPath(); - Path outFile = tmpDir.newFile().toPath(); + void testDecrypt_outputIsAFile_writesToFile() throws Exception { + Path inFile = tmpDir.resolve("atrain.txt"); + Path outFile = tmpDir.resolve("out.dat"); Files.write( inFile, Ghostryde.encode(SONG_BY_CHRISTINA_ROSSETTI, keyring.getRdeStagingEncryptionKey())); runCommand("--decrypt", "--input=" + inFile, "--output=" + outFile); @@ -128,19 +127,18 @@ public class GhostrydeCommandTest extends CommandTestCase { } @Test - public void testDecrypt_outputIsADirectory_AppendsDecryptExtension() throws Exception { - Path inFile = tmpDir.newFolder().toPath().resolve("atrain.ghostryde"); - Path outDir = tmpDir.newFolder().toPath(); + void testDecrypt_outputIsADirectory_AppendsDecryptExtension() throws Exception { + Path inFile = tmpDir.resolve("atrain.ghostryde"); Files.write( inFile, Ghostryde.encode(SONG_BY_CHRISTINA_ROSSETTI, keyring.getRdeStagingEncryptionKey())); - runCommand("--decrypt", "--input=" + inFile, "--output=" + outDir); - Path outFile = outDir.resolve("atrain.ghostryde.decrypt"); + runCommand("--decrypt", "--input=" + inFile, "--output=" + tmpDir.toString()); + Path outFile = tmpDir.resolve("atrain.ghostryde.decrypt"); assertThat(Files.readAllBytes(outFile)).isEqualTo(SONG_BY_CHRISTINA_ROSSETTI); } @Test - public void testDecrypt_outputIsStdOut() throws Exception { - Path inFile = tmpDir.newFolder().toPath().resolve("atrain.ghostryde"); + void testDecrypt_outputIsStdOut() throws Exception { + Path inFile = tmpDir.resolve("atrain.ghostryde"); Files.write( inFile, Ghostryde.encode(SONG_BY_CHRISTINA_ROSSETTI, keyring.getRdeStagingEncryptionKey())); runCommand("--decrypt", "--input=" + inFile); diff --git a/core/src/test/java/google/registry/tools/ImportDatastoreCommandTest.java b/core/src/test/java/google/registry/tools/ImportDatastoreCommandTest.java index 31f7e3270..414b33861 100644 --- a/core/src/test/java/google/registry/tools/ImportDatastoreCommandTest.java +++ b/core/src/test/java/google/registry/tools/ImportDatastoreCommandTest.java @@ -27,17 +27,17 @@ import google.registry.export.datastore.DatastoreAdmin.Get; import google.registry.export.datastore.DatastoreAdmin.Import; import google.registry.export.datastore.Operation; import java.util.Collection; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link ImportDatastoreCommand}. */ -@RunWith(JUnit4.class) -public class ImportDatastoreCommandTest extends CommandTestCase { +@MockitoSettings(strictness = Strictness.LENIENT) +class ImportDatastoreCommandTest extends CommandTestCase { @Captor ArgumentCaptor backupUrl; @Captor ArgumentCaptor> kinds; @@ -49,8 +49,8 @@ public class ImportDatastoreCommandTest extends CommandTestCase @@ -132,7 +132,7 @@ public class ImportDatastoreCommandTest extends CommandTestCase { @@ -40,22 +40,22 @@ public class ListCursorsCommandTest extends CommandTestCase private static final String HEADER_TWO = "--------------------------------------------------------------------------"; - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); - @Before - public void before() { + @BeforeEach + void beforeEach() { inject.setStaticField( Ofy.class, "clock", new FakeClock(DateTime.parse("1984-12-21T06:07:08.789Z"))); } @Test - public void testListCursors_noTlds_printsNothing() throws Exception { + void testListCursors_noTlds_printsNothing() throws Exception { runCommand("--type=BRDA"); assertThat(getStdoutAsString()).isEmpty(); } @Test - public void testListCursors_twoTldsOneAbsent_printsAbsentAndTimestampSorted() throws Exception { + void testListCursors_twoTldsOneAbsent_printsAbsentAndTimestampSorted() throws Exception { createTlds("foo", "bar"); persistResource( Cursor.create(CursorType.BRDA, DateTime.parse("1984-12-18TZ"), Registry.get("bar"))); @@ -70,19 +70,19 @@ public class ListCursorsCommandTest extends CommandTestCase } @Test - public void testListCursors_badCursor_throwsIae() { + void testListCursors_badCursor_throwsIae() { ParameterException thrown = assertThrows(ParameterException.class, () -> runCommand("--type=love")); assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter."); } @Test - public void testListCursors_lowercaseCursor_isAllowed() throws Exception { + void testListCursors_lowercaseCursor_isAllowed() throws Exception { runCommand("--type=brda"); } @Test - public void testListCursors_filterEscrowEnabled_doesWhatItSays() throws Exception { + void testListCursors_filterEscrowEnabled_doesWhatItSays() throws Exception { createTlds("foo", "bar"); persistResource(Registry.get("bar").asBuilder().setEscrowEnabled(true).build()); runCommand("--type=BRDA", "--escrow_enabled"); diff --git a/core/src/test/java/google/registry/tools/ListDatastoreOperationsCommandTest.java b/core/src/test/java/google/registry/tools/ListDatastoreOperationsCommandTest.java index 4845f4643..12031bdd2 100644 --- a/core/src/test/java/google/registry/tools/ListDatastoreOperationsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListDatastoreOperationsCommandTest.java @@ -27,18 +27,14 @@ import google.registry.testing.FakeClock; import google.registry.util.Clock; import java.io.IOException; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; /** Unit tests for {@link google.registry.tools.ListDatastoreOperationsCommand}. */ -@RunWith(JUnit4.class) -public class ListDatastoreOperationsCommandTest - extends CommandTestCase { +class ListDatastoreOperationsCommandTest extends CommandTestCase { @Mock private DatastoreAdmin datastoreAdmin; @Mock private ListOperations listOperationsRequest; @@ -46,25 +42,24 @@ public class ListDatastoreOperationsCommandTest private final Clock clock = new FakeClock(new DateTime("2019-01-01T00:00:30Z")); - @Before - public void setup() throws IOException { + @BeforeEach + void beforeEach() throws IOException { command.datastoreAdmin = datastoreAdmin; command.clock = clock; - - when(datastoreAdmin.list(filterClause.capture())).thenReturn(listOperationsRequest); - when(datastoreAdmin.listAll()).thenReturn(listOperationsRequest); when(listOperationsRequest.execute()).thenReturn(new OperationList()); } @Test - public void testListAll() throws Exception { + void testListAll() throws Exception { + when(datastoreAdmin.listAll()).thenReturn(listOperationsRequest); runCommand(); verify(datastoreAdmin, times(1)).listAll(); verifyNoMoreInteractions(datastoreAdmin); } @Test - public void testListWithFilter() throws Exception { + void testListWithFilter() throws Exception { + when(datastoreAdmin.list(filterClause.capture())).thenReturn(listOperationsRequest); runCommand("--start_time_filter=PT30S"); verify(datastoreAdmin, times(1)).list(filterClause.capture()); assertThat(filterClause.getValue()) diff --git a/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java b/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java index 0289f326b..ee0a5a06e 100644 --- a/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java @@ -27,7 +27,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import google.registry.model.registry.Registry.TldType; import google.registry.tools.server.ListDomainsAction; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** * Unit tests for {@link ListDomainsCommand}. @@ -47,7 +49,8 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase runCommand(tldsParam)); @@ -57,7 +60,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase { +class ListHostsCommandTest extends ListObjectsCommandTestCase { @Override final String getTaskPath() { diff --git a/core/src/test/java/google/registry/tools/ListObjectsCommandTestCase.java b/core/src/test/java/google/registry/tools/ListObjectsCommandTestCase.java index 3aed4091f..53881dd0b 100644 --- a/core/src/test/java/google/registry/tools/ListObjectsCommandTestCase.java +++ b/core/src/test/java/google/registry/tools/ListObjectsCommandTestCase.java @@ -29,8 +29,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; /** Abstract base class for unit tests of commands that list object data using a back-end task. */ @@ -47,16 +47,14 @@ public abstract class ListObjectsCommandTestCase return ImmutableMap.of(); } - ImmutableList otherParams = ImmutableList.of(); + private ImmutableList otherParams = ImmutableList.of(); - @Before - public void init() throws Exception { + @BeforeEach + void beforeEachListObjectsCommandTestCase() throws Exception { ImmutableMap otherParameters = getOtherParameters(); if (!otherParameters.isEmpty()) { otherParams = - otherParameters - .entrySet() - .stream() + otherParameters.entrySet().stream() .map(entry -> String.format("--%s=%s", entry.getKey(), entry.getValue())) .collect(toImmutableList()); } @@ -83,26 +81,26 @@ public abstract class ListObjectsCommandTestCase } @Test - public void testRun_noFields() throws Exception { + void testRun_noFields() throws Exception { runCommand(otherParams); verifySent(null, Optional.empty(), Optional.empty()); } @Test - public void testRun_oneField() throws Exception { + void testRun_oneField() throws Exception { runCommand( new ImmutableList.Builder().addAll(otherParams).add("--fields=fieldName").build()); verifySent("fieldName", Optional.empty(), Optional.empty()); } @Test - public void testRun_wildcardField() throws Exception { + void testRun_wildcardField() throws Exception { runCommand(new ImmutableList.Builder().addAll(otherParams).add("--fields=*").build()); verifySent("*", Optional.empty(), Optional.empty()); } @Test - public void testRun_header() throws Exception { + void testRun_header() throws Exception { runCommand( new ImmutableList.Builder() .addAll(otherParams) @@ -112,7 +110,7 @@ public abstract class ListObjectsCommandTestCase } @Test - public void testRun_noHeader() throws Exception { + void testRun_noHeader() throws Exception { runCommand( new ImmutableList.Builder() .addAll(otherParams) @@ -122,7 +120,7 @@ public abstract class ListObjectsCommandTestCase } @Test - public void testRun_fullFieldNames() throws Exception { + void testRun_fullFieldNames() throws Exception { runCommand( new ImmutableList.Builder() .addAll(otherParams) @@ -132,7 +130,7 @@ public abstract class ListObjectsCommandTestCase } @Test - public void testRun_allParameters() throws Exception { + void testRun_allParameters() throws Exception { runCommand( new ImmutableList.Builder() .addAll(otherParams) diff --git a/core/src/test/java/google/registry/tools/ListPremiumListsCommandTest.java b/core/src/test/java/google/registry/tools/ListPremiumListsCommandTest.java index c4c7353f0..e3e63cfde 100644 --- a/core/src/test/java/google/registry/tools/ListPremiumListsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListPremiumListsCommandTest.java @@ -21,8 +21,7 @@ import google.registry.tools.server.ListPremiumListsAction; * * @see ListObjectsCommandTestCase */ -public class ListPremiumListsCommandTest - extends ListObjectsCommandTestCase { +class ListPremiumListsCommandTest extends ListObjectsCommandTestCase { @Override final String getTaskPath() { diff --git a/core/src/test/java/google/registry/tools/ListRegistrarsCommandTest.java b/core/src/test/java/google/registry/tools/ListRegistrarsCommandTest.java index a7ec6ca57..fce128d86 100644 --- a/core/src/test/java/google/registry/tools/ListRegistrarsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListRegistrarsCommandTest.java @@ -21,8 +21,7 @@ import google.registry.tools.server.ListRegistrarsAction; * * @see ListObjectsCommandTestCase */ -public class ListRegistrarsCommandTest - extends ListObjectsCommandTestCase { +class ListRegistrarsCommandTest extends ListObjectsCommandTestCase { @Override final String getTaskPath() { diff --git a/core/src/test/java/google/registry/tools/ListReservedListsCommandTest.java b/core/src/test/java/google/registry/tools/ListReservedListsCommandTest.java index 4e07d5040..991307637 100644 --- a/core/src/test/java/google/registry/tools/ListReservedListsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListReservedListsCommandTest.java @@ -21,8 +21,7 @@ import google.registry.tools.server.ListReservedListsAction; * * @see ListObjectsCommandTestCase */ -public class ListReservedListsCommandTest - extends ListObjectsCommandTestCase { +class ListReservedListsCommandTest extends ListObjectsCommandTestCase { @Override final String getTaskPath() { diff --git a/core/src/test/java/google/registry/tools/ListTldsCommandTest.java b/core/src/test/java/google/registry/tools/ListTldsCommandTest.java index f9f8e029d..2ae6f230b 100644 --- a/core/src/test/java/google/registry/tools/ListTldsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListTldsCommandTest.java @@ -21,7 +21,7 @@ import google.registry.tools.server.ListTldsAction; * * @see ListObjectsCommandTestCase */ -public class ListTldsCommandTest extends ListObjectsCommandTestCase { +class ListTldsCommandTest extends ListObjectsCommandTestCase { @Override final String getTaskPath() { diff --git a/core/src/test/java/google/registry/tools/LoadTestCommandTest.java b/core/src/test/java/google/registry/tools/LoadTestCommandTest.java index 13922f362..d90974572 100644 --- a/core/src/test/java/google/registry/tools/LoadTestCommandTest.java +++ b/core/src/test/java/google/registry/tools/LoadTestCommandTest.java @@ -17,50 +17,50 @@ package google.registry.tools; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistNewRegistrar; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import google.registry.model.registrar.Registrar; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; -@RunWith(JUnit4.class) -public class LoadTestCommandTest extends CommandTestCase { - AppEngineConnection connection = mock(AppEngineConnection.class); +/** Unit tests for {@link LoadTestCommand}. */ +class LoadTestCommandTest extends CommandTestCase { - @Before - public void setUp() { + @Mock private AppEngineConnection connection; + + @BeforeEach + void beforeEach() { command.setConnection(connection); createTld("example"); persistNewRegistrar("acme", "ACME", Registrar.Type.REAL, 99L); } @Test - public void test_defaults() throws Exception { + void test_defaults() throws Exception { runCommandForced(); - ImmutableMap parms = new ImmutableMap.Builder() - .put("tld", "example") - .put("clientId", "acme") - .put("successfulHostCreates", 1) - .put("successfulDomainCreates", 1) - .put("successfulContactCreates", 1) - .put("hostInfos", 1) - .put("domainInfos", 1) - .put("contactInfos", 1) - .put("runSeconds", 4600) - .build(); + ImmutableMap params = + new ImmutableMap.Builder() + .put("tld", "example") + .put("clientId", "acme") + .put("successfulHostCreates", 1) + .put("successfulDomainCreates", 1) + .put("successfulContactCreates", 1) + .put("hostInfos", 1) + .put("domainInfos", 1) + .put("contactInfos", 1) + .put("runSeconds", 4600) + .build(); verify(connection) .sendPostRequest( - eq("/_dr/loadtest"), eq(parms), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0])); + eq("/_dr/loadtest"), eq(params), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0])); } @Test - public void test_overrides() throws Exception { + void test_overrides() throws Exception { createTld("foo"); runCommandForced( "--tld=foo", @@ -72,38 +72,39 @@ public class LoadTestCommandTest extends CommandTestCase { "--domain_infos=14", "--contact_infos=15", "--run_seconds=16"); - ImmutableMap parms = new ImmutableMap.Builder() - .put("tld", "foo") - .put("clientId", "NewRegistrar") - .put("successfulHostCreates", 10) - .put("successfulDomainCreates", 11) - .put("successfulContactCreates", 12) - .put("hostInfos", 13) - .put("domainInfos", 14) - .put("contactInfos", 15) - .put("runSeconds", 16) - .build(); + ImmutableMap params = + new ImmutableMap.Builder() + .put("tld", "foo") + .put("clientId", "NewRegistrar") + .put("successfulHostCreates", 10) + .put("successfulDomainCreates", 11) + .put("successfulContactCreates", 12) + .put("hostInfos", 13) + .put("domainInfos", 14) + .put("contactInfos", 15) + .put("runSeconds", 16) + .build(); verify(connection) .sendPostRequest( - eq("/_dr/loadtest"), eq(parms), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0])); + eq("/_dr/loadtest"), eq(params), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0])); } @Test - public void test_badTLD() throws Exception { + void test_badTLD() throws Exception { runCommand("--tld=bogus"); - verifyZeroInteractions(connection); + verifyNoInteractions(connection); assertInStderr("No such TLD: bogus"); } @Test - public void test_badClientId() throws Exception { + void test_badClientId() throws Exception { runCommand("--client_id=badaddry"); - verifyZeroInteractions(connection); + verifyNoInteractions(connection); assertInStderr("No such client: badaddry"); } @Test - public void test_noProduction() throws Exception { + void test_noProduction() throws Exception { runCommandInEnvironment(RegistryToolEnvironment.PRODUCTION); assertInStderr("You may not run a load test against production."); } diff --git a/core/src/test/java/google/registry/tools/LockDomainCommandTest.java b/core/src/test/java/google/registry/tools/LockDomainCommandTest.java index d9987ad8d..a8742990c 100644 --- a/core/src/test/java/google/registry/tools/LockDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/LockDomainCommandTest.java @@ -37,14 +37,14 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link LockDomainCommand}. */ -public class LockDomainCommandTest extends CommandTestCase { +class LockDomainCommandTest extends CommandTestCase { - @Before - public void before() { + @BeforeEach + void beforeEach() { persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L); createTld("tld"); command.registryAdminClientId = "adminreg"; @@ -57,7 +57,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_locksDomain() throws Exception { + void testSuccess_locksDomain() throws Exception { DomainBase domain = persistActiveDomain("example.tld"); runCommandForced("--client=TheRegistrar", "example.tld"); assertThat(reloadResource(domain).getStatusValues()) @@ -65,7 +65,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_partiallyUpdatesStatuses() throws Exception { + void testSuccess_partiallyUpdatesStatuses() throws Exception { DomainBase domain = persistResource( newDomainBase("example.tld") @@ -78,7 +78,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_manyDomains() throws Exception { + void testSuccess_manyDomains() throws Exception { // Create 26 domains -- one more than the number of entity groups allowed in a transaction (in // case that was going to be the failure point). List domains = new ArrayList<>(); @@ -98,7 +98,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testFailure_domainDoesntExist() { + void testFailure_domainDoesntExist() { IllegalArgumentException e = assertThrows( IllegalArgumentException.class, @@ -107,7 +107,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_alreadyLockedDomain_performsNoAction() throws Exception { + void testSuccess_alreadyLockedDomain_performsNoAction() throws Exception { DomainBase domain = persistResource( newDomainBase("example.tld") @@ -119,7 +119,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception { + void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception { DomainBase domain = persistActiveDomain("example.tld"); runCommandForced("example.tld"); assertThat(getMostRecentRegistryLockByRepoId(domain.getRepoId()).get().getRegistrarId()) @@ -127,7 +127,7 @@ public class LockDomainCommandTest extends CommandTestCase { } @Test - public void testFailure_duplicateDomainsAreSpecified() { + void testFailure_duplicateDomainsAreSpecified() { IllegalArgumentException e = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/MutatingCommandTest.java b/core/src/test/java/google/registry/tools/MutatingCommandTest.java index 5d511a569..570ab36e3 100644 --- a/core/src/test/java/google/registry/tools/MutatingCommandTest.java +++ b/core/src/test/java/google/registry/tools/MutatingCommandTest.java @@ -29,30 +29,27 @@ import google.registry.model.registrar.Registrar; import google.registry.testing.AppEngineRule; import java.util.Arrays; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link MutatingCommand}. */ -@RunWith(JUnit4.class) public class MutatingCommandTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - Registrar registrar1; - Registrar registrar2; - Registrar newRegistrar1; - Registrar newRegistrar2; - HostResource host1; - HostResource host2; - HostResource newHost1; - HostResource newHost2; + private Registrar registrar1; + private Registrar registrar2; + private Registrar newRegistrar1; + private Registrar newRegistrar2; + private HostResource host1; + private HostResource host2; + private HostResource newHost1; + private HostResource newHost2; - @Before - public void init() { + @BeforeEach + void beforeEach() { registrar1 = persistNewRegistrar("Registrar1", "Registrar1", Registrar.Type.REAL, 1L); registrar2 = persistNewRegistrar("Registrar2", "Registrar2", Registrar.Type.REAL, 2L); newRegistrar1 = registrar1.asBuilder().setBillingIdentifier(42L).build(); @@ -68,7 +65,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_noChanges() throws Exception { + void testSuccess_noChanges() throws Exception { MutatingCommand command = new MutatingCommand() { @Override protected void init() {} @@ -79,7 +76,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_update() throws Exception { + void testSuccess_update() throws Exception { MutatingCommand command = new MutatingCommand() { @Override public void init() { @@ -112,7 +109,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_create() throws Exception { + void testSuccess_create() throws Exception { ofy().deleteWithoutBackup().entities(Arrays.asList(host1, host2, registrar1, registrar2)).now(); MutatingCommand command = new MutatingCommand() { @Override @@ -146,7 +143,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_delete() throws Exception { + void testSuccess_delete() throws Exception { MutatingCommand command = new MutatingCommand() { @Override protected void init() { @@ -179,7 +176,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_noopUpdate() throws Exception { + void testSuccess_noopUpdate() throws Exception { MutatingCommand command = new MutatingCommand() { @Override protected void init() { @@ -203,7 +200,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_batching() throws Exception { + void testSuccess_batching() throws Exception { MutatingCommand command = new MutatingCommand() { @Override protected void init() { @@ -239,7 +236,7 @@ public class MutatingCommandTest { } @Test - public void testSuccess_batching_partialExecutionWorks() throws Exception { + void testSuccess_batching_partialExecutionWorks() throws Exception { // The expected behavior here is that the first transaction will work and be committed, and // the second transaction will throw an IllegalStateException and not commit. MutatingCommand command = new MutatingCommand() { @@ -281,7 +278,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_nullEntityChange() { + void testFailure_nullEntityChange() { MutatingCommand command = new MutatingCommand() { @Override protected void init() { @@ -292,7 +289,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_updateSameEntityTwice() { + void testFailure_updateSameEntityTwice() { MutatingCommand command = new MutatingCommand() { @Override @@ -309,7 +306,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_updateDifferentLongId() { + void testFailure_updateDifferentLongId() { MutatingCommand command = new MutatingCommand() { @Override protected void init() { @@ -323,7 +320,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_updateDifferentStringId() { + void testFailure_updateDifferentStringId() { MutatingCommand command = new MutatingCommand() { @Override @@ -338,7 +335,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_updateDifferentKind() { + void testFailure_updateDifferentKind() { MutatingCommand command = new MutatingCommand() { @Override @@ -353,7 +350,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_updateModifiedEntity() throws Exception { + void testFailure_updateModifiedEntity() throws Exception { MutatingCommand command = new MutatingCommand() { @Override @@ -368,7 +365,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_createExistingEntity() throws Exception { + void testFailure_createExistingEntity() throws Exception { MutatingCommand command = new MutatingCommand() { @Override @@ -383,7 +380,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_deleteChangedEntity() throws Exception { + void testFailure_deleteChangedEntity() throws Exception { MutatingCommand command = new MutatingCommand() { @Override @@ -398,7 +395,7 @@ public class MutatingCommandTest { } @Test - public void testFailure_deleteRemovedEntity() throws Exception { + void testFailure_deleteRemovedEntity() throws Exception { MutatingCommand command = new MutatingCommand() { @Override diff --git a/core/src/test/java/google/registry/tools/MutatingEppToolCommandTest.java b/core/src/test/java/google/registry/tools/MutatingEppToolCommandTest.java index d2fe9ac69..83690c9c2 100644 --- a/core/src/test/java/google/registry/tools/MutatingEppToolCommandTest.java +++ b/core/src/test/java/google/registry/tools/MutatingEppToolCommandTest.java @@ -21,7 +21,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.tools.server.ToolsTestData; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link MutatingEppToolCommand}. */ public class MutatingEppToolCommandTest extends EppToolCommandTestCase { @@ -50,7 +50,7 @@ public class MutatingEppToolCommandTest extends EppToolCommandTestCase xmlPayloads; + @Parameter List xmlPayloads; @Override void initEppToolCommand() { @@ -51,14 +50,14 @@ public class NonMutatingEppToolCommandTest } @Test - public void testSuccess_doesntPrompt_whenNotForced() throws Exception { + void testSuccess_doesntPrompt_whenNotForced() throws Exception { // The choice of xml file is arbitrary. runCommand("--client=NewRegistrar", ToolsTestData.loadFile("domain_check.xml")); eppVerifier.expectDryRun().verifySent("domain_check.xml"); } @Test - public void testFailure_doesntAllowForce() { + void testFailure_doesntAllowForce() { Exception e = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/RecordAccumulatorTest.java b/core/src/test/java/google/registry/tools/RecordAccumulatorTest.java index 631eff7a6..3fb685123 100644 --- a/core/src/test/java/google/registry/tools/RecordAccumulatorTest.java +++ b/core/src/test/java/google/registry/tools/RecordAccumulatorTest.java @@ -21,26 +21,23 @@ import google.registry.testing.AppEngineRule; import google.registry.tools.EntityWrapper.Property; import java.io.File; import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.io.TempDir; -@RunWith(JUnit4.class) +/** Unit tests for {@link RecordAccumulator}. */ public class RecordAccumulatorTest { private static final int BASE_ID = 1001; - @Rule public final TemporaryFolder tempFs = new TemporaryFolder(); + @TempDir public File tmpDir; - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void testReadDirectory() throws IOException { - File subdir = tempFs.newFolder("folder"); - LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(subdir, "data1")); + void testReadDirectory() throws IOException { + LevelDbFileBuilder builder = new LevelDbFileBuilder(new File(tmpDir, "data1")); // Note that we need to specify property values as "Long" for property comparisons to work // correctly because that's how they are deserialized from protos. @@ -60,7 +57,7 @@ public class RecordAccumulatorTest { builder.addEntity(e2.getEntity()); builder.build(); - builder = new LevelDbFileBuilder(new File(subdir, "data2")); + builder = new LevelDbFileBuilder(new File(tmpDir, "data2")); // Duplicate of the record in the other file. builder.addEntity( @@ -81,7 +78,7 @@ public class RecordAccumulatorTest { builder.build(); ImmutableSet entities = - RecordAccumulator.readDirectory(subdir, any -> true).getEntityWrapperSet(); + RecordAccumulator.readDirectory(tmpDir, any -> true).getEntityWrapperSet(); assertThat(entities).containsExactly(e1, e2, e3); } } diff --git a/core/src/test/java/google/registry/tools/RegistrarContactCommandTest.java b/core/src/test/java/google/registry/tools/RegistrarContactCommandTest.java index 33e4fc6ac..b835e66eb 100644 --- a/core/src/test/java/google/registry/tools/RegistrarContactCommandTest.java +++ b/core/src/test/java/google/registry/tools/RegistrarContactCommandTest.java @@ -32,21 +32,21 @@ import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarContact; import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link RegistrarContactCommand}. */ -public class RegistrarContactCommandTest extends CommandTestCase { +class RegistrarContactCommandTest extends CommandTestCase { private String output; - @Before - public void before() throws Exception { - output = tmpDir.newFile().toString(); + @BeforeEach + void beforeEach() { + output = tmpDir.resolve("temp.dat").toString(); } @Test - public void testList() throws Exception { + void testList() throws Exception { Registrar registrar = loadRegistrar("NewRegistrar"); RegistrarContact.updateContacts( registrar, @@ -72,7 +72,7 @@ public class RegistrarContactCommandTest extends CommandTestCase contacts = ImmutableList.of( new RegistrarContact.Builder() @@ -115,7 +115,7 @@ public class RegistrarContactCommandTest extends CommandTestCase @@ -80,34 +77,33 @@ public class RegistryToolEnvironmentTest { } @Test - public void testFromArgs_missingEnvironmentFlag_throwsIae() { + void testFromArgs_missingEnvironmentFlag_throwsIae() { assertThrows( IllegalArgumentException.class, () -> RegistryToolEnvironment.parseFromArgs(new String[] {})); } @Test - public void testFromArgs_extraEnvFlagAfterCommandName_getsIgnored() { - String[] args = new String[] { - "-e", "alpha", - "registrar_activity_report", - "-e", "1406851199"}; + void testFromArgs_extraEnvFlagAfterCommandName_getsIgnored() { + String[] args = new String[] {"-e", "alpha", "registrar_activity_report", "-e", "1406851199"}; assertThat(RegistryToolEnvironment.parseFromArgs(args)) .isEqualTo(RegistryToolEnvironment.ALPHA); } @Test - public void testFromArgs_loggingFlagWithUnderscores_isntConsideredCommand() { - String[] args = new String[] { - "--logging_properties_file", "my_file.properties", - "-e", "alpha", - "list_tlds"}; + void testFromArgs_loggingFlagWithUnderscores_isntConsideredCommand() { + String[] args = + new String[] { + "--logging_properties_file", "my_file.properties", + "-e", "alpha", + "list_tlds" + }; assertThat(RegistryToolEnvironment.parseFromArgs(args)) .isEqualTo(RegistryToolEnvironment.ALPHA); } @Test - public void testFromArgs_badName_throwsIae() { + void testFromArgs_badName_throwsIae() { assertThrows( IllegalArgumentException.class, () -> RegistryToolEnvironment.parseFromArgs(new String[] {"-e", "alphaville"})); diff --git a/core/src/test/java/google/registry/tools/RenewDomainCommandTest.java b/core/src/test/java/google/registry/tools/RenewDomainCommandTest.java index 261597e37..a7d42002c 100644 --- a/core/src/test/java/google/registry/tools/RenewDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/RenewDomainCommandTest.java @@ -32,26 +32,26 @@ import google.registry.testing.InjectRule; import google.registry.util.Clock; import java.util.List; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.shaded.com.google.common.collect.ImmutableList; /** Unit tests for {@link RenewDomainCommand}. */ public class RenewDomainCommandTest extends EppToolCommandTestCase { - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); private final Clock clock = new FakeClock(DateTime.parse("2015-04-05T05:05:05Z")); - @Before - public void before() { + @BeforeEach + void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); command.clock = clock; } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { persistResource( persistActiveDomain( "domain.tld", @@ -94,7 +94,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase runCommandForced("nonexistent.tld")); assertThat(e) @@ -142,7 +142,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase runCommandForced("deleted.tld")); @@ -150,7 +150,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase runCommandForced("dupe.tld", "dupe.tld")); @@ -158,7 +158,7 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase runCommand("--period 4")); } } diff --git a/core/src/test/java/google/registry/tools/RequestFactoryModuleTest.java b/core/src/test/java/google/registry/tools/RequestFactoryModuleTest.java index 10e447d02..46349e520 100644 --- a/core/src/test/java/google/registry/tools/RequestFactoryModuleTest.java +++ b/core/src/test/java/google/registry/tools/RequestFactoryModuleTest.java @@ -17,8 +17,8 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; import static google.registry.tools.RequestFactoryModule.REQUEST_TIMEOUT_MS; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import com.google.api.client.http.GenericUrl; @@ -28,32 +28,29 @@ import com.google.api.client.http.HttpRequestInitializer; import google.registry.config.RegistryConfig; import google.registry.testing.SystemPropertyRule; import google.registry.util.GoogleCredentialsBundle; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(JUnit4.class) +/** Unit tests for {@link RequestFactoryModule}. */ +@ExtendWith(MockitoExtension.class) public class RequestFactoryModuleTest { - @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); - @Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); + @RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); @Mock public GoogleCredentialsBundle credentialsBundle; @Mock public HttpRequestInitializer httpRequestInitializer; - @Before - public void setUp() { + @BeforeEach + void beforeEach() { RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule); - when(credentialsBundle.getHttpRequestInitializer()).thenReturn(httpRequestInitializer); } @Test - public void test_provideHttpRequestFactory_localhost() throws Exception { + void test_provideHttpRequestFactory_localhost() throws Exception { // Make sure that localhost creates a request factory with an initializer. boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal; RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true; @@ -64,14 +61,15 @@ public class RequestFactoryModuleTest { assertThat(initializer).isNotNull(); HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost")); initializer.initialize(request); - verifyZeroInteractions(httpRequestInitializer); + verifyNoInteractions(httpRequestInitializer); } finally { RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal; } } @Test - public void test_provideHttpRequestFactory_remote() throws Exception { + void test_provideHttpRequestFactory_remote() throws Exception { + when(credentialsBundle.getHttpRequestInitializer()).thenReturn(httpRequestInitializer); // Make sure that example.com creates a request factory with the UNITTEST client id but no boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal; RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false; diff --git a/core/src/test/java/google/registry/tools/ResaveEntitiesCommandTest.java b/core/src/test/java/google/registry/tools/ResaveEntitiesCommandTest.java index dd5076a3f..f7bf68a88 100644 --- a/core/src/test/java/google/registry/tools/ResaveEntitiesCommandTest.java +++ b/core/src/test/java/google/registry/tools/ResaveEntitiesCommandTest.java @@ -25,13 +25,13 @@ import google.registry.model.ImmutableObject; import google.registry.model.contact.ContactResource; import google.registry.model.ofy.CommitLogManifest; import google.registry.model.ofy.CommitLogMutation; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link ResaveEntitiesCommand}. */ -public class ResaveEntitiesCommandTest extends CommandTestCase { +class ResaveEntitiesCommandTest extends CommandTestCase { @Test - public void testSuccess_createsCommitLogs() throws Exception { + void testSuccess_createsCommitLogs() throws Exception { ContactResource contact1 = persistActiveContact("contact1"); ContactResource contact2 = persistActiveContact("contact2"); deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class); diff --git a/core/src/test/java/google/registry/tools/ResaveEnvironmentEntitiesCommandTest.java b/core/src/test/java/google/registry/tools/ResaveEnvironmentEntitiesCommandTest.java index 85f6931d0..e0c56c1fd 100644 --- a/core/src/test/java/google/registry/tools/ResaveEnvironmentEntitiesCommandTest.java +++ b/core/src/test/java/google/registry/tools/ResaveEnvironmentEntitiesCommandTest.java @@ -28,14 +28,14 @@ import google.registry.model.ofy.CommitLogMutation; import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarContact; import google.registry.model.registry.Registry; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link ResaveEnvironmentEntitiesCommand}. */ -public class ResaveEnvironmentEntitiesCommandTest +class ResaveEnvironmentEntitiesCommandTest extends CommandTestCase { @Test - public void testSuccess_noop() throws Exception { + void testSuccess_noop() throws Exception { // Get rid of all the entities that this command runs on so that it does nothing. deleteEntitiesOfTypes( Registry.class, @@ -49,7 +49,7 @@ public class ResaveEnvironmentEntitiesCommandTest } @Test - public void testSuccess_createsCommitLogs() throws Exception { + void testSuccess_createsCommitLogs() throws Exception { createTld("tld"); deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class); assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty(); diff --git a/core/src/test/java/google/registry/tools/ResaveEppResourcesCommandTest.java b/core/src/test/java/google/registry/tools/ResaveEppResourcesCommandTest.java index fd1f3f012..f3f8154f9 100644 --- a/core/src/test/java/google/registry/tools/ResaveEppResourcesCommandTest.java +++ b/core/src/test/java/google/registry/tools/ResaveEppResourcesCommandTest.java @@ -22,13 +22,13 @@ import google.registry.model.ImmutableObject; import google.registry.model.contact.ContactResource; import google.registry.model.ofy.CommitLogManifest; import google.registry.model.ofy.CommitLogMutation; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link ResaveEppResourceCommand}. */ -public class ResaveEppResourcesCommandTest extends CommandTestCase { +class ResaveEppResourcesCommandTest extends CommandTestCase { @Test - public void testSuccess_createsCommitLogs() throws Exception { + void testSuccess_createsCommitLogs() throws Exception { ContactResource contact = persistActiveContact("contact"); deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class); assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty(); diff --git a/core/src/test/java/google/registry/tools/SetNumInstancesCommandTest.java b/core/src/test/java/google/registry/tools/SetNumInstancesCommandTest.java index cab93ecf0..4028806cb 100644 --- a/core/src/test/java/google/registry/tools/SetNumInstancesCommandTest.java +++ b/core/src/test/java/google/registry/tools/SetNumInstancesCommandTest.java @@ -24,29 +24,31 @@ import com.google.common.collect.ImmutableMultimap; import google.registry.testing.AppEngineAdminApiHelper; import google.registry.testing.InjectRule; import google.registry.util.AppEngineServiceUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link SetNumInstancesCommand}. */ public class SetNumInstancesCommandTest extends CommandTestCase { - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); @Mock AppEngineServiceUtils appEngineServiceUtils; private final String projectId = "domain-registry-test"; - @Before - public void before() { + @BeforeEach + void beforeEach() { command = new SetNumInstancesCommand(); command.appEngineServiceUtils = appEngineServiceUtils; command.projectId = projectId; } @Test - public void test_missingService_throwsException() { + void test_missingService_throwsException() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -55,7 +57,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase runCommand("--services=DEFAULT", "--versions=version")); @@ -103,7 +105,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase { +class SetupOteCommandTest extends CommandTestCase { - static final String PASSWORD = "abcdefghijklmnop"; + private static final String PASSWORD = "abcdefghijklmnop"; - DeterministicStringGenerator passwordGenerator = + private DeterministicStringGenerator passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz"); - @Before - public void init() { + @BeforeEach + void beforeEach() { command.passwordGenerator = passwordGenerator; command.clock = new FakeClock(DateTime.parse("2018-07-07TZ")); persistPremiumList("default_sandbox_list", "sandbox,USD 1000"); @@ -133,7 +133,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommandForced( "--ip_allow_list=1.1.1.1", "--registrar=blobio", @@ -159,7 +159,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testSuccess_shortRegistrarName() throws Exception { + void testSuccess_shortRegistrarName() throws Exception { runCommandForced( "--ip_allow_list=1.1.1.1", "--registrar=abc", @@ -185,7 +185,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testSuccess_certificateHash() throws Exception { + void testSuccess_certificateHash() throws Exception { runCommandForced( "--ip_allow_list=1.1.1.1", "--registrar=blobio", @@ -203,7 +203,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipleIps() throws Exception { + void testSuccess_multipleIps() throws Exception { runCommandForced( "--ip_allow_list=1.1.1.1,2.2.2.2", "--registrar=blobio", @@ -230,7 +230,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_missingIpAllowList() { + void testFailure_missingIpAllowList() { ParameterException thrown = assertThrows( ParameterException.class, @@ -243,7 +243,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_missingRegistrar() { + void testFailure_missingRegistrar() { ParameterException thrown = assertThrows( ParameterException.class, @@ -256,7 +256,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_missingCertificateFileAndCertificateHash() { + void testFailure_missingCertificateFileAndCertificateHash() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -270,7 +270,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_suppliedCertificateFileAndCertificateHash() { + void testFailure_suppliedCertificateFileAndCertificateHash() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -288,7 +288,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_missingEmail() { + void testFailure_missingEmail() { ParameterException thrown = assertThrows( ParameterException.class, @@ -301,7 +301,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidCert() { + void testFailure_invalidCert() { CertificateParsingException thrown = assertThrows( CertificateParsingException.class, @@ -315,7 +315,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidRegistrar() { + void testFailure_invalidRegistrar() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -329,7 +329,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_registrarTooShort() { + void testFailure_registrarTooShort() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -343,7 +343,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_registrarTooLong() { + void testFailure_registrarTooLong() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -357,7 +357,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_registrarInvalidCharacter() { + void testFailure_registrarInvalidCharacter() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -371,7 +371,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_tldExists() { + void testFailure_tldExists() { createTld("blobio-sunrise"); IllegalStateException thrown = assertThrows( @@ -386,7 +386,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testSuccess_tldExists_replaceExisting() throws Exception { + void testSuccess_tldExists_replaceExisting() throws Exception { createTld("blobio-sunrise"); runCommandForced( @@ -401,7 +401,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testFailure_registrarExists() { + void testFailure_registrarExists() { Registrar registrar = loadRegistrar("TheRegistrar").asBuilder() .setClientId("blobio-1") .setRegistrarName("blobio-1") @@ -420,7 +420,7 @@ public class SetupOteCommandTest extends CommandTestCase { } @Test - public void testSuccess_registrarExists_replaceExisting() throws Exception { + void testSuccess_registrarExists_replaceExisting() throws Exception { Registrar registrar = loadRegistrar("TheRegistrar").asBuilder() .setClientId("blobio-1") .setRegistrarName("blobio-1") diff --git a/core/src/test/java/google/registry/tools/ShellCommandTest.java b/core/src/test/java/google/registry/tools/ShellCommandTest.java index 2146cba17..3c0a850e7 100644 --- a/core/src/test/java/google/registry/tools/ShellCommandTest.java +++ b/core/src/test/java/google/registry/tools/ShellCommandTest.java @@ -39,43 +39,39 @@ import java.util.ArrayList; import java.util.List; import org.joda.time.DateTime; import org.joda.time.Duration; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@RunWith(JUnit4.class) -public class ShellCommandTest { +/** Unit tests for {@link ShellCommand}. */ +class ShellCommandTest { - @Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); + @RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); CommandRunner cli = mock(CommandRunner.class); - FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ")); + private FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ")); - PrintStream orgStdout; - PrintStream orgStderr; + private PrintStream orgStdout; + private PrintStream orgStderr; - ByteArrayOutputStream stdout; - ByteArrayOutputStream stderr; + private ByteArrayOutputStream stdout; + private ByteArrayOutputStream stderr; - public ShellCommandTest() {} - - @Before - public void setUp() { + @BeforeEach + void beforeEach() { orgStdout = System.out; orgStderr = System.err; } - @After - public void tearDown() { + @AfterEach + void afterEach() { System.setOut(orgStdout); System.setErr(orgStderr); } @Test - public void testParsing() { + void testParsing() { assertThat(ShellCommand.parseCommand("foo bar 123 baz+ // comment \"string data\"")) .isEqualTo(new String[] {"foo", "bar", "123", "baz+", "//", "comment", "string data"}); assertThat(ShellCommand.parseCommand("\"got \\\" escapes?\"")) @@ -87,18 +83,20 @@ public class ShellCommandTest { CommandRunner commandRunner, Duration delay, String... commands) throws Exception { ArrayDeque queue = new ArrayDeque(ImmutableList.copyOf(commands)); BufferedReader bufferedReader = mock(BufferedReader.class); - when(bufferedReader.readLine()).thenAnswer((x) -> { - clock.advanceBy(delay); - if (queue.isEmpty()) { - throw new IOException(); - } - return queue.poll(); - }); + when(bufferedReader.readLine()) + .thenAnswer( + (x) -> { + clock.advanceBy(delay); + if (queue.isEmpty()) { + throw new IOException(); + } + return queue.poll(); + }); return new ShellCommand(bufferedReader, clock, commandRunner); } @Test - public void testCommandProcessing() throws Exception { + void testCommandProcessing() throws Exception { MockCli cli = new MockCli(); ShellCommand shellCommand = createShellCommand(cli, Duration.ZERO, "test1 foo bar", "test2 foo bar"); @@ -110,7 +108,7 @@ public class ShellCommandTest { } @Test - public void testNoIdleWhenInAlpha() throws Exception { + void testNoIdleWhenInAlpha() throws Exception { RegistryToolEnvironment.ALPHA.setup(systemPropertyRule); MockCli cli = new MockCli(); ShellCommand shellCommand = @@ -119,7 +117,7 @@ public class ShellCommandTest { } @Test - public void testNoIdleWhenInSandbox() throws Exception { + void testNoIdleWhenInSandbox() throws Exception { RegistryToolEnvironment.SANDBOX.setup(systemPropertyRule); MockCli cli = new MockCli(); ShellCommand shellCommand = @@ -128,7 +126,7 @@ public class ShellCommandTest { } @Test - public void testIdleWhenOverHourInProduction() throws Exception { + void testIdleWhenOverHourInProduction() throws Exception { RegistryToolEnvironment.PRODUCTION.setup(systemPropertyRule); MockCli cli = new MockCli(); ShellCommand shellCommand = @@ -138,7 +136,7 @@ public class ShellCommandTest { } @Test - public void testNoIdleWhenUnderHourInProduction() throws Exception { + void testNoIdleWhenUnderHourInProduction() throws Exception { RegistryToolEnvironment.PRODUCTION.setup(systemPropertyRule); MockCli cli = new MockCli(); ShellCommand shellCommand = @@ -156,7 +154,7 @@ public class ShellCommandTest { } @Test - public void testMultipleCommandInvocations() throws Exception { + void testMultipleCommandInvocations() throws Exception { try (RegistryCli cli = new RegistryCli("unittest", ImmutableMap.of("test_command", TestCommand.class))) { RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule); @@ -173,7 +171,7 @@ public class ShellCommandTest { } @Test - public void testNonExistentCommand() { + void testNonExistentCommand() { try (RegistryCli cli = new RegistryCli("unittest", ImmutableMap.of("test_command", TestCommand.class))) { @@ -183,9 +181,7 @@ public class ShellCommandTest { } private void performJCommanderCompletorTest( - String line, - int expectedBackMotion, - String... expectedCompletions) { + String line, int expectedBackMotion, String... expectedCompletions) { JCommander jcommander = new JCommander(); jcommander.setProgramName("test"); jcommander.addCommand("help", new HelpCommand(jcommander)); @@ -201,7 +197,7 @@ public class ShellCommandTest { } @Test - public void testCompletion_commands() { + void testCompletion_commands() { performJCommanderCompletorTest("", 0, "testCommand ", "testAnotherCommand ", "help "); performJCommanderCompletorTest("n", 1); performJCommanderCompletorTest("test", 4, "testCommand ", "testAnotherCommand "); @@ -211,7 +207,7 @@ public class ShellCommandTest { } @Test - public void testCompletion_help() { + void testCompletion_help() { performJCommanderCompletorTest("h", 1, "help "); performJCommanderCompletorTest("help ", 0, "testCommand ", "testAnotherCommand ", "help "); performJCommanderCompletorTest("help testC", 5, "testCommand "); @@ -219,7 +215,7 @@ public class ShellCommandTest { } @Test - public void testCompletion_documentation() { + void testCompletion_documentation() { performJCommanderCompletorTest( "testCommand ", 0, @@ -239,7 +235,7 @@ public class ShellCommandTest { } @Test - public void testCompletion_arguments() { + void testCompletion_arguments() { performJCommanderCompletorTest("testCommand -", 1, "-x ", "--xparam ", "--xorg "); performJCommanderCompletorTest("testCommand --wrong", 7); performJCommanderCompletorTest("testCommand noise --", 2, "--xparam ", "--xorg "); @@ -247,7 +243,7 @@ public class ShellCommandTest { } @Test - public void testCompletion_enum() { + void testCompletion_enum() { performJCommanderCompletorTest("testCommand --xorg P", 1, "PRIVATE ", "PUBLIC "); performJCommanderCompletorTest("testCommand --xorg PU", 2, "PUBLIC "); performJCommanderCompletorTest( @@ -255,7 +251,7 @@ public class ShellCommandTest { } @Test - public void testEncapsulatedOutputStream_basicFuncionality() { + void testEncapsulatedOutputStream_basicFuncionality() { ByteArrayOutputStream backing = new ByteArrayOutputStream(); try (PrintStream out = new PrintStream(new ShellCommand.EncapsulatingOutputStream(backing, "out: "))) { @@ -267,7 +263,7 @@ public class ShellCommandTest { } @Test - public void testEncapsulatedOutputStream_emptyStream() { + void testEncapsulatedOutputStream_emptyStream() { ByteArrayOutputStream backing = new ByteArrayOutputStream(); try (PrintStream out = new PrintStream(new ShellCommand.EncapsulatingOutputStream(backing, "out: "))) {} @@ -275,7 +271,7 @@ public class ShellCommandTest { } @Test - public void testEncapsulatedOutput_command() throws Exception { + void testEncapsulatedOutput_command() throws Exception { RegistryToolEnvironment.ALPHA.setup(systemPropertyRule); captureOutput(); ShellCommand shellCommand = @@ -299,7 +295,7 @@ public class ShellCommandTest { } @Test - public void testEncapsulatedOutput_throws() throws Exception { + void testEncapsulatedOutput_throws() throws Exception { RegistryToolEnvironment.ALPHA.setup(systemPropertyRule); captureOutput(); ShellCommand shellCommand = @@ -319,7 +315,7 @@ public class ShellCommandTest { } @Test - public void testEncapsulatedOutput_noCommand() throws Exception { + void testEncapsulatedOutput_noCommand() throws Exception { captureOutput(); ShellCommand shellCommand = createShellCommand( @@ -353,15 +349,13 @@ public class ShellCommandTest { } @Parameter( - names = {"-x", "--xparam"}, - description = "test parameter" - ) + names = {"-x", "--xparam"}, + description = "test parameter") String xparam = "default value"; @Parameter( - names = {"--xorg"}, - description = "test organization" - ) + names = {"--xorg"}, + description = "test organization") OrgType orgType = OrgType.PRIVATE; // List for recording command invocations by run(). @@ -373,7 +367,7 @@ public class ShellCommandTest { @Parameter(description = "normal argument") List args; - public TestCommand() {} + TestCommand() {} @Override public void run() { diff --git a/core/src/test/java/google/registry/tools/UniformRapidSuspensionCommandTest.java b/core/src/test/java/google/registry/tools/UniformRapidSuspensionCommandTest.java index 98f428ecb..184b340f7 100644 --- a/core/src/test/java/google/registry/tools/UniformRapidSuspensionCommandTest.java +++ b/core/src/test/java/google/registry/tools/UniformRapidSuspensionCommandTest.java @@ -29,20 +29,20 @@ import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; import google.registry.persistence.VKey; import javax.xml.bind.annotation.adapters.HexBinaryAdapter; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UniformRapidSuspensionCommand}. */ -public class UniformRapidSuspensionCommandTest +class UniformRapidSuspensionCommandTest extends EppToolCommandTestCase { - HostResource ns1; - HostResource ns2; - HostResource urs1; - HostResource urs2; + private HostResource ns1; + private HostResource ns2; + private HostResource urs1; + private HostResource urs2; - @Before - public void initResources() { + @BeforeEach + void beforeEach() { // Since the command's history client ID must be CharlestonRoad, resave TheRegistrar that way. persistResource( loadRegistrar("TheRegistrar").asBuilder().setClientId("CharlestonRoad").build()); @@ -66,7 +66,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception { + void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception { persistDomainWithHosts(ns1, ns2); runCommandForced( "--domain_name=evil.tld", @@ -86,7 +86,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testCommand_respectsExistingHost() throws Exception { + void testCommand_respectsExistingHost() throws Exception { persistDomainWithHosts(urs2, ns1); runCommandForced("--domain_name=evil.tld", "--hosts=urs1.example.com,urs2.example.com"); eppVerifier @@ -100,7 +100,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testCommand_generatesUndoForUndelegatedDomain() throws Exception { + void testCommand_generatesUndoForUndelegatedDomain() throws Exception { persistActiveDomain("evil.tld"); runCommandForced("--domain_name=evil.tld", "--hosts=urs1.example.com,urs2.example.com"); eppVerifier.verifySentAny(); @@ -110,7 +110,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testCommand_generatesUndoWithLocksToPreserve() throws Exception { + void testCommand_generatesUndoWithLocksToPreserve() throws Exception { persistResource( newDomainBase("evil.tld").asBuilder() .addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED) @@ -123,7 +123,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testUndo_removesLocksReplacesHostsAndDsData() throws Exception { + void testUndo_removesLocksReplacesHostsAndDsData() throws Exception { persistDomainWithHosts(urs1, urs2); runCommandForced( "--domain_name=evil.tld", "--undo", "--hosts=ns1.example.com,ns2.example.com"); @@ -135,7 +135,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testUndo_respectsLocksToPreserveFlag() throws Exception { + void testUndo_respectsLocksToPreserveFlag() throws Exception { persistDomainWithHosts(urs1, urs2); runCommandForced( "--domain_name=evil.tld", @@ -150,7 +150,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testFailure_locksToPreserveWithoutUndo() { + void testFailure_locksToPreserveWithoutUndo() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = assertThrows( @@ -162,7 +162,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testFailure_domainNameRequired() { + void testFailure_domainNameRequired() { persistActiveDomain("evil.tld"); ParameterException thrown = assertThrows( @@ -172,7 +172,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testFailure_extraFieldInDsData() { + void testFailure_extraFieldInDsData() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = assertThrows( @@ -185,7 +185,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testFailure_missingFieldInDsData() { + void testFailure_missingFieldInDsData() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = assertThrows( @@ -198,7 +198,7 @@ public class UniformRapidSuspensionCommandTest } @Test - public void testFailure_malformedDsData() { + void testFailure_malformedDsData() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = assertThrows( diff --git a/core/src/test/java/google/registry/tools/UnlockDomainCommandTest.java b/core/src/test/java/google/registry/tools/UnlockDomainCommandTest.java index cfd8a43ad..e5885d851 100644 --- a/core/src/test/java/google/registry/tools/UnlockDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/UnlockDomainCommandTest.java @@ -40,14 +40,14 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UnlockDomainCommand}. */ -public class UnlockDomainCommandTest extends CommandTestCase { +class UnlockDomainCommandTest extends CommandTestCase { - @Before - public void before() { + @BeforeEach + void beforeEach() { persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L); createTld("tld"); command.registryAdminClientId = "adminreg"; @@ -68,14 +68,14 @@ public class UnlockDomainCommandTest extends CommandTestCase domains = new ArrayList<>(); @@ -108,7 +108,7 @@ public class UnlockDomainCommandTest extends CommandTestCase { - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); private final FakeClock clock = new FakeClock(DateTime.parse("2016-12-06T13:55:01Z")); - @Before - public void before() { + @BeforeEach + void beforeEach() { createTld("tld"); inject.setStaticField(Ofy.class, "clock", clock); command.clock = clock; } @Test - public void test_unrenewTwoDomains_worksSuccessfully() throws Exception { + void test_unrenewTwoDomains_worksSuccessfully() throws Exception { ContactResource contact = persistActiveContact("jd1234"); clock.advanceOneMilli(); persistDomainWithDependentResources( @@ -91,7 +91,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase runCommandForced("--period", "0", "domain.tld")); @@ -163,7 +163,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase runCommandForced("--period", "10", "domain.tld")); @@ -171,7 +171,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase { +class UpdateAllocationTokensCommandTest extends CommandTestCase { @Test - public void testUpdateTlds_setTlds() throws Exception { + void testUpdateTlds_setTlds() throws Exception { AllocationToken token = persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("toRemove")).build()); runCommandForced("--prefix", "token", "--allowed_tlds", "tld,example"); @@ -45,7 +44,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdateTlds_clearTlds() throws Exception { + void testUpdateTlds_clearTlds() throws Exception { AllocationToken token = persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("toRemove")).build()); runCommandForced("--prefix", "token", "--allowed_tlds", ""); @@ -53,7 +52,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdateClientIds_setClientIds() throws Exception { + void testUpdateClientIds_setClientIds() throws Exception { AllocationToken token = persistResource( builderWithPromo().setAllowedClientIds(ImmutableSet.of("toRemove")).build()); @@ -63,7 +62,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdateClientIds_clearClientIds() throws Exception { + void testUpdateClientIds_clearClientIds() throws Exception { AllocationToken token = persistResource( builderWithPromo().setAllowedClientIds(ImmutableSet.of("toRemove")).build()); @@ -72,14 +71,14 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdateDiscountFraction() throws Exception { + void testUpdateDiscountFraction() throws Exception { AllocationToken token = persistResource(builderWithPromo().setDiscountFraction(0.5).build()); runCommandForced("--prefix", "token", "--discount_fraction", "0.15"); assertThat(reloadResource(token).getDiscountFraction()).isEqualTo(0.15); } @Test - public void testUpdateStatusTransitions() throws Exception { + void testUpdateStatusTransitions() throws Exception { DateTime now = DateTime.now(UTC); AllocationToken token = persistResource(builderWithPromo().build()); runCommandForced( @@ -94,7 +93,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdateStatusTransitions_badTransitions() { + void testUpdateStatusTransitions_badTransitions() { DateTime now = DateTime.now(UTC); persistResource(builderWithPromo().build()); IllegalArgumentException thrown = @@ -114,7 +113,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdate_onlyWithPrefix() throws Exception { + void testUpdate_onlyWithPrefix() throws Exception { AllocationToken token = persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("tld")).build()); AllocationToken otherToken = @@ -130,7 +129,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testUpdate_onlyTokensProvided() throws Exception { + void testUpdate_onlyTokensProvided() throws Exception { AllocationToken firstToken = persistResource(builderWithPromo().setAllowedTlds(ImmutableSet.of("tld")).build()); AllocationToken secondToken = @@ -154,7 +153,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testDoNothing() throws Exception { + void testDoNothing() throws Exception { AllocationToken token = persistResource( builderWithPromo() @@ -170,7 +169,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testFailure_bothTokensAndPrefix() { + void testFailure_bothTokensAndPrefix() { assertThat( assertThrows( IllegalArgumentException.class, @@ -180,7 +179,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testFailure_neitherTokensNorPrefix() { + void testFailure_neitherTokensNorPrefix() { assertThat( assertThrows( IllegalArgumentException.class, () -> runCommandForced("--allowed_tlds", "tld"))) @@ -189,7 +188,7 @@ public class UpdateAllocationTokensCommandTest } @Test - public void testFailure_emptyPrefix() { + void testFailure_emptyPrefix() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommandForced("--prefix", "")); assertThat(thrown).hasMessageThat().isEqualTo("Provided prefix should not be blank"); diff --git a/core/src/test/java/google/registry/tools/UpdateCursorsCommandTest.java b/core/src/test/java/google/registry/tools/UpdateCursorsCommandTest.java index f0ac3579b..7586f8f32 100644 --- a/core/src/test/java/google/registry/tools/UpdateCursorsCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateCursorsCommandTest.java @@ -26,16 +26,16 @@ import google.registry.model.common.Cursor.CursorType; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.RegistryNotFoundException; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UpdateCursorsCommand}. */ -public class UpdateCursorsCommandTest extends CommandTestCase { +class UpdateCursorsCommandTest extends CommandTestCase { - Registry registry; + private Registry registry; - @Before - public void before() { + @BeforeEach + void beforeEach() { createTld("foo"); registry = Registry.get("foo"); } @@ -66,33 +66,33 @@ public class UpdateCursorsCommandTest extends CommandTestCase runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar")); } @Test - public void testFailure_badCursorType() { + void testFailure_badCursorType() { ParameterException thrown = assertThrows( ParameterException.class, diff --git a/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java b/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java index 1b2be39f7..192890955 100644 --- a/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java @@ -31,13 +31,13 @@ import google.registry.model.domain.DesignatedContact; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; import google.registry.persistence.VKey; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UpdateDomainCommand}. */ -public class UpdateDomainCommandTest extends EppToolCommandTestCase { +class UpdateDomainCommandTest extends EppToolCommandTestCase { @Test - public void testSuccess_complete() throws Exception { + void testSuccess_complete() throws Exception { runCommandForced( "--client=NewRegistrar", "--add_nameservers=ns1.zdns.google,ns2.zdns.google", @@ -57,7 +57,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase> nameservers = @@ -181,7 +181,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase> nameservers = ImmutableSet.of(host.createVKey()); persistResource( @@ -229,14 +229,14 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase> nameservers = ImmutableSet.of(host.createVKey()); persistResource( @@ -280,7 +280,7 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase +class UpdatePremiumListCommandTest extends CreateOrUpdatePremiumListCommandTestCase { @Mock AppEngineConnection connection; - String premiumTermsPath; + private String premiumTermsPath; String premiumTermsCsv; - String servletPath; + private String servletPath; - @Before - public void init() throws Exception { + @BeforeEach + void beforeEach() throws Exception { command.setConnection(connection); servletPath = "/_dr/admin/updatePremiumList"; premiumTermsPath = @@ -52,7 +52,7 @@ public class UpdatePremiumListCommandTest } @Test - public void testRun() throws Exception { + void testRun() throws Exception { runCommandForced("-i=" + premiumTermsPath, "-n=foo"); verifySentParams( connection, @@ -61,7 +61,7 @@ public class UpdatePremiumListCommandTest } @Test - public void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception { + void testRun_noProvidedName_usesBasenameOfInputFile() throws Exception { runCommandForced("-i=" + premiumTermsPath); assertInStdout("Successfully"); verifySentParams( diff --git a/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java b/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java index c1d679638..80c2f59b9 100644 --- a/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java @@ -39,13 +39,13 @@ import google.registry.util.CidrAddressBlock; import java.util.Optional; import org.joda.money.CurrencyUnit; import org.joda.time.DateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UpdateRegistrarCommand}. */ -public class UpdateRegistrarCommandTest extends CommandTestCase { +class UpdateRegistrarCommandTest extends CommandTestCase { @Test - public void testSuccess_alsoUpdateInCloudSql() throws Exception { + void testSuccess_alsoUpdateInCloudSql() throws Exception { assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(loadRegistrar("NewRegistrar"))); runCommand("--password=some_password", "--force", "NewRegistrar"); @@ -58,14 +58,14 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar")); } @Test - public void testFailure_invalidRegistrarState() { + void testFailure_invalidRegistrarState() { assertThrows( ParameterException.class, () -> runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar")); } @Test - public void testFailure_negativeIanaId() { + void testFailure_negativeIanaId() { assertThrows( IllegalArgumentException.class, () -> runCommand("--iana_id=-1", "--force", "NewRegistrar")); } @Test - public void testFailure_nonIntegerIanaId() { + void testFailure_nonIntegerIanaId() { assertThrows( ParameterException.class, () -> runCommand("--iana_id=ABC123", "--force", "NewRegistrar")); } @Test - public void testFailure_negativeBillingId() { + void testFailure_negativeBillingId() { assertThrows( IllegalArgumentException.class, () -> runCommand("--billing_id=-1", "--force", "NewRegistrar")); } @Test - public void testFailure_nonIntegerBillingId() { + void testFailure_nonIntegerBillingId() { assertThrows( ParameterException.class, () -> runCommand("--billing_id=ABC123", "--force", "NewRegistrar")); } @Test - public void testFailure_passcodeTooShort() { + void testFailure_passcodeTooShort() { assertThrows( IllegalArgumentException.class, () -> runCommand("--passcode=0123", "--force", "NewRegistrar")); } @Test - public void testFailure_passcodeTooLong() { + void testFailure_passcodeTooLong() { assertThrows( IllegalArgumentException.class, () -> runCommand("--passcode=012345", "--force", "NewRegistrar")); } @Test - public void testFailure_invalidPasscode() { + void testFailure_invalidPasscode() { assertThrows( IllegalArgumentException.class, () -> runCommand("--passcode=code1", "--force", "NewRegistrar")); } @Test - public void testFailure_allowedTldDoesNotExist() { + void testFailure_allowedTldDoesNotExist() { assertThrows( IllegalArgumentException.class, () -> runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar")); } @Test - public void testFailure_addAllowedTldDoesNotExist() { + void testFailure_addAllowedTldDoesNotExist() { assertThrows( IllegalArgumentException.class, () -> runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar")); } @Test - public void testFailure_allowedTldsAndAddAllowedTlds() { + void testFailure_allowedTldsAndAddAllowedTlds() { assertThrows( IllegalArgumentException.class, () -> @@ -623,7 +623,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--ip_allow_list=foobarbaz", "--force", "NewRegistrar")); } @Test - public void testFailure_invalidCertFileContents() { + void testFailure_invalidCertFileContents() { assertThrows( Exception.class, () -> runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar")); } @Test - public void testFailure_certHashAndCertFile() { + void testFailure_certHashAndCertFile() { assertThrows( IllegalArgumentException.class, () -> @@ -679,12 +679,12 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--force")); } @Test - public void testFailure_missingStreetLines() { + void testFailure_missingStreetLines() { assertThrows( IllegalArgumentException.class, () -> @@ -698,7 +698,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -714,7 +714,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -730,7 +730,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -746,7 +746,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -762,7 +762,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -779,7 +779,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -797,7 +797,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase @@ -812,21 +812,21 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar")); } @Test - public void testFailure_doesNotExist() { + void testFailure_doesNotExist() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("--force", "ClientZ")); assertThat(thrown).hasMessageThat().contains("Registrar ClientZ not found"); } @Test - public void testFailure_registrarNameSimilarToExisting() { + void testFailure_registrarNameSimilarToExisting() { // Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by // AppEngineRule. assertThrows( @@ -835,7 +835,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase { +class UpdateReservedListCommandTest + extends CreateOrUpdateReservedListCommandTestCase { - @Before - public void setup() { + @BeforeEach + void beforeEach() { populateInitialReservedListInDatastore(true); } @@ -60,17 +60,17 @@ public class UpdateReservedListCommandTest extends } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runSuccessfulUpdateTest("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath); } @Test - public void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception { + void testSuccess_unspecifiedNameDefaultsToFileName() throws Exception { runSuccessfulUpdateTest("--input=" + reservedTermsPath); } @Test - public void testSuccess_lastUpdateTime_updatedCorrectly() throws Exception { + void testSuccess_lastUpdateTime_updatedCorrectly() throws Exception { ReservedList original = ReservedList.get("xn--q9jyb4c_common-reserved").get(); runCommandForced("--input=" + reservedTermsPath); ReservedList updated = ReservedList.get("xn--q9jyb4c_common-reserved").get(); @@ -80,7 +80,7 @@ public class UpdateReservedListCommandTest extends } @Test - public void testSuccess_shouldPublish_setToFalseCorrectly() throws Exception { + void testSuccess_shouldPublish_setToFalseCorrectly() throws Exception { runSuccessfulUpdateTest("--input=" + reservedTermsPath, "--should_publish=false"); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); ReservedList reservedList = ReservedList.get("xn--q9jyb4c_common-reserved").get(); @@ -88,7 +88,7 @@ public class UpdateReservedListCommandTest extends } @Test - public void testSuccess_shouldPublish_doesntOverrideFalseIfNotSpecified() throws Exception { + void testSuccess_shouldPublish_doesntOverrideFalseIfNotSpecified() throws Exception { populateInitialReservedListInDatastore(false); runCommandForced("--input=" + reservedTermsPath); assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent(); @@ -107,7 +107,7 @@ public class UpdateReservedListCommandTest extends } @Test - public void testFailure_reservedListDoesntExist() { + void testFailure_reservedListDoesntExist() { String errorMessage = "Could not update reserved list xn--q9jyb4c_poobah because it doesn't exist."; IllegalArgumentException thrown = @@ -119,7 +119,7 @@ public class UpdateReservedListCommandTest extends } @Test - public void testSaveToCloudSql_succeeds() throws Exception { + void testSaveToCloudSql_succeeds() throws Exception { populateInitialReservedListInCloudSql(true); runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath); verifyXnq9jyb4cInDatastore(); @@ -127,7 +127,7 @@ public class UpdateReservedListCommandTest extends } @Test - public void testSaveToCloudSql_succeedsEvenPreviousListNotExist() throws Exception { + void testSaveToCloudSql_succeedsEvenPreviousListNotExist() throws Exception { // Note that, during the dual-write phase, we always save the reserved list to Cloud SQL without // checking if there is a list with same name. This is to backfill the existing list in Cloud // Datastore when we update it. diff --git a/core/src/test/java/google/registry/tools/UpdateServerLocksCommandTest.java b/core/src/test/java/google/registry/tools/UpdateServerLocksCommandTest.java index ff3e4620b..e05df9d78 100644 --- a/core/src/test/java/google/registry/tools/UpdateServerLocksCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateServerLocksCommandTest.java @@ -17,48 +17,48 @@ package google.registry.tools; import static org.junit.Assert.assertThrows; import com.beust.jcommander.ParameterException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UpdateServerLocksCommand}. */ -public class UpdateServerLocksCommandTest extends EppToolCommandTestCase { +class UpdateServerLocksCommandTest extends EppToolCommandTestCase { @Test - public void testSuccess_applyOne() throws Exception { + void testSuccess_applyOne() throws Exception { runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", "--domain_name=example.tld", "--apply=serverRenewProhibited"); eppVerifier.verifySent("update_server_locks_apply_one.xml"); } @Test - public void testSuccess_multipleWordReason() throws Exception { + void testSuccess_multipleWordReason() throws Exception { runCommandForced("--client=NewRegistrar", "--registrar_request=false", "--reason=\"Test this\"", "--domain_name=example.tld", "--apply=serverRenewProhibited"); eppVerifier.verifySent("update_server_locks_multiple_word_reason.xml"); } @Test - public void testSuccess_removeOne() throws Exception { + void testSuccess_removeOne() throws Exception { runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", "--domain_name=example.tld", "--remove=serverRenewProhibited"); eppVerifier.verifySent("update_server_locks_remove_one.xml"); } @Test - public void testSuccess_applyAll() throws Exception { + void testSuccess_applyAll() throws Exception { runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", "--domain_name=example.tld", "--apply=all"); eppVerifier.verifySent("update_server_locks_apply_all.xml"); } @Test - public void testSuccess_removeAll() throws Exception { + void testSuccess_removeAll() throws Exception { runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", "--domain_name=example.tld", "--remove=all"); eppVerifier.verifySent("update_server_locks_remove_all.xml"); } @Test - public void testFailure_applyAllRemoveOne_failsDueToOverlap() { + void testFailure_applyAllRemoveOne_failsDueToOverlap() { assertThrows( IllegalArgumentException.class, () -> @@ -72,7 +72,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase @@ -115,7 +115,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase @@ -130,7 +130,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase @@ -142,7 +142,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase @@ -156,7 +156,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase @@ -168,7 +168,7 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase diff --git a/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java b/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java index adca0723b..df7cb1d05 100644 --- a/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java @@ -41,16 +41,16 @@ import google.registry.model.registry.label.PremiumList; import org.joda.money.Money; import org.joda.time.DateTime; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UpdateTldCommand}. */ -public class UpdateTldCommandTest extends CommandTestCase { +class UpdateTldCommandTest extends CommandTestCase { private final DateTime now = DateTime.now(UTC); - @Before - public void initTest() { + @BeforeEach + void beforeEach() { persistReservedList("common_abuse", "baa,FULLY_BLOCKED"); persistReservedList("xn--q9jyb4c_abuse", "lamb,FULLY_BLOCKED"); persistReservedList("tld_banned", "kilo,FULLY_BLOCKED", "lima,FULLY_BLOCKED"); @@ -63,7 +63,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_tldStateTransitions() throws Exception { + void testSuccess_tldStateTransitions() throws Exception { DateTime sunriseStart = now; DateTime quietPeriodStart = sunriseStart.plusMonths(2); DateTime gaStart = quietPeriodStart.plusWeeks(1); @@ -88,7 +88,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setTldState() throws Exception { + void testSuccess_setTldState() throws Exception { persistResource( Registry.get("xn--q9jyb4c") .asBuilder() @@ -100,7 +100,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_renewBillingCostTransitions() throws Exception { + void testSuccess_renewBillingCostTransitions() throws Exception { DateTime later = now.plusMonths(1); runCommandForced( String.format( @@ -122,7 +122,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_multipleArguments() throws Exception { + void testSuccess_multipleArguments() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getAddGracePeriodLength()) .isNotEqualTo(standardMinutes(5)); createTld("example"); @@ -135,7 +135,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_addGracePeriodFlag() throws Exception { + void testSuccess_addGracePeriodFlag() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getAddGracePeriodLength()) .isNotEqualTo(standardMinutes(5)); runCommandForced("--add_grace_period=PT300S", "xn--q9jyb4c"); @@ -143,7 +143,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_redemptionGracePeriodFlag() throws Exception { + void testSuccess_redemptionGracePeriodFlag() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getRedemptionGracePeriodLength()) .isNotEqualTo(standardMinutes(5)); runCommandForced("--redemption_grace_period=PT300S", "xn--q9jyb4c"); @@ -152,7 +152,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_pendingDeleteLengthFlag() throws Exception { + void testSuccess_pendingDeleteLengthFlag() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getPendingDeleteLength()) .isNotEqualTo(standardMinutes(5)); runCommandForced("--pending_delete_length=PT300S", "xn--q9jyb4c"); @@ -160,14 +160,14 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_dnsWriter() throws Exception { + void testSuccess_dnsWriter() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("VoidDnsWriter"); runCommandForced("--dns_writers=FooDnsWriter", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("FooDnsWriter"); } @Test - public void testSuccess_multipleDnsWriters() throws Exception { + void testSuccess_multipleDnsWriters() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("VoidDnsWriter"); runCommandForced("--dns_writers=FooDnsWriter,VoidDnsWriter", "xn--q9jyb4c"); @@ -176,32 +176,32 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_escrow() throws Exception { + void testSuccess_escrow() throws Exception { runCommandForced("--escrow=true", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getEscrowEnabled()).isTrue(); } @Test - public void testSuccess_noEscrow() throws Exception { + void testSuccess_noEscrow() throws Exception { runCommandForced("--escrow=false", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getEscrowEnabled()).isFalse(); } @Test - public void testSuccess_createBillingCostFlag() throws Exception { + void testSuccess_createBillingCostFlag() throws Exception { runCommandForced("--create_billing_cost=\"USD 42.42\"", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost()).isEqualTo(Money.of(USD, 42.42)); } @Test - public void testSuccess_restoreBillingCostFlag() throws Exception { + void testSuccess_restoreBillingCostFlag() throws Exception { runCommandForced("--restore_billing_cost=\"USD 42.42\"", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getStandardRestoreCost()) .isEqualTo(Money.of(USD, 42.42)); } @Test - public void testSuccess_nonUsdBillingCostFlag() throws Exception { + void testSuccess_nonUsdBillingCostFlag() throws Exception { persistResource( Registry.get("xn--q9jyb4c") .asBuilder() @@ -228,27 +228,27 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setLordnUsername() throws Exception { + void testSuccess_setLordnUsername() throws Exception { runCommandForced("--lordn_username=lordn000", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getLordnUsername()).isEqualTo("lordn000"); } @Test - public void testSuccess_setOptionalParamsNullString() throws Exception { + void testSuccess_setOptionalParamsNullString() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder().setLordnUsername("lordn000").build()); runCommandForced("--lordn_username=null", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getLordnUsername()).isNull(); } @Test - public void testSuccess_setOptionalParamsEmptyString() throws Exception { + void testSuccess_setOptionalParamsEmptyString() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder().setLordnUsername("lordn000").build()); runCommandForced("--lordn_username=", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getLordnUsername()).isNull(); } @Test - public void testSuccess_setReservedLists() throws Exception { + void testSuccess_setReservedLists() throws Exception { runCommandForced("--reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName)) @@ -256,7 +256,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setReservedListsOverwrites() throws Exception { + void testSuccess_setReservedListsOverwrites() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); @@ -266,7 +266,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_addReservedLists() throws Exception { + void testSuccess_addReservedLists() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1")) .build()); @@ -276,7 +276,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_removeAllReservedLists() throws Exception { + void testSuccess_removeAllReservedLists() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); @@ -285,7 +285,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_removeSomeReservedLists() throws Exception { + void testSuccess_removeSomeReservedLists() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); @@ -295,14 +295,14 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setAllowedRegistrants() throws Exception { + void testSuccess_setAllowedRegistrants() throws Exception { runCommandForced("--allowed_registrants=alice,bob", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getAllowedRegistrantContactIds()) .containsExactly("alice", "bob"); } @Test - public void testSuccess_setAllowedRegistrantsOverwrites() throws Exception { + void testSuccess_setAllowedRegistrantsOverwrites() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("jane", "john")) @@ -313,7 +313,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_addAllowedRegistrants() throws Exception { + void testSuccess_addAllowedRegistrants() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice")) @@ -324,7 +324,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_removeAllAllowedRegistrants() throws Exception { + void testSuccess_removeAllAllowedRegistrants() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob")) @@ -334,7 +334,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_removeSomeAllowedRegistrants() throws Exception { + void testSuccess_removeSomeAllowedRegistrants() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob")) @@ -344,14 +344,14 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_setAllowedNameservers() throws Exception { + void testSuccess_setAllowedNameservers() throws Exception { runCommandForced("--allowed_nameservers=ns1.example.com,ns2.example.com", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getAllowedFullyQualifiedHostNames()) .containsExactly("ns1.example.com", "ns2.example.com"); } @Test - public void testSuccess_setAllowedNameserversOverwrites() throws Exception { + void testSuccess_setAllowedNameserversOverwrites() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedFullyQualifiedHostNames( @@ -363,7 +363,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_addAllowedNameservers() throws Exception { + void testSuccess_addAllowedNameservers() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.com")) @@ -374,7 +374,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_removeAllAllowedNameservers() throws Exception { + void testSuccess_removeAllAllowedNameservers() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedFullyQualifiedHostNames( @@ -385,7 +385,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_removeSomeAllowedNameservers() throws Exception { + void testSuccess_removeSomeAllowedNameservers() throws Exception { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedFullyQualifiedHostNames( @@ -397,7 +397,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidAddGracePeriod() { + void testFailure_invalidAddGracePeriod() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -406,7 +406,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidRedemptionGracePeriod() { + void testFailure_invalidRedemptionGracePeriod() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -415,7 +415,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidPendingDeleteLength() { + void testFailure_invalidPendingDeleteLength() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -424,7 +424,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidTldState() { + void testFailure_invalidTldState() { ParameterException thrown = assertThrows( ParameterException.class, @@ -437,7 +437,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidTldStateTransitionTime() { + void testFailure_invalidTldStateTransitionTime() { ParameterException thrown = assertThrows( ParameterException.class, @@ -449,7 +449,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_tldStatesOutOfOrder() { + void testFailure_tldStatesOutOfOrder() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -463,7 +463,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_duplicateTldStateTransitions() { + void testFailure_duplicateTldStateTransitions() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -477,7 +477,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_duplicateTldStateTransitionTimes() { + void testFailure_duplicateTldStateTransitionTimes() { ParameterException thrown = assertThrows( ParameterException.class, @@ -492,7 +492,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_outOfOrderTldStateTransitionTimes() { + void testFailure_outOfOrderTldStateTransitionTimes() { ParameterException thrown = assertThrows( ParameterException.class, @@ -508,7 +508,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_bothTldStateFlags() { + void testFailure_bothTldStateFlags() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -525,7 +525,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setCurrentTldState_outOfOrder() { + void testFailure_setCurrentTldState_outOfOrder() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setTldStateTransitions( @@ -541,7 +541,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setCurrentTldState_laterTransitionScheduled() { + void testFailure_setCurrentTldState_laterTransitionScheduled() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setTldStateTransitions( @@ -559,7 +559,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setCurrentTldState_inProduction() { + void testFailure_setCurrentTldState_inProduction() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setTldStateTransitions( @@ -582,7 +582,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidRenewBillingCost() { + void testFailure_invalidRenewBillingCost() { ParameterException thrown = assertThrows( ParameterException.class, @@ -596,7 +596,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_negativeRenewBillingCost() { + void testFailure_negativeRenewBillingCost() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -608,7 +608,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_invalidRenewCostTransitionTime() { + void testFailure_invalidRenewCostTransitionTime() { ParameterException thrown = assertThrows( ParameterException.class, @@ -620,7 +620,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_duplicateRenewCostTransitionTimes() { + void testFailure_duplicateRenewCostTransitionTimes() { ParameterException thrown = assertThrows( ParameterException.class, @@ -635,7 +635,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_outOfOrderRenewCostTransitionTimes() { + void testFailure_outOfOrderRenewCostTransitionTimes() { ParameterException thrown = assertThrows( ParameterException.class, @@ -651,7 +651,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_noTldName() { + void testFailure_noTldName() { ParameterException thrown = assertThrows(ParameterException.class, this::runCommandForced); assertThat(thrown) .hasMessageThat() @@ -659,14 +659,14 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_oneTldDoesNotExist() { + void testFailure_oneTldDoesNotExist() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommandForced("foo", "xn--q9jyb4c")); assertThat(thrown).hasMessageThat().contains("TLD foo does not exist"); } @Test - public void testFailure_duplicateArguments() { + void testFailure_duplicateArguments() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> runCommandForced("xn--q9jyb4c", "xn--q9jyb4c")); @@ -674,14 +674,14 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_tldDoesNotExist() { + void testFailure_tldDoesNotExist() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommandForced("foobarbaz")); assertThat(thrown).hasMessageThat().contains("TLD foobarbaz does not exist"); } @Test - public void testFailure_specifiedDnsWriter_doesntExist() { + void testFailure_specifiedDnsWriter_doesntExist() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -692,7 +692,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setNonExistentReservedLists() { + void testFailure_setNonExistentReservedLists() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -703,7 +703,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantAddDuplicateReservedList() { + void testFailure_cantAddDuplicateReservedList() { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); @@ -715,7 +715,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantRemoveReservedListThatIsntPresent() { + void testFailure_cantRemoveReservedListThatIsntPresent() { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); @@ -727,7 +727,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantAddAndRemoveSameReservedListSimultaneously() { + void testFailure_cantAddAndRemoveSameReservedListSimultaneously() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -740,7 +740,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantAddDuplicateAllowedRegistrants() { + void testFailure_cantAddDuplicateAllowedRegistrants() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob")) @@ -753,7 +753,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantRemoveAllowedRegistrantThatIsntPresent() { + void testFailure_cantRemoveAllowedRegistrantThatIsntPresent() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice")) @@ -766,7 +766,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() { + void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -779,7 +779,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantAddDuplicateAllowedNameservers() { + void testFailure_cantAddDuplicateAllowedNameservers() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedFullyQualifiedHostNames( @@ -793,7 +793,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantRemoveAllowedNameserverThatIsntPresent() { + void testFailure_cantRemoveAllowedNameserverThatIsntPresent() { persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setAllowedFullyQualifiedHostNames( @@ -807,7 +807,7 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() { + void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -820,33 +820,33 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_canSetRoidSuffixToWhatItAlreadyIs() throws Exception { + void testSuccess_canSetRoidSuffixToWhatItAlreadyIs() throws Exception { createTld("foo", "BLAH"); runCommandForced("--roid_suffix=BLAH", "foo"); assertThat(Registry.get("foo").getRoidSuffix()).isEqualTo("BLAH"); } @Test - public void testSuccess_updateRoidSuffix() throws Exception { + void testSuccess_updateRoidSuffix() throws Exception { createTld("foo", "ARGLE"); runCommandForced("--roid_suffix=BARGLE", "foo"); assertThat(Registry.get("foo").getRoidSuffix()).isEqualTo("BARGLE"); } @Test - public void testSuccess_removePremiumListWithNull() throws Exception { + void testSuccess_removePremiumListWithNull() throws Exception { runCommandForced("--premium_list=null", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getPremiumList()).isNull(); } @Test - public void testSuccess_removePremiumListWithBlank() throws Exception { + void testSuccess_removePremiumListWithBlank() throws Exception { runCommandForced("--premium_list=", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getPremiumList()).isNull(); } @Test - public void testSuccess_premiumListNotRemovedWhenNotSpecified() throws Exception { + void testSuccess_premiumListNotRemovedWhenNotSpecified() throws Exception { runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c"); Key premiumListKey = Registry.get("xn--q9jyb4c").getPremiumList(); assertThat(premiumListKey).isNotNull(); @@ -854,48 +854,48 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testSuccess_driveFolderId_notRemovedWhenNotSpecified() throws Exception { + void testSuccess_driveFolderId_notRemovedWhenNotSpecified() throws Exception { persistResource(Registry.get("xn--q9jyb4c").asBuilder().setDriveFolderId("foobar").build()); runCommandForced("xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getDriveFolderId()).isEqualTo("foobar"); } @Test - public void testSuccess_setCommonReservedListOnTld() throws Exception { + void testSuccess_setCommonReservedListOnTld() throws Exception { runSuccessfulReservedListsTest("common_abuse"); } @Test - public void testSuccess_setTldSpecificReservedListOnTld() throws Exception { + void testSuccess_setTldSpecificReservedListOnTld() throws Exception { runSuccessfulReservedListsTest("xn--q9jyb4c_abuse"); } @Test - public void testSuccess_setCommonReservedListAndTldSpecificReservedListOnTld() throws Exception { + void testSuccess_setCommonReservedListAndTldSpecificReservedListOnTld() throws Exception { runSuccessfulReservedListsTest("common_abuse,xn--q9jyb4c_abuse"); } @Test - public void testFailure_setReservedListFromOtherTld() { + void testFailure_setReservedListFromOtherTld() { runFailureReservedListsTest("tld_banned", IllegalArgumentException.class, "The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c"); } @Test - public void testSuccess_setReservedListFromOtherTld_withOverride() throws Exception { + void testSuccess_setReservedListFromOtherTld_withOverride() throws Exception { runReservedListsTestOverride("tld_banned"); } @Test - public void testFailure_setCommonAndReservedListFromOtherTld() { + void testFailure_setCommonAndReservedListFromOtherTld() { runFailureReservedListsTest("common_abuse,tld_banned", IllegalArgumentException.class, "The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c"); } @Test - public void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception { + void testSuccess_setCommonAndReservedListFromOtherTld_withOverride() throws Exception { runReservedListsTestOverride("common_abuse,tld_banned"); String errMsg = "Error overridden: The reserved list(s) tld_banned " @@ -904,37 +904,37 @@ public class UpdateTldCommandTest extends CommandTestCase { } @Test - public void testFailure_setMultipleReservedListsFromOtherTld() { + void testFailure_setMultipleReservedListsFromOtherTld() { runFailureReservedListsTest("tld_banned,soy_expurgated", IllegalArgumentException.class, "The reserved list(s) tld_banned, soy_expurgated cannot be applied to the tld xn--q9jyb4c"); } @Test - public void testSuccess_setMultipleReservedListsFromOtherTld_withOverride() throws Exception { + void testSuccess_setMultipleReservedListsFromOtherTld_withOverride() throws Exception { runReservedListsTestOverride("tld_banned,soy_expurgated"); } @Test - public void testSuccess_setPremiumList() throws Exception { + void testSuccess_setPremiumList() throws Exception { runCommandForced("--premium_list=xn--q9jyb4c", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getPremiumList().getName()).isEqualTo("xn--q9jyb4c"); } @Test - public void testSuccess_setDriveFolderIdToValue() throws Exception { + void testSuccess_setDriveFolderIdToValue() throws Exception { runCommandForced("--drive_folder_id=madmax2030", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getDriveFolderId()).isEqualTo("madmax2030"); } @Test - public void testSuccess_setDriveFolderIdToNull() throws Exception { + void testSuccess_setDriveFolderIdToNull() throws Exception { runCommandForced("--drive_folder_id=null", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getDriveFolderId()).isNull(); } @Test - public void testFailure_setPremiumListThatDoesntExist() { + void testFailure_setPremiumListThatDoesntExist() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java b/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java index 844d6c115..3243d4637 100644 --- a/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java +++ b/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java @@ -21,13 +21,13 @@ import static org.junit.Assert.assertThrows; import google.registry.model.tmch.ClaimsListShard; import java.io.FileNotFoundException; import org.joda.time.DateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Unit tests for {@link UploadClaimsListCommand}. */ -public class UploadClaimsListCommandTest extends CommandTestCase { +class UploadClaimsListCommandTest extends CommandTestCase { @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { String filename = writeToTmpFile( "1,2012-08-16T00:00:00.0Z", "DNL,lookup-key,insertion-datetime", @@ -47,7 +47,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", "nonexistent_file.csv")); } @Test - public void testFailure_noFileNamePassed() { + void testFailure_noFileNamePassed() { assertThrows(IllegalArgumentException.class, () -> runCommand("--force")); } @Test - public void testFailure_tooManyArguments() { + void testFailure_tooManyArguments() { assertThrows(IllegalArgumentException.class, () -> runCommand("--force", "foo", "bar")); } } diff --git a/core/src/test/java/google/registry/tools/ValidateEscrowDepositCommandTest.java b/core/src/test/java/google/registry/tools/ValidateEscrowDepositCommandTest.java index 9242dbe24..4edc719e0 100644 --- a/core/src/test/java/google/registry/tools/ValidateEscrowDepositCommandTest.java +++ b/core/src/test/java/google/registry/tools/ValidateEscrowDepositCommandTest.java @@ -19,17 +19,13 @@ import static org.junit.Assert.assertThrows; import google.registry.rde.RdeTestData; import google.registry.xml.XmlException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link ValidateEscrowDepositCommand}. */ -@RunWith(JUnit4.class) -public class ValidateEscrowDepositCommandTest - extends CommandTestCase { +class ValidateEscrowDepositCommandTest extends CommandTestCase { @Test - public void testRun_plainXml() throws Exception { + void testRun_plainXml() throws Exception { String file = writeToTmpFile(RdeTestData.loadBytes("deposit_full.xml").read()); runCommand("--input=" + file); assertThat(getStdoutAsString()).isEqualTo("" @@ -64,7 +60,7 @@ public class ValidateEscrowDepositCommandTest } @Test - public void testRun_plainXml_badReference() throws Exception { + void testRun_plainXml_badReference() throws Exception { String file = writeToTmpFile(RdeTestData.loadBytes("deposit_full_badref.xml").read()); runCommand("--input=" + file); assertThat(getStdoutAsString()).isEqualTo("" @@ -100,7 +96,7 @@ public class ValidateEscrowDepositCommandTest } @Test - public void testRun_badXml() throws Exception { + void testRun_badXml() throws Exception { String file = writeToTmpFile(RdeTestData.loadFile("deposit_full.xml").substring(0, 2000)); XmlException thrown = assertThrows(XmlException.class, () -> runCommand("--input=" + file)); assertThat(thrown) diff --git a/core/src/test/java/google/registry/tools/ValidateLoginCredentialsCommandTest.java b/core/src/test/java/google/registry/tools/ValidateLoginCredentialsCommandTest.java index 194929257..e4437dd7d 100644 --- a/core/src/test/java/google/registry/tools/ValidateLoginCredentialsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ValidateLoginCredentialsCommandTest.java @@ -31,19 +31,20 @@ import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar.State; import google.registry.testing.CertificateSamples; import google.registry.util.CidrAddressBlock; -import org.junit.Before; -import org.junit.Test; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link ValidateLoginCredentialsCommand}. */ -public class ValidateLoginCredentialsCommandTest - extends CommandTestCase { +class ValidateLoginCredentialsCommandTest extends CommandTestCase { private static final String PASSWORD = "foo-BAR2"; private static final String CERT_HASH = CertificateSamples.SAMPLE_CERT_HASH; private static final String CLIENT_IP = "1.2.3.4"; - @Before - public void init() { + @BeforeEach + void beforeEach() { createTld("tld"); persistResource( loadRegistrar("NewRegistrar") @@ -57,7 +58,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testSuccess() throws Exception { + void testSuccess() throws Exception { runCommand( "--client=NewRegistrar", "--password=" + PASSWORD, @@ -66,7 +67,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_registrarIsDisabled() { + void testFailure_registrarIsDisabled() { persistResource( Registrar.loadByClientId("NewRegistrar") .get() @@ -88,7 +89,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_loginWithBadPassword() { + void testFailure_loginWithBadPassword() { EppException thrown = assertThrows( BadRegistrarPasswordException.class, @@ -102,7 +103,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_loginWithBadCertificateHash() { + void testFailure_loginWithBadCertificateHash() { EppException thrown = assertThrows( EppException.class, @@ -116,7 +117,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_loginWithBadIp() { + void testFailure_loginWithBadIp() { EppException thrown = assertThrows( EppException.class, @@ -130,7 +131,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_missingClientId() { + void testFailure_missingClientId() { assertThrows( ParameterException.class, () -> @@ -139,7 +140,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_missingPassword() { + void testFailure_missingPassword() { assertThrows( ParameterException.class, () -> @@ -148,7 +149,7 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_unknownFlag() { + void testFailure_unknownFlag() { assertThrows( ParameterException.class, () -> @@ -161,7 +162,8 @@ public class ValidateLoginCredentialsCommandTest } @Test - public void testFailure_certHashAndCertFile() { + void testFailure_certHashAndCertFile() throws Exception { + Path certFile = Files.createFile(tmpDir.resolve("temp.crt")); assertThrows( IllegalArgumentException.class, () -> @@ -169,7 +171,7 @@ public class ValidateLoginCredentialsCommandTest "--client=NewRegistrar", "--password=" + PASSWORD, "--cert_hash=" + CERT_HASH, - "--cert_file=" + tmpDir.newFile(), + "--cert_file=" + certFile.toString(), "--ip_address=" + CLIENT_IP)); } } diff --git a/core/src/test/java/google/registry/tools/VerifyOteCommandTest.java b/core/src/test/java/google/registry/tools/VerifyOteCommandTest.java index 23dde7ddc..97702fca7 100644 --- a/core/src/test/java/google/registry/tools/VerifyOteCommandTest.java +++ b/core/src/test/java/google/registry/tools/VerifyOteCommandTest.java @@ -27,17 +27,19 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import google.registry.model.registrar.Registrar; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; /** Unit tests for {@link VerifyOteCommand}. */ -public class VerifyOteCommandTest extends CommandTestCase { +class VerifyOteCommandTest extends CommandTestCase { @Mock private AppEngineConnection connection; - @Before - public void init() throws Exception { + @BeforeEach + void beforeEach() throws Exception { command.setConnection(connection); ImmutableMap response = ImmutableMap.of("blobio", "Num actions: 19 - Reqs passed: 19/19 - Overall: PASS"); @@ -46,7 +48,7 @@ public class VerifyOteCommandTest extends CommandTestCase { } @Test - public void testSuccess_pass() throws Exception { + void testSuccess_pass() throws Exception { Registrar registrar = loadRegistrar("TheRegistrar") .asBuilder() @@ -64,15 +66,17 @@ public class VerifyOteCommandTest extends CommandTestCase { assertInStdout("Overall: PASS"); } + @MockitoSettings(strictness = Strictness.LENIENT) @Test - public void testFailure_registrarDoesntExist() { + void testFailure_registrarDoesntExist() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("blobio")); assertThat(thrown).hasMessageThat().contains("Registrar blobio does not exist."); } + @MockitoSettings(strictness = Strictness.LENIENT) @Test - public void testFailure_noRegistrarsNoCheckAll() { + void testFailure_noRegistrarsNoCheckAll() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> runCommand("")); assertThat(thrown) diff --git a/core/src/test/java/google/registry/tools/javascrap/BackfillRegistryLocksCommandTest.java b/core/src/test/java/google/registry/tools/javascrap/BackfillRegistryLocksCommandTest.java index 320f857dc..03a62a298 100644 --- a/core/src/test/java/google/registry/tools/javascrap/BackfillRegistryLocksCommandTest.java +++ b/core/src/test/java/google/registry/tools/javascrap/BackfillRegistryLocksCommandTest.java @@ -41,18 +41,14 @@ import google.registry.util.StringGenerator.Alphabets; import java.util.Optional; import org.joda.time.DateTime; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link BackfillRegistryLocksCommand}. */ -@RunWith(JUnit4.class) -public class BackfillRegistryLocksCommandTest - extends CommandTestCase { +class BackfillRegistryLocksCommandTest extends CommandTestCase { - @Before - public void before() { + @BeforeEach + void beforeEach() { persistNewRegistrar("adminreg", "Admin Registrar", Registrar.Type.REAL, 693L); createTld("tld"); command.registryAdminClientId = "adminreg"; @@ -61,7 +57,7 @@ public class BackfillRegistryLocksCommandTest } @Test - public void testSimpleBackfill() throws Exception { + void testSimpleBackfill() throws Exception { DomainBase domain = persistLockedDomain("example.tld"); Truth8.assertThat(getMostRecentRegistryLockByRepoId(domain.getRepoId())).isEmpty(); @@ -73,7 +69,7 @@ public class BackfillRegistryLocksCommandTest } @Test - public void testBackfill_onlyLockedDomains() throws Exception { + void testBackfill_onlyLockedDomains() throws Exception { DomainBase neverLockedDomain = persistActiveDomain("neverlocked.tld"); DomainBase previouslyLockedDomain = persistLockedDomain("unlocked.tld"); persistResource(previouslyLockedDomain.asBuilder().setStatusValues(ImmutableSet.of()).build()); @@ -93,7 +89,7 @@ public class BackfillRegistryLocksCommandTest } @Test - public void testBackfill_skipsDeletedDomains() throws Exception { + void testBackfill_skipsDeletedDomains() throws Exception { DomainBase domain = persistDeletedDomain("example.tld", fakeClock.nowUtc()); persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build()); fakeClock.advanceBy(Duration.standardSeconds(1)); @@ -102,7 +98,7 @@ public class BackfillRegistryLocksCommandTest } @Test - public void testBackfill_skipsDomains_ifLockAlreadyExists() throws Exception { + void testBackfill_skipsDomains_ifLockAlreadyExists() throws Exception { DomainBase domain = persistLockedDomain("example.tld"); RegistryLock previousLock = @@ -127,7 +123,7 @@ public class BackfillRegistryLocksCommandTest } @Test - public void testBackfill_usesUrsTime_ifExists() throws Exception { + void testBackfill_usesUrsTime_ifExists() throws Exception { DateTime ursTime = fakeClock.nowUtc(); DomainBase ursDomain = persistLockedDomain("urs.tld"); HistoryEntry historyEntry = @@ -155,7 +151,7 @@ public class BackfillRegistryLocksCommandTest } @Test - public void testFailure_mustProvideDomainRoids() { + void testFailure_mustProvideDomainRoids() { assertThat(assertThrows(IllegalArgumentException.class, () -> runCommandForced())) .hasMessageThat() .isEqualTo("Must provide non-empty domain_roids argument"); diff --git a/core/src/test/java/google/registry/ui/server/registrar/RegistryLockPostActionTest.java b/core/src/test/java/google/registry/ui/server/registrar/RegistryLockPostActionTest.java index f2937b1d3..233a8add2 100644 --- a/core/src/test/java/google/registry/ui/server/registrar/RegistryLockPostActionTest.java +++ b/core/src/test/java/google/registry/ui/server/registrar/RegistryLockPostActionTest.java @@ -282,11 +282,13 @@ public final class RegistryLockPostActionTest { @Test public void testFailure_nonPunycodeDomainName() { - Map response = action.handleJsonRequest(ImmutableMap.of( - "isLock", true, - "registrarId", "TheRegistrar", - "domainName", "example.みんな", - "password", "hi")); + Map response = + action.handleJsonRequest( + ImmutableMap.of( + "isLock", true, + "registrarId", "TheRegistrar", + "domainName", "example.みんな", + "password", "hi")); assertFailureWithMessage(response, "Domain names can only contain a-z, 0-9, '.' and '-'"); } diff --git a/proxy/src/test/java/google/registry/proxy/handler/FrontendMetricsHandlerTest.java b/proxy/src/test/java/google/registry/proxy/handler/FrontendMetricsHandlerTest.java index 8c1ab9ecc..a7fca938f 100644 --- a/proxy/src/test/java/google/registry/proxy/handler/FrontendMetricsHandlerTest.java +++ b/proxy/src/test/java/google/registry/proxy/handler/FrontendMetricsHandlerTest.java @@ -20,8 +20,8 @@ import static google.registry.proxy.handler.EppServiceHandler.CLIENT_CERTIFICATE import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import com.google.common.collect.ImmutableList; import google.registry.proxy.Protocol; @@ -78,7 +78,7 @@ public class FrontendMetricsHandlerTest { Object request = new Object(); assertThat(channel.writeInbound(request)).isTrue(); assertThat((Object) channel.readInbound()).isEqualTo(request); - verifyZeroInteractions(metrics); + verifyNoInteractions(metrics); } @Test