diff --git a/javatests/google/registry/flows/EppCommitLogsTest.java b/javatests/google/registry/flows/EppCommitLogsTest.java index f815b9f66..39c56d3fa 100644 --- a/javatests/google/registry/flows/EppCommitLogsTest.java +++ b/javatests/google/registry/flows/EppCommitLogsTest.java @@ -39,7 +39,6 @@ import org.joda.time.DateTime; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -53,9 +52,6 @@ public class EppCommitLogsTest extends ShardableTestCase { .withTaskQueue() .build(); - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @Rule public final InjectRule inject = new InjectRule(); diff --git a/javatests/google/registry/flows/EppXmlTransformerTest.java b/javatests/google/registry/flows/EppXmlTransformerTest.java index 00e25bd54..d9de68152 100644 --- a/javatests/google/registry/flows/EppXmlTransformerTest.java +++ b/javatests/google/registry/flows/EppXmlTransformerTest.java @@ -17,14 +17,13 @@ package google.registry.flows; import static com.google.common.truth.Truth.assertThat; import static google.registry.flows.EppXmlTransformer.unmarshal; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.util.ResourceUtils.readResourceBytes; import google.registry.model.eppinput.EppInput; import google.registry.model.eppoutput.EppOutput; import google.registry.testing.ShardableTestCase; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -32,9 +31,6 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class EppXmlTransformerTest extends ShardableTestCase { - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @Test public void testUnmarshalingEppInput() throws Exception { EppInput input = unmarshal( @@ -44,8 +40,11 @@ public class EppXmlTransformerTest extends ShardableTestCase { @Test public void testUnmarshalingWrongClassThrows() throws Exception { - thrown.expect(ClassCastException.class); - EppXmlTransformer.unmarshal( - EppOutput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read()); + assertThrows( + ClassCastException.class, + () -> + EppXmlTransformer.unmarshal( + EppOutput.class, + readResourceBytes(getClass(), "testdata/contact_info.xml").read())); } } diff --git a/javatests/google/registry/flows/ExtensionManagerTest.java b/javatests/google/registry/flows/ExtensionManagerTest.java index 8068f0c2d..8cdcc281d 100644 --- a/javatests/google/registry/flows/ExtensionManagerTest.java +++ b/javatests/google/registry/flows/ExtensionManagerTest.java @@ -15,6 +15,7 @@ package google.registry.flows; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -38,7 +39,6 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -50,10 +50,6 @@ public class ExtensionManagerTest { public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastore() .build(); - - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @Test public void testDuplicateExtensionsForbidden() throws Exception { ExtensionManager manager = new TestInstanceBuilder() @@ -65,8 +61,7 @@ public class ExtensionManagerTest { MetadataExtension.class) .build(); manager.register(MetadataExtension.class, LaunchCreateExtension.class); - thrown.expect(UnsupportedRepeatedExtensionException.class); - manager.validate(); + assertThrows(UnsupportedRepeatedExtensionException.class, () -> manager.validate()); } @Test @@ -97,8 +92,7 @@ public class ExtensionManagerTest { .setSuppliedExtensions(FeeInfoCommandExtensionV06.class) .build(); manager.register(FeeInfoCommandExtensionV06.class); - thrown.expect(UndeclaredServiceExtensionException.class); - manager.validate(); + assertThrows(UndeclaredServiceExtensionException.class, () -> manager.validate()); } @Test @@ -131,8 +125,7 @@ public class ExtensionManagerTest { .setSuppliedExtensions(MetadataExtension.class) .build(); manager.register(MetadataExtension.class); - thrown.expect(OnlyToolCanPassMetadataException.class); - manager.validate(); + assertThrows(OnlyToolCanPassMetadataException.class, () -> manager.validate()); } @Test @@ -156,8 +149,7 @@ public class ExtensionManagerTest { .setIsSuperuser(false) .build(); manager.register(DomainTransferRequestSuperuserExtension.class); - thrown.expect(UnauthorizedForSuperuserExtensionException.class); - manager.validate(); + assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate()); } @Test @@ -169,8 +161,7 @@ public class ExtensionManagerTest { .setIsSuperuser(true) .build(); manager.register(DomainTransferRequestSuperuserExtension.class); - thrown.expect(UnauthorizedForSuperuserExtensionException.class); - manager.validate(); + assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate()); } @Test @@ -180,8 +171,7 @@ public class ExtensionManagerTest { .setDeclaredUris() .setSuppliedExtensions(LaunchCreateExtension.class) .build(); - thrown.expect(UnimplementedExtensionException.class); - manager.validate(); + assertThrows(UnimplementedExtensionException.class, () -> manager.validate()); } /** A builder for a test-ready {@link ExtensionManager} instance. */ diff --git a/javatests/google/registry/flows/FlowTestCase.java b/javatests/google/registry/flows/FlowTestCase.java index 156743c62..e1cdf6c5c 100644 --- a/javatests/google/registry/flows/FlowTestCase.java +++ b/javatests/google/registry/flows/FlowTestCase.java @@ -63,7 +63,6 @@ import java.util.Map; import org.joda.time.DateTime; import org.junit.Before; import org.junit.Rule; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -87,9 +86,6 @@ public abstract class FlowTestCase extends ShardableTestCase { .withTaskQueue() .build(); - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @Rule public final InjectRule inject = new InjectRule(); diff --git a/javatests/google/registry/flows/ResourceFlowTestCase.java b/javatests/google/registry/flows/ResourceFlowTestCase.java index 83a4e0740..fdeee3ed3 100644 --- a/javatests/google/registry/flows/ResourceFlowTestCase.java +++ b/javatests/google/registry/flows/ResourceFlowTestCase.java @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.LogsSubject.assertAboutLogs; import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; @@ -131,8 +132,7 @@ public abstract class ResourceFlowTestCase runFlow()); } /** diff --git a/javatests/google/registry/flows/TlsCredentialsTest.java b/javatests/google/registry/flows/TlsCredentialsTest.java index a5bd6c981..05e7adc94 100644 --- a/javatests/google/registry/flows/TlsCredentialsTest.java +++ b/javatests/google/registry/flows/TlsCredentialsTest.java @@ -15,37 +15,34 @@ package google.registry.flows; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import google.registry.request.HttpException.BadRequestException; import javax.servlet.http.HttpServletRequest; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Unit tests for {@link TlsCredentials}. */ @RunWith(JUnit4.class) public final class TlsCredentialsTest { - - @Rule public final ExpectedException thrown = ExpectedException.none(); - @Test public void testProvideClientCertificateHash() { HttpServletRequest req = mock(HttpServletRequest.class); when(req.getHeader("X-SSL-Certificate")).thenReturn("data"); - assertThat(TlsCredentials.EppTlsModule.provideClientCertificateHash(req)) - .isEqualTo("data"); + assertThat(TlsCredentials.EppTlsModule.provideClientCertificateHash(req)).isEqualTo("data"); } @Test public void testProvideClientCertificateHash_missing() { - thrown.expect(BadRequestException.class); - thrown.expectMessage("Missing header: X-SSL-Certificate"); HttpServletRequest req = mock(HttpServletRequest.class); - TlsCredentials.EppTlsModule.provideClientCertificateHash(req); + BadRequestException thrown = + expectThrows( + BadRequestException.class, + () -> TlsCredentials.EppTlsModule.provideClientCertificateHash(req)); + assertThat(thrown).hasMessageThat().contains("Missing header: X-SSL-Certificate"); } @Test @@ -58,10 +55,12 @@ public final class TlsCredentialsTest { @Test public void testProvideRequestedServername_missing() { - thrown.expect(BadRequestException.class); - thrown.expectMessage("Missing header: X-Requested-Servername-SNI"); HttpServletRequest req = mock(HttpServletRequest.class); - TlsCredentials.EppTlsModule.provideRequestedServername(req); + BadRequestException thrown = + expectThrows( + BadRequestException.class, + () -> TlsCredentials.EppTlsModule.provideRequestedServername(req)); + assertThat(thrown).hasMessageThat().contains("Missing header: X-Requested-Servername-SNI"); } } diff --git a/javatests/google/registry/flows/contact/ContactCheckFlowTest.java b/javatests/google/registry/flows/contact/ContactCheckFlowTest.java index a7e342889..6fb842c6e 100644 --- a/javatests/google/registry/flows/contact/ContactCheckFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactCheckFlowTest.java @@ -17,6 +17,7 @@ package google.registry.flows.contact; import static google.registry.model.eppoutput.CheckData.ContactCheck.create; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact; +import static google.registry.testing.JUnitBackports.assertThrows; import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.exceptions.TooManyResourceChecksException; @@ -76,8 +77,7 @@ public class ContactCheckFlowTest @Test public void testTooManyIds() throws Exception { setEppInput("contact_check_51.xml"); - thrown.expect(TooManyResourceChecksException.class); - runFlow(); + assertThrows(TooManyResourceChecksException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/contact/ContactCreateFlowTest.java b/javatests/google/registry/flows/contact/ContactCreateFlowTest.java index 122cdf246..9491fa9c2 100644 --- a/javatests/google/registry/flows/contact/ContactCreateFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactCreateFlowTest.java @@ -14,10 +14,13 @@ package google.registry.flows.contact; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.contact.ContactFlowUtils.BadInternationalizedPostalInfoException; @@ -66,10 +69,12 @@ public class ContactCreateFlowTest @Test public void testFailure_alreadyExists() throws Exception { persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(ResourceAlreadyExistsException.class); - thrown.expectMessage( - String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); - runFlow(); + ResourceAlreadyExistsException thrown = + expectThrows(ResourceAlreadyExistsException.class, () -> runFlow()); + assertThat(thrown) + .hasMessageThat() + .contains( + String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); } @Test @@ -81,15 +86,13 @@ public class ContactCreateFlowTest @Test public void testFailure_nonAsciiInIntAddress() throws Exception { setEppInput("contact_create_hebrew_int.xml"); - thrown.expect(BadInternationalizedPostalInfoException.class); - runFlow(); + assertThrows(BadInternationalizedPostalInfoException.class, () -> runFlow()); } @Test public void testFailure_declineDisclosure() throws Exception { setEppInput("contact_create_decline_disclosure.xml"); - thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class); - runFlow(); + assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java b/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java index 6fc1f3fa1..a9ee77b71 100644 --- a/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java @@ -23,6 +23,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableSet; @@ -71,17 +72,17 @@ public class ContactDeleteFlowTest @Test public void testFailure_neverExisted() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -116,8 +117,7 @@ public class ContactDeleteFlowTest public void testFailure_unauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -142,8 +142,7 @@ public class ContactDeleteFlowTest createTld("tld"); persistResource( newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand()))); - thrown.expect(ResourceToDeleteIsReferencedException.class); - runFlow(); + assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow()); } @Test @@ -151,8 +150,7 @@ public class ContactDeleteFlowTest createTld("tld"); persistResource( newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand()))); - thrown.expect(ResourceToDeleteIsReferencedException.class); - runFlow(); + assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/contact/ContactInfoFlowTest.java b/javatests/google/registry/flows/contact/ContactInfoFlowTest.java index f027cd7ce..2d695a74b 100644 --- a/javatests/google/registry/flows/contact/ContactInfoFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactInfoFlowTest.java @@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -163,17 +164,17 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistContactResource(false); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test diff --git a/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java index 39a31bcc8..cfcadebb9 100644 --- a/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java @@ -23,6 +23,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.getOnlyPollMessage; import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; @@ -142,73 +144,76 @@ public class ContactTransferApproveFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("contact_transfer_approve_with_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("contact_transfer_approve_with_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_clientApproved() throws Exception { changeTransferStatus(TransferStatus.CLIENT_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_clientRejected() throws Exception { changeTransferStatus(TransferStatus.CLIENT_REJECTED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_clientCancelled() throws Exception { changeTransferStatus(TransferStatus.CLIENT_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_serverApproved() throws Exception { changeTransferStatus(TransferStatus.SERVER_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_serverCancelled() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_gainingClient() throws Exception { setClientIdForFlow("NewRegistrar"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("contact_transfer_approve.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml")); } @Test public void testFailure_deletedContact() throws Exception { contact = persistResource( contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_approve.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_approve.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -216,9 +221,11 @@ public class ContactTransferApproveFlowTest deleteResource(contact); contact = persistResource( contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_approve.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_approve.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test diff --git a/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java index 2700046aa..131f970bd 100644 --- a/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java @@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.getOnlyPollMessage; import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; @@ -126,81 +128,86 @@ public class ContactTransferCancelFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("contact_transfer_cancel_with_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("contact_transfer_cancel_with_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_clientApproved() throws Exception { changeTransferStatus(TransferStatus.CLIENT_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_clientRejected() throws Exception { changeTransferStatus(TransferStatus.CLIENT_REJECTED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_clientCancelled() throws Exception { changeTransferStatus(TransferStatus.CLIENT_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_serverApproved() throws Exception { changeTransferStatus(TransferStatus.SERVER_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_serverCancelled() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_sponsoringClient() throws Exception { setClientIdForFlow("TheRegistrar"); - thrown.expect(NotTransferInitiatorException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(NotTransferInitiatorException.class); - doFailingTest("contact_transfer_cancel.xml"); + assertThrows( + NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml")); } @Test public void testFailure_deletedContact() throws Exception { contact = persistResource( contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_cancel.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_cancel.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentContact() throws Exception { deleteResource(contact); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_cancel.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_cancel.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test diff --git a/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java index 191a54b28..2e4e6b0e1 100644 --- a/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java @@ -14,10 +14,13 @@ package google.registry.flows.contact; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; @@ -138,8 +141,9 @@ public class ContactTransferQueryFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("contact_transfer_query_with_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("contact_transfer_query_with_authinfo.xml")); } @Test @@ -147,39 +151,43 @@ public class ContactTransferQueryFlowTest // Set the contact to a different ROID, but don't persist it; this is just so the substitution // code above will write the wrong ROID into the file. contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build(); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("contact_transfer_query_with_roid.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("contact_transfer_query_with_roid.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NoTransferHistoryToQueryException.class); - doFailingTest("contact_transfer_query.xml"); + assertThrows( + NoTransferHistoryToQueryException.class, () -> doFailingTest("contact_transfer_query.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(NotAuthorizedToViewTransferException.class); - doFailingTest("contact_transfer_query.xml"); + assertThrows( + NotAuthorizedToViewTransferException.class, + () -> doFailingTest("contact_transfer_query.xml")); } @Test public void testFailure_deletedContact() throws Exception { contact = persistResource( contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_query.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentContact() throws Exception { deleteResource(contact); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_query.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test diff --git a/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java index da04d6b5f..c641ca2d0 100644 --- a/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java @@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.getOnlyPollMessage; import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; @@ -141,81 +143,86 @@ public class ContactTransferRejectFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("contact_transfer_reject_with_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("contact_transfer_reject_with_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_clientApproved() throws Exception { changeTransferStatus(TransferStatus.CLIENT_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_clientRejected() throws Exception { changeTransferStatus(TransferStatus.CLIENT_REJECTED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_clientCancelled() throws Exception { changeTransferStatus(TransferStatus.CLIENT_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_serverApproved() throws Exception { changeTransferStatus(TransferStatus.SERVER_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_serverCancelled() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_gainingClient() throws Exception { setClientIdForFlow("NewRegistrar"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("contact_transfer_reject.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml")); } @Test public void testFailure_deletedContact() throws Exception { contact = persistResource( contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_reject.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_reject.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentContact() throws Exception { deleteResource(contact); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_reject.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_reject.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test diff --git a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java index b9692d821..e5757ed39 100644 --- a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java @@ -28,6 +28,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -154,8 +156,9 @@ public class ContactTransferRequestFlowTest @Test public void testFailure_noAuthInfo() throws Exception { - thrown.expect(MissingTransferRequestAuthInfoException.class); - doFailingTest("contact_transfer_request_no_authinfo.xml"); + assertThrows( + MissingTransferRequestAuthInfoException.class, + () -> doFailingTest("contact_transfer_request_no_authinfo.xml")); } @Test @@ -165,8 +168,8 @@ public class ContactTransferRequestFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("contact_transfer_request.xml"); + assertThrows( + BadAuthInfoForResourceException.class, () -> doFailingTest("contact_transfer_request.xml")); } @Test @@ -208,59 +211,69 @@ public class ContactTransferRequestFlowTest .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .build()) .build()); - thrown.expect(AlreadyPendingTransferException.class); - doFailingTest("contact_transfer_request.xml"); + assertThrows( + AlreadyPendingTransferException.class, () -> doFailingTest("contact_transfer_request.xml")); } @Test public void testFailure_sponsoringClient() throws Exception { setClientIdForFlow("TheRegistrar"); - thrown.expect(ObjectAlreadySponsoredException.class); - doFailingTest("contact_transfer_request.xml"); + assertThrows( + ObjectAlreadySponsoredException.class, () -> doFailingTest("contact_transfer_request.xml")); } @Test public void testFailure_deletedContact() throws Exception { contact = persistResource( contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_request.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentContact() throws Exception { deleteResource(contact); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("contact_transfer_request.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("contact_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_clientTransferProhibited() throws Exception { contact = persistResource( contact.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("clientTransferProhibited"); - doFailingTest("contact_transfer_request.xml"); + ResourceStatusProhibitsOperationException thrown = + expectThrows( + ResourceStatusProhibitsOperationException.class, + () -> doFailingTest("contact_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains("clientTransferProhibited"); } @Test public void testFailure_serverTransferProhibited() throws Exception { contact = persistResource( contact.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("serverTransferProhibited"); - doFailingTest("contact_transfer_request.xml"); + ResourceStatusProhibitsOperationException thrown = + expectThrows( + ResourceStatusProhibitsOperationException.class, + () -> doFailingTest("contact_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains("serverTransferProhibited"); } @Test public void testFailure_pendingDelete() throws Exception { contact = persistResource( contact.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("pendingDelete"); - doFailingTest("contact_transfer_request.xml"); + ResourceStatusProhibitsOperationException thrown = + expectThrows( + ResourceStatusProhibitsOperationException.class, + () -> doFailingTest("contact_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test diff --git a/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java b/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java index e012acbb4..aadad3632 100644 --- a/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java @@ -14,12 +14,15 @@ package google.registry.flows.contact; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.newContactResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -253,25 +256,24 @@ public class ContactUpdateFlowTest @Test public void testFailure_neverExisted() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_statusValueNotClientSettable() throws Exception { setEppInput("contact_update_prohibited_status.xml"); persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(StatusNotClientSettableException.class); - runFlow(); + assertThrows(StatusNotClientSettableException.class, () -> runFlow()); } @Test @@ -289,8 +291,7 @@ public class ContactUpdateFlowTest public void testFailure_unauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -337,8 +338,7 @@ public class ContactUpdateFlowTest newContactResource(getUniqueIdFromCommand()).asBuilder() .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) .build()); - thrown.expect(ResourceHasClientUpdateProhibitedException.class); - runFlow(); + assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow()); } @Test @@ -347,9 +347,9 @@ public class ContactUpdateFlowTest newContactResource(getUniqueIdFromCommand()).asBuilder() .setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)) .build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("serverUpdateProhibited"); - runFlow(); + ResourceStatusProhibitsOperationException thrown = + expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited"); } @Test @@ -358,9 +358,9 @@ public class ContactUpdateFlowTest newContactResource(getUniqueIdFromCommand()).asBuilder() .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("pendingDelete"); - runFlow(); + ResourceStatusProhibitsOperationException thrown = + expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test @@ -373,24 +373,21 @@ public class ContactUpdateFlowTest public void testFailure_nonAsciiInIntAddress() throws Exception { setEppInput("contact_update_hebrew_int.xml"); persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(BadInternationalizedPostalInfoException.class); - runFlow(); + assertThrows(BadInternationalizedPostalInfoException.class, () -> runFlow()); } @Test public void testFailure_declineDisclosure() throws Exception { setEppInput("contact_update_decline_disclosure.xml"); persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class); - runFlow(); + assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, () -> runFlow()); } @Test public void testFailure_addRemoveSameValue() throws Exception { setEppInput("contact_update_add_remove_same.xml"); persistActiveContact(getUniqueIdFromCommand()); - thrown.expect(AddRemoveSameValueException.class); - runFlow(); + assertThrows(AddRemoveSameValueException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java index 1e7ef403a..fdf1c41bb 100644 --- a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java @@ -30,6 +30,8 @@ import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued; @@ -253,9 +255,9 @@ public class DomainAllocateFlowTest .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) .build()); - thrown.expect(NameserversNotAllowedForTldException.class); - thrown.expectMessage("ns1.example.net"); - runFlowAsSuperuser(); + NameserversNotAllowedForTldException thrown = + expectThrows(NameserversNotAllowedForTldException.class, () -> runFlowAsSuperuser()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -268,9 +270,9 @@ public class DomainAllocateFlowTest .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns1.example.net", "ns2.example.net")) .build()); - thrown.expect(RegistrantNotAllowedException.class); - thrown.expectMessage("jd1234"); - runFlowAsSuperuser(); + RegistrantNotAllowedException thrown = + expectThrows(RegistrantNotAllowedException.class, () -> runFlowAsSuperuser()); + assertThat(thrown).hasMessageThat().contains("jd1234"); } @Test @@ -283,8 +285,9 @@ public class DomainAllocateFlowTest .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.net, ns2.example.net")) .build()); - thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); - runFlowAsSuperuser(); + assertThrows( + NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, + () -> runFlowAsSuperuser()); } @Test @@ -313,9 +316,9 @@ public class DomainAllocateFlowTest "reserved", "example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net")) .build()); - thrown.expect(NameserversNotAllowedForDomainException.class); - thrown.expectMessage("ns1.example.net"); - runFlowAsSuperuser(); + NameserversNotAllowedForDomainException thrown = + expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlowAsSuperuser()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -330,8 +333,9 @@ public class DomainAllocateFlowTest "reserved", "example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net")) .build()); - thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); - runFlowAsSuperuser(); + assertThrows( + NameserversNotSpecifiedForNameserverRestrictedDomainException.class, + () -> runFlowAsSuperuser()); } @Test @@ -366,9 +370,9 @@ public class DomainAllocateFlowTest .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns1.example.net", "ns2.example.net", "ns3.example.net")) .build()); - thrown.expect(NameserversNotAllowedForDomainException.class); - thrown.expectMessage("ns1.example.net"); - runFlowAsSuperuser(); + NameserversNotAllowedForDomainException thrown = + expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlowAsSuperuser()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -385,9 +389,9 @@ public class DomainAllocateFlowTest .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns4.example.net", "ns2.example.net", "ns3.example.net")) .build()); - thrown.expect(NameserversNotAllowedForTldException.class); - thrown.expectMessage("ns1.example.net"); - runFlowAsSuperuser(); + NameserversNotAllowedForTldException thrown = + expectThrows(NameserversNotAllowedForTldException.class, () -> runFlowAsSuperuser()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -571,8 +575,7 @@ public class DomainAllocateFlowTest public void testFailure_alreadyExists() throws Exception { setupDomainApplication("tld", TldState.QUIET_PERIOD); persistActiveDomain(getUniqueIdFromCommand()); - thrown.expect(ResourceAlreadyExistsException.class); - runFlowAsSuperuser(); + assertThrows(ResourceAlreadyExistsException.class, () -> runFlowAsSuperuser()); } @Test @@ -607,8 +610,7 @@ public class DomainAllocateFlowTest public void testFailure_applicationDeleted() throws Exception { setupDomainApplication("tld", TldState.QUIET_PERIOD); persistResource(application.asBuilder().setDeletionTime(clock.nowUtc()).build()); - thrown.expect(MissingApplicationException.class); - runFlowAsSuperuser(); + assertThrows(MissingApplicationException.class, () -> runFlowAsSuperuser()); } @Test @@ -617,8 +619,7 @@ public class DomainAllocateFlowTest persistResource(application.asBuilder() .setApplicationStatus(ApplicationStatus.REJECTED) .build()); - thrown.expect(HasFinalStatusException.class); - runFlowAsSuperuser(); + assertThrows(HasFinalStatusException.class, () -> runFlowAsSuperuser()); } @Test @@ -627,16 +628,14 @@ public class DomainAllocateFlowTest persistResource(application.asBuilder() .setApplicationStatus(ApplicationStatus.ALLOCATED) .build()); - thrown.expect(HasFinalStatusException.class); - runFlowAsSuperuser(); + assertThrows(HasFinalStatusException.class, () -> runFlowAsSuperuser()); } @Test public void testFailure_applicationDoesNotExist() throws Exception { setupDomainApplication("tld", TldState.QUIET_PERIOD); setEppInput("domain_allocate_bad_application_roid.xml"); - thrown.expect(MissingApplicationException.class); - runFlowAsSuperuser(); + assertThrows(MissingApplicationException.class, () -> runFlowAsSuperuser()); } @Test @@ -645,16 +644,16 @@ public class DomainAllocateFlowTest clock.advanceOneMilli(); setEppInput("domain_allocate_no_nameservers.xml"); assertTransactionalFlow(true); - thrown.expect(OnlySuperuserCanAllocateException.class); - runFlow(CommitMode.LIVE, UserPrivileges.NORMAL); + assertThrows( + OnlySuperuserCanAllocateException.class, + () -> runFlow(CommitMode.LIVE, UserPrivileges.NORMAL)); } @Test public void testFailure_max10Years() throws Exception { setupDomainApplication("tld", TldState.QUIET_PERIOD); setEppInput("domain_allocate_11_years.xml"); - thrown.expect(ExceedsMaxRegistrationYearsException.class); - runFlowAsSuperuser(); + assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlowAsSuperuser()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java index 5fc7182d8..279d2859c 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java @@ -34,6 +34,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static java.util.Comparator.comparing; import static org.joda.money.CurrencyUnit.EUR; @@ -245,8 +246,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark_corrupt.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkParsingErrorException.class); - runFlow(); + assertThrows(SignedMarkParsingErrorException.class, () -> runFlow()); } @Test @@ -255,8 +255,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark_revoked_cert.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkCertificateRevokedException.class); - runFlow(); + assertThrows(SignedMarkCertificateRevokedException.class, () -> runFlow()); } @Test @@ -267,8 +266,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); clock.setTo(DateTime.parse("2022-01-01")); clock.setTo(DateTime.parse("2022-01-01")); - thrown.expect(SignedMarkCertificateExpiredException.class); - runFlow(); + assertThrows(SignedMarkCertificateExpiredException.class, () -> runFlow()); } @Test @@ -278,8 +276,7 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); clock.setTo(DateTime.parse("2012-07-22T00:01:00Z")); - thrown.expect(SignedMarkCertificateNotYetValidException.class); - runFlow(); + assertThrows(SignedMarkCertificateNotYetValidException.class, () -> runFlow()); } @Test @@ -296,8 +293,7 @@ public class DomainApplicationCreateFlowTest public void verify(byte[] smdXml) throws GeneralSecurityException { throw new GeneralSecurityException(); }}; - thrown.expect(SignedMarkCertificateInvalidException.class); - runFlow(); + assertThrows(SignedMarkCertificateInvalidException.class, () -> runFlow()); } @Test @@ -307,8 +303,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkCertificateSignatureException.class); - runFlow(); + assertThrows(SignedMarkCertificateSignatureException.class, () -> runFlow()); } @Test @@ -317,8 +312,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark_signature_corrupt.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkSignatureException.class); - runFlow(); + assertThrows(SignedMarkSignatureException.class, () -> runFlow()); } @Test @@ -394,8 +388,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_allowedinsunrise.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(DomainReservedException.class); - runFlow(); + assertThrows(DomainReservedException.class, () -> runFlow()); } @Test @@ -406,8 +399,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); // Modify the Registrar to block premium names. persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build()); - thrown.expect(PremiumNameBlockedException.class); - runFlow(); + assertThrows(PremiumNameBlockedException.class, () -> runFlow()); } @Test @@ -416,8 +408,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_premium.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(FeesRequiredForPremiumNameException.class); - runFlow(); + assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow()); } @Test @@ -526,8 +517,7 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -537,8 +527,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -548,8 +537,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -559,8 +547,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -570,8 +557,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -581,8 +567,7 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -591,8 +576,7 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -601,8 +585,7 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -611,8 +594,7 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -718,8 +700,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_without_marks.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(LandrushApplicationDisallowedDuringSunriseException.class); - runFlow(); + assertThrows(LandrushApplicationDisallowedDuringSunriseException.class, () -> runFlow()); } @Test @@ -734,8 +715,7 @@ public class DomainApplicationCreateFlowTest .setState(State.SUSPENDED) .build()); clock.advanceOneMilli(); - thrown.expect(RegistrarMustBeActiveToCreateDomainsException.class); - runFlow(); + assertThrows(RegistrarMustBeActiveToCreateDomainsException.class, () -> runFlow()); } @Test @@ -744,8 +724,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SunriseApplicationDisallowedDuringLandrushException.class); - runFlow(); + assertThrows(SunriseApplicationDisallowedDuringLandrushException.class, () -> runFlow()); } @Test @@ -753,8 +732,7 @@ public class DomainApplicationCreateFlowTest SignedMarkRevocationList.create(clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc())).save(); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkRevokedErrorException.class); - runFlow(); + assertThrows(SignedMarkRevokedErrorException.class, () -> runFlow()); } @Test @@ -763,8 +741,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_14_nameservers.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(TooManyNameserversException.class); - runFlow(); + assertThrows(TooManyNameserversException.class, () -> runFlow()); } @Test @@ -772,8 +749,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_with_secdns_maxsiglife.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(MaxSigLifeNotSupportedException.class); - runFlow(); + assertThrows(MaxSigLifeNotSupportedException.class, () -> runFlow()); } @Test @@ -781,8 +757,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_signed_mark_with_secdns_9_records.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(TooManyDsRecordsException.class); - runFlow(); + assertThrows(TooManyDsRecordsException.class, () -> runFlow()); } @Test @@ -790,8 +765,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_wrong_extension.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(UnimplementedExtensionException.class); - runFlow(); + assertThrows(UnimplementedExtensionException.class, () -> runFlow()); } @Test @@ -799,8 +773,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_signed_mark_reserved.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(DomainReservedException.class); - runFlow(); + assertThrows(DomainReservedException.class, () -> runFlow()); } @Test @@ -852,8 +825,7 @@ public class DomainApplicationCreateFlowTest persistSunriseApplication(); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(UncontestedSunriseApplicationBlockedInLandrushException.class); - runFlow(); + assertThrows(UncontestedSunriseApplicationBlockedInLandrushException.class, () -> runFlow()); } @Test @@ -940,8 +912,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidLrpTokenException.class); - runFlow(); + assertThrows(InvalidLrpTokenException.class, () -> runFlow()); } @Test @@ -961,8 +932,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidLrpTokenException.class); - runFlow(); + assertThrows(InvalidLrpTokenException.class, () -> runFlow()); } @Test @@ -981,8 +951,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidLrpTokenException.class); - runFlow(); + assertThrows(InvalidLrpTokenException.class, () -> runFlow()); } @Test @@ -1037,8 +1006,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidLrpTokenException.class); - runFlow(); + assertThrows(InvalidLrpTokenException.class, () -> runFlow()); } @Test @@ -1047,8 +1015,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_months.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(BadPeriodUnitException.class); - runFlow(); + assertThrows(BadPeriodUnitException.class, () -> runFlow()); } @Test @@ -1056,9 +1023,9 @@ public class DomainApplicationCreateFlowTest persistActiveHost("ns1.example.net"); persistActiveContact("jd1234"); persistActiveContact("sh8013"); - thrown.expect(LinkedResourcesDoNotExistException.class); - thrown.expectMessage("(ns2.example.net)"); - runFlow(); + LinkedResourcesDoNotExistException thrown = + expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("(ns2.example.net)"); } @Test @@ -1066,9 +1033,9 @@ public class DomainApplicationCreateFlowTest persistActiveHost("ns1.example.net"); persistActiveHost("ns2.example.net"); persistActiveContact("jd1234"); - thrown.expect(LinkedResourcesDoNotExistException.class); - thrown.expectMessage("(sh8013)"); - runFlow(); + LinkedResourcesDoNotExistException thrown = + expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("(sh8013)"); } @Test @@ -1077,8 +1044,7 @@ public class DomainApplicationCreateFlowTest createTld("foo", TldState.SUNRISE); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(TldDoesNotExistException.class); - runFlow(); + assertThrows(TldDoesNotExistException.class, () -> runFlow()); } @Test @@ -1086,8 +1052,7 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.PREDELEGATION); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -1095,8 +1060,7 @@ public class DomainApplicationCreateFlowTest persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); persistContactsAndHosts(); - thrown.expect(NotAuthorizedForTldException.class); - runFlow(); + assertThrows(NotAuthorizedForTldException.class, () -> runFlow()); } @Test @@ -1104,8 +1068,7 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.SUNRUSH); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(LaunchPhaseMismatchException.class); - runFlow(); + assertThrows(LaunchPhaseMismatchException.class, () -> runFlow()); } @Test @@ -1113,8 +1076,7 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.QUIET_PERIOD); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -1122,8 +1084,7 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.GENERAL_AVAILABILITY); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -1131,8 +1092,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(LaunchPhaseMismatchException.class); - runFlow(); + assertThrows(LaunchPhaseMismatchException.class, () -> runFlow()); } @Test @@ -1189,8 +1149,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_duplicate_contact.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(DuplicateContactForRoleException.class); - runFlow(); + assertThrows(DuplicateContactForRoleException.class, () -> runFlow()); } @Test @@ -1199,8 +1158,7 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); // We need to test for missing type, but not for invalid - the schema enforces that for us. - thrown.expect(MissingContactTypeException.class); - runFlow(); + assertThrows(MissingContactTypeException.class, () -> runFlow()); } @Test @@ -1208,8 +1166,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_no_matching_marks.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NoMarksFoundMatchingDomainException.class); - runFlow(); + assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow()); } @Test @@ -1218,8 +1175,7 @@ public class DomainApplicationCreateFlowTest clock.setTo(DateTime.parse("2013-08-09T10:05:59Z").minusSeconds(1)); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NoMarksFoundMatchingDomainException.class); - runFlow(); + assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow()); } @Test @@ -1228,8 +1184,7 @@ public class DomainApplicationCreateFlowTest clock.setTo(DateTime.parse("2017-07-23T22:00:00.000Z")); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NoMarksFoundMatchingDomainException.class); - runFlow(); + assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow()); } @Test @@ -1237,8 +1192,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_hex_encoding.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(Base64RequiredForEncodedSignedMarksException.class); - runFlow(); + assertThrows(Base64RequiredForEncodedSignedMarksException.class, () -> runFlow()); } @Test @@ -1246,8 +1200,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_bad_encoding.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkEncodingErrorException.class); - runFlow(); + assertThrows(SignedMarkEncodingErrorException.class, () -> runFlow()); } @Test @@ -1255,8 +1208,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_bad_encoded_xml.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkParsingErrorException.class); - runFlow(); + assertThrows(SignedMarkParsingErrorException.class, () -> runFlow()); } @Test @@ -1265,8 +1217,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_bad_idn_minna.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidIdnDomainLabelException.class); - runFlow(); + assertThrows(InvalidIdnDomainLabelException.class, () -> runFlow()); } @Test @@ -1276,8 +1227,7 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidTrademarkValidatorException.class); - runFlow(); + assertThrows(InvalidTrademarkValidatorException.class, () -> runFlow()); } @Test @@ -1285,8 +1235,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarksMustBeEncodedException.class); - runFlow(); + assertThrows(SignedMarksMustBeEncodedException.class, () -> runFlow()); } @Test @@ -1294,8 +1243,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_code_with_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(UnsupportedMarkTypeException.class); - runFlow(); + assertThrows(UnsupportedMarkTypeException.class, () -> runFlow()); } @Test @@ -1303,8 +1251,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_empty_encoded_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(SignedMarkParsingErrorException.class); - runFlow(); + assertThrows(SignedMarkParsingErrorException.class, () -> runFlow()); } @Test @@ -1313,8 +1260,7 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NoticeCannotBeUsedWithSignedMarkException.class); - runFlow(); + assertThrows(NoticeCannotBeUsedWithSignedMarkException.class, () -> runFlow()); } @Test @@ -1322,8 +1268,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_two_signed_marks.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(TooManySignedMarksException.class); - runFlow(); + assertThrows(TooManySignedMarksException.class, () -> runFlow()); } @Test @@ -1333,8 +1278,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(MissingClaimsNoticeException.class); - runFlow(); + assertThrows(MissingClaimsNoticeException.class, () -> runFlow()); } @Test @@ -1343,8 +1287,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_claim_notice.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(UnexpectedClaimsNoticeException.class); - runFlow(); + assertThrows(UnexpectedClaimsNoticeException.class, () -> runFlow()); } @Test @@ -1356,8 +1299,7 @@ public class DomainApplicationCreateFlowTest persistResource(Registry.get("tld").asBuilder() .setClaimsPeriodEnd(clock.nowUtc()) .build()); - thrown.expect(ClaimsPeriodEndedException.class); - runFlow(); + assertThrows(ClaimsPeriodEndedException.class, () -> runFlow()); } @Test @@ -1368,8 +1310,7 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(ExpiredClaimException.class); - runFlow(); + assertThrows(ExpiredClaimException.class, () -> runFlow()); } @Test @@ -1380,8 +1321,7 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(AcceptedTooLongAgoException.class); - runFlow(); + assertThrows(AcceptedTooLongAgoException.class, () -> runFlow()); } @Test @@ -1392,8 +1332,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_malformed_claim_notice1.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(MalformedTcnIdException.class); - runFlow(); + assertThrows(MalformedTcnIdException.class, () -> runFlow()); } @Test @@ -1404,8 +1343,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_malformed_claim_notice2.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(MalformedTcnIdException.class); - runFlow(); + assertThrows(MalformedTcnIdException.class, () -> runFlow()); } @Test @@ -1416,8 +1354,7 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(InvalidTcnIdChecksumException.class); - runFlow(); + assertThrows(InvalidTcnIdChecksumException.class, () -> runFlow()); } @Test @@ -1428,8 +1365,7 @@ public class DomainApplicationCreateFlowTest Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } @Test @@ -1440,8 +1376,7 @@ public class DomainApplicationCreateFlowTest Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } @Test @@ -1452,8 +1387,7 @@ public class DomainApplicationCreateFlowTest Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } @Test @@ -1470,8 +1404,7 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test @@ -1488,8 +1421,7 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test @@ -1506,8 +1438,7 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test @@ -1516,8 +1447,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6")); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test @@ -1526,8 +1456,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11")); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test @@ -1536,8 +1465,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12")); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @@ -1565,9 +1493,9 @@ public class DomainApplicationCreateFlowTest persistResource(Registry.get("tld").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("someone")) .build()); - thrown.expect(RegistrantNotAllowedException.class); - thrown.expectMessage("jd1234"); - runFlow(); + RegistrantNotAllowedException thrown = + expectThrows(RegistrantNotAllowedException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("jd1234"); } @Test @@ -1576,9 +1504,9 @@ public class DomainApplicationCreateFlowTest persistResource(Registry.get("tld").asBuilder() .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) .build()); - thrown.expect(NameserversNotAllowedForTldException.class); - thrown.expectMessage("ns1.example.net"); - runFlow(); + NameserversNotAllowedForTldException thrown = + expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1603,8 +1531,8 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); - runFlow(); + assertThrows( + NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow()); } @Test @@ -1638,9 +1566,9 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForDomainException.class); - thrown.expectMessage("ns1.example.net"); - runFlow(); + NameserversNotAllowedForDomainException thrown = + expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1656,8 +1584,8 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); - runFlow(); + assertThrows( + NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow()); } @Test @@ -1697,9 +1625,9 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForDomainException.class); - thrown.expectMessage("ns1.example.net"); - runFlow(); + NameserversNotAllowedForDomainException thrown = + expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1717,9 +1645,9 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForTldException.class); - thrown.expectMessage("ns1.example.net"); - runFlow(); + NameserversNotAllowedForTldException thrown = + expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1728,8 +1656,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_11_years.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - thrown.expect(ExceedsMaxRegistrationYearsException.class); - runFlow(); + assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow()); } private void doFailingDomainNameTest(String domainName, Class exception) diff --git a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java index f50616085..30fa6061b 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java @@ -26,6 +26,8 @@ import static google.registry.testing.DatastoreHelper.newHostResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -123,9 +125,9 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_neverExisted() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -134,9 +136,9 @@ public class DomainApplicationDeleteFlowTest .setRepoId("1-TLD") .setDeletionTime(clock.nowUtc().minusSeconds(1)) .build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -144,8 +146,7 @@ public class DomainApplicationDeleteFlowTest sessionMetadata.setClientId("NewRegistrar"); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -163,8 +164,7 @@ public class DomainApplicationDeleteFlowTest persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - runFlow(); + assertThrows(NotAuthorizedForTldException.class, () -> runFlow()); } @Test @@ -186,8 +186,7 @@ public class DomainApplicationDeleteFlowTest .setRepoId("1-TLD") .setPhase(LaunchPhase.SUNRISE) .build()); - thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class); - runFlow(); + assertThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, () -> runFlow()); } @Test @@ -233,16 +232,14 @@ public class DomainApplicationDeleteFlowTest setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - thrown.expect(LaunchPhaseMismatchException.class); - runFlow(); + assertThrows(LaunchPhaseMismatchException.class, () -> runFlow()); } @Test public void testFailure_wrongExtension() throws Exception { setEppInput("domain_delete_application_wrong_extension.xml"); persistActiveDomainApplication("example.tld"); - thrown.expect(UnimplementedExtensionException.class); - runFlow(); + assertThrows(UnimplementedExtensionException.class, () -> runFlow()); } @Test @@ -250,8 +247,7 @@ public class DomainApplicationDeleteFlowTest createTld("tld", TldState.PREDELEGATION); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -259,8 +255,7 @@ public class DomainApplicationDeleteFlowTest createTld("tld", TldState.QUIET_PERIOD); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -268,8 +263,7 @@ public class DomainApplicationDeleteFlowTest createTld("tld", TldState.GENERAL_AVAILABILITY); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -306,8 +300,7 @@ public class DomainApplicationDeleteFlowTest public void testFailure_applicationIdForDifferentDomain() throws Exception { persistResource( newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build()); - thrown.expect(ApplicationDomainNameMismatchException.class); - runFlow(); + assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index b05f75c85..77d2bb5c5 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; @@ -261,9 +263,9 @@ public class DomainApplicationInfoFlowTest @Test public void testFailure_neverExisted() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -274,9 +276,9 @@ public class DomainApplicationInfoFlowTest .setDeletionTime(clock.nowUtc().minusDays(1)) .setRegistrant(Key.create(persistActiveContact("jd1234"))) .build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -285,8 +287,7 @@ public class DomainApplicationInfoFlowTest AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build()); sessionMetadata.setClientId("ClientZ"); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -297,16 +298,14 @@ public class DomainApplicationInfoFlowTest .setRegistrant(Key.create(persistActiveContact("jd1234"))) .setPhase(LaunchPhase.SUNRUSH) .build()); - thrown.expect(ApplicationDomainNameMismatchException.class); - runFlow(); + assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow()); } @Test public void testFailure_noApplicationId() throws Exception { setEppInput("domain_info_sunrise_no_application_id.xml"); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); - thrown.expect(MissingApplicationIdException.class); - runFlow(); + assertThrows(MissingApplicationIdException.class, () -> runFlow()); } @Test @@ -314,8 +313,7 @@ public class DomainApplicationInfoFlowTest persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); application = persistResource( application.asBuilder().setPhase(LaunchPhase.SUNRISE).build()); - thrown.expect(ApplicationLaunchPhaseMismatchException.class); - runFlow(); + assertThrows(ApplicationLaunchPhaseMismatchException.class, () -> runFlow()); } /** Test that we load contacts and hosts as a batch rather than individually. */ diff --git a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java index f6380a774..58dfec515 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java @@ -29,6 +29,7 @@ import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableMap; @@ -371,8 +372,7 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_dsdata_add.xml"); persistResource(newApplicationBuilder().setDsData(builder.build()).build()); - thrown.expect(TooManyDsRecordsException.class); - runFlow(); + assertThrows(TooManyDsRecordsException.class, () -> runFlow()); } private void modifyApplicationToHave13Nameservers() throws Exception { @@ -395,40 +395,37 @@ public class DomainApplicationUpdateFlowTest // Modify application to have 13 nameservers. We will then remove one and add one in the test. modifyApplicationToHave13Nameservers(); setEppInput("domain_update_sunrise_add_nameserver.xml"); - thrown.expect(TooManyNameserversException.class); - runFlow(); + assertThrows(TooManyNameserversException.class, () -> runFlow()); } @Test public void testFailure_wrongExtension() throws Exception { setEppInput("domain_update_sunrise_wrong_extension.xml"); - thrown.expect(UnimplementedExtensionException.class); - runFlow(); + assertThrows(UnimplementedExtensionException.class, () -> runFlow()); } @Test public void testFailure_applicationDomainNameMismatch() throws Exception { persistReferencedEntities(); persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build()); - thrown.expect(ApplicationDomainNameMismatchException.class); - runFlow(); + assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow()); } @Test public void testFailure_neverExisted() throws Exception { persistReferencedEntities(); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistReferencedEntities(); persistResource(newApplicationBuilder().setDeletionTime(START_OF_TIME).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -437,8 +434,7 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistResource(newApplicationBuilder().setStatusValues( ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); - thrown.expect(ResourceHasClientUpdateProhibitedException.class); - runFlow(); + assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow()); } @Test @@ -446,16 +442,15 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistResource(newApplicationBuilder().setStatusValues( ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("serverUpdateProhibited"); - runFlow(); + ResourceStatusProhibitsOperationException thrown = + expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited"); } private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception { persistReferencedEntities(); persistResource(newApplicationBuilder().setApplicationStatus(status).build()); - thrown.expect(ApplicationStatusProhibitsUpdateException.class); - runFlow(); + assertThrows(ApplicationStatusProhibitsUpdateException.class, () -> runFlow()); } @Test @@ -479,9 +474,9 @@ public class DomainApplicationUpdateFlowTest persistActiveContact("sh8013"); persistActiveContact("mak21"); persistNewApplication(); - thrown.expect(LinkedResourcesDoNotExistException.class); - thrown.expectMessage("(ns2.example.tld)"); - runFlow(); + LinkedResourcesDoNotExistException thrown = + expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("(ns2.example.tld)"); } @Test @@ -490,9 +485,9 @@ public class DomainApplicationUpdateFlowTest persistActiveHost("ns2.example.tld"); persistActiveContact("mak21"); persistNewApplication(); - thrown.expect(LinkedResourcesDoNotExistException.class); - thrown.expectMessage("(sh8013)"); - runFlow(); + LinkedResourcesDoNotExistException thrown = + expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("(sh8013)"); } @Test @@ -505,8 +500,7 @@ public class DomainApplicationUpdateFlowTest persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of( DesignatedContact.create(Type.TECH, Key.create( loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build()); - thrown.expect(DuplicateContactForRoleException.class); - runFlow(); + assertThrows(DuplicateContactForRoleException.class, () -> runFlow()); } @Test @@ -514,8 +508,7 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_prohibited_status.xml"); persistReferencedEntities(); persistNewApplication(); - thrown.expect(StatusNotClientSettableException.class); - runFlow(); + assertThrows(StatusNotClientSettableException.class, () -> runFlow()); } @@ -536,8 +529,7 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_duplicate_contact.xml"); persistReferencedEntities(); persistNewApplication(); - thrown.expect(DuplicateContactForRoleException.class); - runFlow(); + assertThrows(DuplicateContactForRoleException.class, () -> runFlow()); } @Test @@ -546,8 +538,7 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistNewApplication(); // We need to test for missing type, but not for invalid - the schema enforces that for us. - thrown.expect(MissingContactTypeException.class); - runFlow(); + assertThrows(MissingContactTypeException.class, () -> runFlow()); } @Test @@ -555,8 +546,7 @@ public class DomainApplicationUpdateFlowTest sessionMetadata.setClientId("NewRegistrar"); persistReferencedEntities(); persistApplication(); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -575,8 +565,7 @@ public class DomainApplicationUpdateFlowTest loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); persistReferencedEntities(); persistApplication(); - thrown.expect(NotAuthorizedForTldException.class); - runFlow(); + assertThrows(NotAuthorizedForTldException.class, () -> runFlow()); } @Test @@ -598,8 +587,7 @@ public class DomainApplicationUpdateFlowTest .setNameservers(ImmutableSet.of(Key.create( loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) .build()); - thrown.expect(AddRemoveSameValueException.class); - runFlow(); + assertThrows(AddRemoveSameValueException.class, () -> runFlow()); } @Test @@ -612,8 +600,7 @@ public class DomainApplicationUpdateFlowTest Key.create( loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) .build()); - thrown.expect(AddRemoveSameValueException.class); - runFlow(); + assertThrows(AddRemoveSameValueException.class, () -> runFlow()); } @Test @@ -625,8 +612,7 @@ public class DomainApplicationUpdateFlowTest DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) .build()); - thrown.expect(MissingAdminContactException.class); - runFlow(); + assertThrows(MissingAdminContactException.class, () -> runFlow()); } @Test @@ -638,8 +624,7 @@ public class DomainApplicationUpdateFlowTest DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) .build()); - thrown.expect(MissingTechnicalContactException.class); - runFlow(); + assertThrows(MissingTechnicalContactException.class, () -> runFlow()); } @Test @@ -651,8 +636,7 @@ public class DomainApplicationUpdateFlowTest .setAllowedRegistrantContactIds(ImmutableSet.of("contact1234")) .build()); clock.advanceOneMilli(); - thrown.expect(RegistrantNotAllowedException.class); - runFlow(); + assertThrows(RegistrantNotAllowedException.class, () -> runFlow()); } @Test @@ -664,8 +648,7 @@ public class DomainApplicationUpdateFlowTest .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo")) .build()); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForTldException.class); - runFlow(); + assertThrows(NameserversNotAllowedForTldException.class, () -> runFlow()); } @Test @@ -692,8 +675,8 @@ public class DomainApplicationUpdateFlowTest ImmutableSet.of("ns1.example.tld", "ns2.example.tld")) .build()); clock.advanceOneMilli(); - thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); - runFlow(); + assertThrows( + NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow()); } @Test @@ -746,9 +729,9 @@ public class DomainApplicationUpdateFlowTest "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld")) .build()); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForDomainException.class); - thrown.expectMessage("ns2.example.tld"); - runFlow(); + NameserversNotAllowedForDomainException thrown = + expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.tld"); } @Test @@ -764,8 +747,8 @@ public class DomainApplicationUpdateFlowTest "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld")) .build()); clock.advanceOneMilli(); - thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); - runFlow(); + assertThrows( + NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow()); } @Test @@ -825,9 +808,9 @@ public class DomainApplicationUpdateFlowTest "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld")) .build()); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForDomainException.class); - thrown.expectMessage("ns2.example.tld"); - runFlow(); + NameserversNotAllowedForDomainException thrown = + expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.tld"); } @Test @@ -845,9 +828,9 @@ public class DomainApplicationUpdateFlowTest "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld")) .build()); clock.advanceOneMilli(); - thrown.expect(NameserversNotAllowedForTldException.class); - thrown.expectMessage("ns2.example.tld"); - runFlow(); + NameserversNotAllowedForTldException thrown = + expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.tld"); } @Test @@ -859,8 +842,7 @@ public class DomainApplicationUpdateFlowTest "domain_update_sunrise_fee.xml", ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00")); clock.advanceOneMilli(); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainCheckFlowTest.java b/javatests/google/registry/flows/domain/DomainCheckFlowTest.java index 354685e32..48cd13e98 100644 --- a/javatests/google/registry/flows/domain/DomainCheckFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCheckFlowTest.java @@ -274,23 +274,20 @@ public class DomainCheckFlowTest @Test public void testFailure_tooManyIds() throws Exception { setEppInput("domain_check_51.xml"); - thrown.expect(TooManyResourceChecksException.class); - runFlow(); + assertThrows(TooManyResourceChecksException.class, () -> runFlow()); } @Test public void testFailure_wrongTld() throws Exception { setEppInput("domain_check.xml"); - thrown.expect(TldDoesNotExistException.class); - runFlow(); + assertThrows(TldDoesNotExistException.class, () -> runFlow()); } @Test public void testFailure_notAuthorizedForTld() throws Exception { persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - runFlow(); + assertThrows(NotAuthorizedForTldException.class, () -> runFlow()); } @Test @@ -389,8 +386,7 @@ public class DomainCheckFlowTest @Test public void testFailure_predelegation() throws Exception { createTld("tld", TldState.PREDELEGATION); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -677,177 +673,152 @@ public class DomainCheckFlowTest @Test public void testFeeExtension_wrongCurrency_v06() throws Exception { setEppInput("domain_check_fee_euro_v06.xml"); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test public void testFeeExtension_wrongCurrency_v11() throws Exception { setEppInput("domain_check_fee_euro_v11.xml"); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test public void testFeeExtension_wrongCurrency_v12() throws Exception { setEppInput("domain_check_fee_euro_v12.xml"); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test public void testFeeExtension_periodNotInYears_v06() throws Exception { setEppInput("domain_check_fee_bad_period_v06.xml"); - thrown.expect(BadPeriodUnitException.class); - runFlow(); + assertThrows(BadPeriodUnitException.class, () -> runFlow()); } @Test public void testFeeExtension_periodNotInYears_v11() throws Exception { setEppInput("domain_check_fee_bad_period_v11.xml"); - thrown.expect(BadPeriodUnitException.class); - runFlow(); + assertThrows(BadPeriodUnitException.class, () -> runFlow()); } @Test public void testFeeExtension_periodNotInYears_v12() throws Exception { setEppInput("domain_check_fee_bad_period_v12.xml"); - thrown.expect(BadPeriodUnitException.class); - runFlow(); + assertThrows(BadPeriodUnitException.class, () -> runFlow()); } @Test public void testFeeExtension_commandWithPhase_v06() throws Exception { setEppInput("domain_check_fee_command_phase_v06.xml"); - thrown.expect(FeeChecksDontSupportPhasesException.class); - runFlow(); + assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow()); } @Test public void testFeeExtension_commandWithPhase_v11() throws Exception { setEppInput("domain_check_fee_command_phase_v11.xml"); - thrown.expect(FeeChecksDontSupportPhasesException.class); - runFlow(); + assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow()); } @Test public void testFeeExtension_commandWithPhase_v12() throws Exception { setEppInput("domain_check_fee_command_phase_v12.xml"); - thrown.expect(FeeChecksDontSupportPhasesException.class); - runFlow(); + assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow()); } @Test public void testFeeExtension_commandSubphase_v06() throws Exception { setEppInput("domain_check_fee_command_subphase_v06.xml"); - thrown.expect(FeeChecksDontSupportPhasesException.class); - runFlow(); + assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow()); } @Test public void testFeeExtension_commandSubphase_v11() throws Exception { setEppInput("domain_check_fee_command_subphase_v11.xml"); - thrown.expect(FeeChecksDontSupportPhasesException.class); - runFlow(); + assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow()); } @Test public void testFeeExtension_commandSubphase_v12() throws Exception { setEppInput("domain_check_fee_command_subphase_v12.xml"); - thrown.expect(FeeChecksDontSupportPhasesException.class); - runFlow(); + assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow()); } // This test is only relevant for v06, since domain names are not specified in v11 or v12. @Test public void testFeeExtension_feeCheckNotInAvailabilityCheck() throws Exception { setEppInput("domain_check_fee_not_in_avail.xml"); - thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class); - runFlow(); + assertThrows(OnlyCheckedNamesCanBeFeeCheckedException.class, () -> runFlow()); } @Test public void testFeeExtension_multiyearRestore_v06() throws Exception { setEppInput("domain_check_fee_multiyear_restore_v06.xml"); - thrown.expect(RestoresAreAlwaysForOneYearException.class); - runFlow(); + assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow()); } @Test public void testFeeExtension_multiyearRestore_v11() throws Exception { setEppInput("domain_check_fee_multiyear_restore_v11.xml"); - thrown.expect(RestoresAreAlwaysForOneYearException.class); - runFlow(); + assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow()); } @Test public void testFeeExtension_multiyearRestore_v12() throws Exception { setEppInput("domain_check_fee_multiyear_restore_v12.xml"); - thrown.expect(RestoresAreAlwaysForOneYearException.class); - runFlow(); + assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow()); } @Test public void testFeeExtension_multiyearTransfer_v06() throws Exception { setEppInput("domain_check_fee_multiyear_transfer_v06.xml"); - thrown.expect(TransfersAreAlwaysForOneYearException.class); - runFlow(); + assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow()); } @Test public void testFeeExtension_multiyearTransfer_v11() throws Exception { setEppInput("domain_check_fee_multiyear_transfer_v11.xml"); - thrown.expect(TransfersAreAlwaysForOneYearException.class); - runFlow(); + assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow()); } @Test public void testFeeExtension_multiyearTransfer_v12() throws Exception { setEppInput("domain_check_fee_multiyear_transfer_v12.xml"); - thrown.expect(TransfersAreAlwaysForOneYearException.class); - runFlow(); + assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow()); } @Test public void testFeeExtension_unknownCommand_v06() throws Exception { setEppInput("domain_check_fee_unknown_command_v06.xml"); - thrown.expect(UnknownFeeCommandException.class); - runFlow(); + assertThrows(UnknownFeeCommandException.class, () -> runFlow()); } @Test public void testFeeExtension_unknownCommand_v11() throws Exception { setEppInput("domain_check_fee_unknown_command_v11.xml"); - thrown.expect(UnknownFeeCommandException.class); - runFlow(); + assertThrows(UnknownFeeCommandException.class, () -> runFlow()); } @Test public void testFeeExtension_unknownCommand_v12() throws Exception { setEppInput("domain_check_fee_unknown_command_v12.xml"); - thrown.expect(UnknownFeeCommandException.class); - runFlow(); + assertThrows(UnknownFeeCommandException.class, () -> runFlow()); } @Test public void testFeeExtension_invalidCommand_v06() throws Exception { setEppInput("domain_check_fee_invalid_command_v06.xml"); - thrown.expect(UnknownFeeCommandException.class); - runFlow(); + assertThrows(UnknownFeeCommandException.class, () -> runFlow()); } @Test public void testFeeExtension_invalidCommand_v11() throws Exception { setEppInput("domain_check_fee_invalid_command_v11.xml"); - thrown.expect(UnknownFeeCommandException.class); - runFlow(); + assertThrows(UnknownFeeCommandException.class, () -> runFlow()); } @Test public void testFeeExtension_invalidCommand_v12() throws Exception { setEppInput("domain_check_fee_invalid_command_v12.xml"); - thrown.expect(UnknownFeeCommandException.class); - runFlow(); + assertThrows(UnknownFeeCommandException.class, () -> runFlow()); } private void runEapFeeCheckTest(String inputFile, String outputFile) throws Exception { diff --git a/javatests/google/registry/flows/domain/DomainClaimsCheckFlowTest.java b/javatests/google/registry/flows/domain/DomainClaimsCheckFlowTest.java index a33a8f333..00db01b38 100644 --- a/javatests/google/registry/flows/domain/DomainClaimsCheckFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainClaimsCheckFlowTest.java @@ -18,6 +18,7 @@ import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -101,23 +102,20 @@ public class DomainClaimsCheckFlowTest @Test public void testFailure_TooManyIds() throws Exception { setEppInput("domain_check_claims_51.xml"); - thrown.expect(TooManyResourceChecksException.class); - runFlow(); + assertThrows(TooManyResourceChecksException.class, () -> runFlow()); } @Test public void testFailure_tldDoesntExist() throws Exception { setEppInput("domain_check_claims_bad_tld.xml"); - thrown.expect(TldDoesNotExistException.class); - runFlow(); + assertThrows(TldDoesNotExistException.class, () -> runFlow()); } @Test public void testFailure_notAuthorizedForTld() throws Exception { persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - runFlow(); + assertThrows(NotAuthorizedForTldException.class, () -> runFlow()); } @Test @@ -138,8 +136,7 @@ public class DomainClaimsCheckFlowTest createTld("tld", TldState.PREDELEGATION); persistResource(Registry.get("tld").asBuilder().build()); setEppInput("domain_check_claims.xml"); - thrown.expect(BadCommandForRegistryPhaseException.class); - runFlow(); + assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow()); } @Test @@ -147,8 +144,7 @@ public class DomainClaimsCheckFlowTest createTld("tld", TldState.SUNRISE); persistResource(Registry.get("tld").asBuilder().build()); setEppInput("domain_check_claims.xml"); - thrown.expect(DomainClaimsCheckNotAllowedInSunrise.class); - runFlow(); + assertThrows(DomainClaimsCheckNotAllowedInSunrise.class, () -> runFlow()); } @Test @@ -158,8 +154,7 @@ public class DomainClaimsCheckFlowTest persistResource( Registry.get("tld2").asBuilder().setClaimsPeriodEnd(clock.nowUtc().minusMillis(1)).build()); setEppInput("domain_check_claims_multiple_tlds.xml"); - thrown.expect(ClaimsPeriodEndedException.class); - runFlow(); + assertThrows(ClaimsPeriodEndedException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index 4013a20e1..139ccbc43 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -386,8 +386,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -395,8 +394,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -536,72 +534,63 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_refundableFee_v11() throws Exception { setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_refundableFee_v12() throws Exception { setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v06() throws Exception { setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v11() throws Exception { setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v12() throws Exception { setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v06() throws Exception { setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v11() throws Exception { setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v12() throws Exception { setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12")); persistContactsAndHosts(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -621,8 +610,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -649,9 +637,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("Invalid limited registration period token"); } @Test @@ -750,8 +737,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -783,8 +769,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -792,8 +777,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -804,40 +788,35 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_tooManyNameservers() throws Exception { setEppInput("domain_create_14_nameservers.xml"); persistContactsAndHosts(); - thrown.expect(TooManyNameserversException.class); - runFlow(); + assertThrows(TooManyNameserversException.class, () -> runFlow()); } @Test public void testFailure_secDnsMaxSigLife() throws Exception { setEppInput("domain_create_dsdata.xml"); persistContactsAndHosts(); - thrown.expect(MaxSigLifeNotSupportedException.class); - runFlow(); + assertThrows(MaxSigLifeNotSupportedException.class, () -> runFlow()); } @Test public void testFailure_secDnsTooManyDsRecords() throws Exception { setEppInput("domain_create_dsdata_9_records.xml"); persistContactsAndHosts(); - thrown.expect(TooManyDsRecordsException.class); - runFlow(); + assertThrows(TooManyDsRecordsException.class, () -> runFlow()); } @Test public void testFailure_wrongExtension() throws Exception { setEppInput("domain_create_wrong_extension.xml"); persistContactsAndHosts(); - thrown.expect(UnimplementedExtensionException.class); - runFlow(); + assertThrows(UnimplementedExtensionException.class, () -> runFlow()); } @Test @@ -846,8 +825,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -856,8 +834,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -866,8 +843,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -882,8 +858,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -898,8 +873,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -914,8 +888,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -939,16 +912,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_anchorTenantViaAuthCode_wrongAuthCode() throws Exception { setEppInput("domain_create_anchor_wrong_authcode.xml"); persistContactsAndHosts(); - thrown.expect(DomainReservedException.class); - runFlow(); + assertThrows(DomainReservedException.class, () -> runFlow()); } @Test @@ -1045,9 +1016,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("(ns2.example.net)"); } @Test @@ -1059,9 +1030,10 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.net"); } @Test @@ -1069,8 +1041,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1095,9 +1066,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("(sh8013)"); } @Test @@ -1109,57 +1080,52 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("jd1234"); } @Test public void testFailure_wrongTld() throws Exception { persistContactsAndHosts("net"); deleteTld("tld"); - thrown.expect(TldDoesNotExistException.class); - runFlow(); + assertThrows(TldDoesNotExistException.class, () -> runFlow()); } @Test public void testFailure_predelegation() throws Exception { createTld("tld", TldState.PREDELEGATION); persistContactsAndHosts(); - thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); - runFlow(); + assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow()); } @Test public void testFailure_sunrise() throws Exception { createTld("tld", TldState.SUNRISE); persistContactsAndHosts(); - thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); - runFlow(); + assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow()); } @Test public void testFailure_sunrush() throws Exception { createTld("tld", TldState.SUNRUSH); persistContactsAndHosts(); - thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); - runFlow(); + assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow()); } @Test public void testFailure_landrush() throws Exception { createTld("tld", TldState.LANDRUSH); persistContactsAndHosts(); - thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); - runFlow(); + assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow()); } @Test public void testFailure_quietPeriod() throws Exception { createTld("tld", TldState.QUIET_PERIOD); persistContactsAndHosts(); - thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); - runFlow(); + assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow()); } @Test @@ -1232,8 +1198,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1241,40 +1206,35 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_missingRegistrant() throws Exception { setEppInput("domain_create_missing_registrant.xml"); persistContactsAndHosts(); - thrown.expect(MissingRegistrantException.class); - runFlow(); + assertThrows(MissingRegistrantException.class, () -> runFlow()); } @Test public void testFailure_missingAdmin() throws Exception { setEppInput("domain_create_missing_admin.xml"); persistContactsAndHosts(); - thrown.expect(MissingAdminContactException.class); - runFlow(); + assertThrows(MissingAdminContactException.class, () -> runFlow()); } @Test public void testFailure_missingTech() throws Exception { setEppInput("domain_create_missing_tech.xml"); persistContactsAndHosts(); - thrown.expect(MissingTechnicalContactException.class); - runFlow(); + assertThrows(MissingTechnicalContactException.class, () -> runFlow()); } @Test public void testFailure_missingNonRegistrantContacts() throws Exception { setEppInput("domain_create_missing_non_registrant_contacts.xml"); persistContactsAndHosts(); - thrown.expect(MissingAdminContactException.class); - runFlow(); + assertThrows(MissingAdminContactException.class, () -> runFlow()); } @Test @@ -1282,8 +1242,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1291,16 +1250,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_codeMark() throws Exception { setEppInput("domain_create_code_with_mark.xml"); persistContactsAndHosts(); - thrown.expect(UnsupportedMarkTypeException.class); - runFlow(); + assertThrows(UnsupportedMarkTypeException.class, () -> runFlow()); } @Test @@ -1308,8 +1265,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1317,8 +1273,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1326,8 +1281,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1335,8 +1289,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1344,8 +1297,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1353,8 +1305,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1367,8 +1318,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1376,8 +1326,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1388,8 +1337,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1400,8 +1348,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1412,32 +1359,28 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v06() throws Exception { setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6")); persistContactsAndHosts(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v11() throws Exception { setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11")); persistContactsAndHosts(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v12() throws Exception { setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12")); persistContactsAndHosts(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test @@ -1450,8 +1393,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } private void doFailingDomainNameTest( @@ -1534,8 +1476,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1586,8 +1527,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1599,8 +1539,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1651,8 +1590,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1705,9 +1643,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("jd1234"); } @Test @@ -1716,9 +1654,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1728,8 +1666,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1770,8 +1708,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1784,9 +1722,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1800,9 +1738,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("example.tld"); } @Test @@ -1850,9 +1788,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1869,9 +1807,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.net"); } @Test @@ -1890,9 +1828,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("example.tld"); } @Test @@ -2020,8 +1958,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java index 80853c4cd..c248c8448 100644 --- a/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java @@ -42,6 +42,8 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -636,8 +638,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -651,17 +652,17 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -674,16 +675,14 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_unauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); persistActiveDomain(getUniqueIdFromCommand()); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -700,8 +699,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -719,9 +717,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("clientDeleteProhibited"); } @Test @@ -729,9 +727,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("serverDeleteProhibited"); } @Test @@ -739,9 +737,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test @@ -764,8 +762,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainInfoFlowTest.java index 30432d4b8..df9f4d16a 100644 --- a/javatests/google/registry/flows/domain/DomainInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainInfoFlowTest.java @@ -23,6 +23,8 @@ import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; @@ -373,9 +375,9 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -383,9 +385,9 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -397,8 +399,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -409,8 +410,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -425,8 +425,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -440,8 +439,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -456,8 +454,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -471,8 +468,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -483,8 +479,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -494,8 +489,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** @@ -574,8 +568,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** Test requesting a period that isn't in years. */ @@ -583,8 +576,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** Test a command that specifies a phase. */ @@ -592,8 +584,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** Test a command that specifies a subphase. */ @@ -601,8 +592,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** Test a restore for more than one year. */ @@ -610,8 +600,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** Test a transfer for more than one year. */ @@ -619,8 +608,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase runFlow()); } /** Test that we load contacts and hosts as a batch rather than individually. */ diff --git a/javatests/google/registry/flows/domain/DomainRenewFlowTest.java b/javatests/google/registry/flows/domain/DomainRenewFlowTest.java index b67a87a62..f775984a7 100644 --- a/javatests/google/registry/flows/domain/DomainRenewFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainRenewFlowTest.java @@ -27,6 +27,8 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.EUR; @@ -291,72 +293,63 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_refundableFee_v11() throws Exception { setEppInput("domain_renew_fee_refundable.xml", FEE_11_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_refundableFee_v12() throws Exception { setEppInput("domain_renew_fee_refundable.xml", FEE_12_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v06() throws Exception { setEppInput("domain_renew_fee_grace_period.xml", FEE_06_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v11() throws Exception { setEppInput("domain_renew_fee_grace_period.xml", FEE_11_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v12() throws Exception { setEppInput("domain_renew_fee_grace_period.xml", FEE_12_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v06() throws Exception { setEppInput("domain_renew_fee_applied.xml", FEE_06_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v11() throws Exception { setEppInput("domain_renew_fee_applied.xml", FEE_11_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v12() throws Exception { setEppInput("domain_renew_fee_applied.xml", FEE_12_MAP); persistDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -410,33 +403,33 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_clientRenewProhibited() throws Exception { persistDomain(StatusValue.CLIENT_RENEW_PROHIBITED); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("clientRenewProhibited"); - runFlow(); + ResourceStatusProhibitsOperationException thrown = + expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("clientRenewProhibited"); } @Test public void testFailure_serverRenewProhibited() throws Exception { persistDomain(StatusValue.SERVER_RENEW_PROHIBITED); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("serverRenewProhibited"); - runFlow(); + ResourceStatusProhibitsOperationException thrown = + expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("serverRenewProhibited"); } @Test @@ -446,9 +439,9 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test @@ -460,8 +453,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -473,8 +465,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -486,8 +477,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -504,8 +494,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -522,8 +511,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -540,32 +528,28 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v06() throws Exception { setEppInput("domain_renew_fee_bad_scale.xml", FEE_06_MAP); persistDomain(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v11() throws Exception { setEppInput("domain_renew_fee_bad_scale.xml", FEE_11_MAP); persistDomain(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v12() throws Exception { setEppInput("domain_renew_fee_bad_scale.xml", FEE_12_MAP); persistDomain(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test @@ -575,25 +559,23 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("pendingTransfer"); } @Test public void testFailure_periodInMonths() throws Exception { setEppInput("domain_renew_months.xml"); persistDomain(); - thrown.expect(BadPeriodUnitException.class); - runFlow(); + assertThrows(BadPeriodUnitException.class, () -> runFlow()); } @Test public void testFailure_max10Years() throws Exception { setEppInput("domain_renew_11_years.xml"); persistDomain(); - thrown.expect(ExceedsMaxRegistrationYearsException.class); - runFlow(); + assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow()); } @Test @@ -603,16 +585,14 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_unauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); persistActiveDomain(getUniqueIdFromCommand()); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test @@ -628,8 +608,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -647,8 +626,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainRestoreRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainRestoreRequestFlowTest.java index c43810318..304f3a5a7 100644 --- a/javatests/google/registry/flows/domain/DomainRestoreRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainRestoreRequestFlowTest.java @@ -27,6 +27,8 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -232,72 +234,63 @@ public class DomainRestoreRequestFlowTest extends public void testFailure_refundableFee_v06() throws Exception { setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_refundableFee_v11() throws Exception { setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_refundableFee_v12() throws Exception { setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v06() throws Exception { setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v11() throws Exception { setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_gracePeriodFee_v12() throws Exception { setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v06() throws Exception { setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v11() throws Exception { setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test public void testFailure_appliedFee_v12() throws Exception { setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP); persistPendingDeleteDomain(); - thrown.expect(UnsupportedFeeAttributeException.class); - runFlow(); + assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow()); } @Test @@ -340,9 +333,9 @@ public class DomainRestoreRequestFlowTest extends @Test public void testFailure_doesNotExist() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -351,8 +344,7 @@ public class DomainRestoreRequestFlowTest extends persistPendingDeleteDomain(); persistResource( Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build()); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } @Test @@ -361,8 +353,7 @@ public class DomainRestoreRequestFlowTest extends persistPendingDeleteDomain(); persistResource( Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build()); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } @Test @@ -371,8 +362,7 @@ public class DomainRestoreRequestFlowTest extends persistPendingDeleteDomain(); persistResource( Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build()); - thrown.expect(FeesMismatchException.class); - runFlow(); + assertThrows(FeesMismatchException.class, () -> runFlow()); } private void runWrongCurrencyTest(Map substitutions) throws Exception { @@ -388,8 +378,7 @@ public class DomainRestoreRequestFlowTest extends .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .setServerStatusChangeBillingCost(Money.of(EUR, 19)) .build()); - thrown.expect(CurrencyUnitMismatchException.class); - runFlow(); + assertThrows(CurrencyUnitMismatchException.class, () -> runFlow()); } @Test @@ -411,24 +400,21 @@ public class DomainRestoreRequestFlowTest extends public void testFailure_feeGivenInWrongScale_v06() throws Exception { setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP); persistPendingDeleteDomain(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v11() throws Exception { setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP); persistPendingDeleteDomain(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test public void testFailure_feeGivenInWrongScale_v12() throws Exception { setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP); persistPendingDeleteDomain(); - thrown.expect(CurrencyValueScaleException.class); - runFlow(); + assertThrows(CurrencyValueScaleException.class, () -> runFlow()); } @Test @@ -439,70 +425,63 @@ public class DomainRestoreRequestFlowTest extends .setDeletionTime(clock.nowUtc().plusDays(4)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); - thrown.expect(DomainNotEligibleForRestoreException.class); - runFlow(); + assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow()); } @Test public void testFailure_notDeleted() throws Exception { persistActiveDomain(getUniqueIdFromCommand()); - thrown.expect(DomainNotEligibleForRestoreException.class); - runFlow(); + assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow()); } @Test public void testFailure_fullyDeleted() throws Exception { persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - runFlow(); + assertThrows(ResourceDoesNotExistException.class, () -> runFlow()); } @Test public void testFailure_withChange() throws Exception { persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_change.xml"); - thrown.expect(RestoreCommandIncludesChangesException.class); - runFlow(); + assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow()); } @Test public void testFailure_withAdd() throws Exception { persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_add.xml"); - thrown.expect(RestoreCommandIncludesChangesException.class); - runFlow(); + assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow()); } @Test public void testFailure_withRemove() throws Exception { persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_remove.xml"); - thrown.expect(RestoreCommandIncludesChangesException.class); - runFlow(); + assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow()); } @Test public void testFailure_withSecDnsExtension() throws Exception { persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_secdns.xml"); - thrown.expect(UnimplementedExtensionException.class); - runFlow(); + assertThrows(UnimplementedExtensionException.class, () -> runFlow()); } @Test public void testFailure_unauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); persistPendingDeleteDomain(); - thrown.expect(ResourceNotOwnedException.class); - runFlow(); + assertThrows(ResourceNotOwnedException.class, () -> runFlow()); } @Test public void testSuccess_superuserUnauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); persistPendingDeleteDomain(); - thrown.expect(ResourceNotOwnedException.class); - runFlowAssertResponse(loadFile("domain_update_response.xml")); + assertThrows( + ResourceNotOwnedException.class, + () -> runFlowAssertResponse(loadFile("domain_update_response.xml"))); } @Test @@ -510,8 +489,7 @@ public class DomainRestoreRequestFlowTest extends persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); persistPendingDeleteDomain(); - thrown.expect(NotAuthorizedForTldException.class); - runFlow(); + assertThrows(NotAuthorizedForTldException.class, () -> runFlow()); } @Test @@ -530,8 +508,7 @@ public class DomainRestoreRequestFlowTest extends persistPendingDeleteDomain(); // Modify the Registrar to block premium names. persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build()); - thrown.expect(PremiumNameBlockedException.class); - runFlow(); + assertThrows(PremiumNameBlockedException.class, () -> runFlow()); } @Test @@ -543,8 +520,7 @@ public class DomainRestoreRequestFlowTest extends .setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED")) .build()); persistPendingDeleteDomain(); - thrown.expect(DomainReservedException.class); - runFlow(); + assertThrows(DomainReservedException.class, () -> runFlow()); } @Test @@ -552,8 +528,7 @@ public class DomainRestoreRequestFlowTest extends createTld("example"); setEppInput("domain_update_restore_request_premium.xml"); persistPendingDeleteDomain(); - thrown.expect(FeesRequiredForPremiumNameException.class); - runFlow(); + assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java index d23113138..dc3df37c2 100644 --- a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java @@ -32,6 +32,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.USD; @@ -406,8 +408,9 @@ public class DomainTransferApproveFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_approve_contact_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_approve_contact_authinfo.xml")); } @Test @@ -416,89 +419,97 @@ public class DomainTransferApproveFlowTest persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_approve_domain_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_approve_domain_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_clientApproved() throws Exception { changeTransferStatus(TransferStatus.CLIENT_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_clientRejected() throws Exception { changeTransferStatus(TransferStatus.CLIENT_REJECTED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_clientCancelled() throws Exception { changeTransferStatus(TransferStatus.CLIENT_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_serverApproved() throws Exception { changeTransferStatus(TransferStatus.SERVER_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_serverCancelled() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_gainingClient() throws Exception { setClientIdForFlow("NewRegistrar"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("domain_transfer_approve.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml")); } @Test public void testFailure_deletedDomain() throws Exception { persistResource( domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_approve.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("domain_transfer_approve.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentDomain() throws Exception { deleteResource(domain); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_approve.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("domain_transfer_approve.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_notAuthorizedForTld() throws Exception { persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml"); + assertThrows( + NotAuthorizedForTldException.class, + () -> + doSuccessfulTest( + "tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml")); } @Test diff --git a/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java index 99f931b03..54bdcbc50 100644 --- a/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java @@ -29,6 +29,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.END_OF_TIME; import com.google.common.collect.ImmutableList; @@ -211,8 +213,9 @@ public class DomainTransferCancelFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_cancel_contact_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_cancel_contact_authinfo.xml")); } @Test @@ -221,89 +224,94 @@ public class DomainTransferCancelFlowTest domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_cancel_domain_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_cancel_domain_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_clientApproved() throws Exception { changeTransferStatus(TransferStatus.CLIENT_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_clientRejected() throws Exception { changeTransferStatus(TransferStatus.CLIENT_REJECTED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_clientCancelled() throws Exception { changeTransferStatus(TransferStatus.CLIENT_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_serverApproved() throws Exception { changeTransferStatus(TransferStatus.SERVER_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_serverCancelled() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_sponsoringClient() throws Exception { setClientIdForFlow("TheRegistrar"); - thrown.expect(NotTransferInitiatorException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(NotTransferInitiatorException.class); - doFailingTest("domain_transfer_cancel.xml"); + assertThrows( + NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml")); } @Test public void testFailure_deletedDomain() throws Exception { domain = persistResource( domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_cancel.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentDomain() throws Exception { deleteResource(domain); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_cancel.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_notAuthorizedForTld() throws Exception { persistResource( loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"); + assertThrows( + NotAuthorizedForTldException.class, + () -> + doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml")); } @Test diff --git a/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java index 5c49abec8..36c8471e4 100644 --- a/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java @@ -20,6 +20,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; @@ -175,8 +177,9 @@ public class DomainTransferQueryFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_query_contact_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_query_contact_authinfo.xml")); } @Test @@ -185,39 +188,43 @@ public class DomainTransferQueryFlowTest domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_query_domain_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_query_domain_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NoTransferHistoryToQueryException.class); - doFailingTest("domain_transfer_query.xml"); + assertThrows( + NoTransferHistoryToQueryException.class, () -> doFailingTest("domain_transfer_query.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(NotAuthorizedToViewTransferException.class); - doFailingTest("domain_transfer_query.xml"); + assertThrows( + NotAuthorizedToViewTransferException.class, + () -> doFailingTest("domain_transfer_query.xml")); } @Test public void testFailure_deletedDomain() throws Exception { domain = persistResource( domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_query.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentDomain() throws Exception { deleteResource(domain); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_query.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test diff --git a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java index dceb40ca1..9287f430a 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java @@ -31,6 +31,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.END_OF_TIME; import com.google.common.collect.ImmutableSet; @@ -174,8 +176,10 @@ public class DomainTransferRejectFlowTest public void testFailure_notAuthorizedForTld() throws Exception { persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml"); + assertThrows( + NotAuthorizedForTldException.class, + () -> + doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml")); } @Test @@ -193,8 +197,9 @@ public class DomainTransferRejectFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_reject_contact_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_reject_contact_authinfo.xml")); } @Test @@ -204,81 +209,84 @@ public class DomainTransferRejectFlowTest domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_reject_domain_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_reject_domain_authinfo.xml")); } @Test public void testFailure_neverBeenTransferred() throws Exception { changeTransferStatus(null); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_clientApproved() throws Exception { changeTransferStatus(TransferStatus.CLIENT_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_clientRejected() throws Exception { changeTransferStatus(TransferStatus.CLIENT_REJECTED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_clientCancelled() throws Exception { changeTransferStatus(TransferStatus.CLIENT_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_serverApproved() throws Exception { changeTransferStatus(TransferStatus.SERVER_APPROVED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_serverCancelled() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - thrown.expect(NotPendingTransferException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_gainingClient() throws Exception { setClientIdForFlow("NewRegistrar"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_unrelatedClient() throws Exception { setClientIdForFlow("ClientZ"); - thrown.expect(ResourceNotOwnedException.class); - doFailingTest("domain_transfer_reject.xml"); + assertThrows( + ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml")); } @Test public void testFailure_deletedDomain() throws Exception { domain = persistResource( domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_reject.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonexistentDomain() throws Exception { deleteResource(domain); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_reject.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } // NB: No need to test pending delete status since pending transfers will get cancelled upon diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java index f1ad0a7b4..8f60fd9f2 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -33,6 +33,8 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HostResourceSubject.assertAboutHosts; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static java.util.stream.Collectors.toSet; import static org.joda.money.CurrencyUnit.EUR; @@ -643,64 +645,73 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_refundableFee_v06() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_06_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_06_MAP)); } @Test public void testFailure_refundableFee_v11() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_11_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_11_MAP)); } @Test public void testFailure_refundableFee_v12() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_12_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_12_MAP)); } @Test public void testFailure_gracePeriodFee_v06() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_06_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_06_MAP)); } @Test public void testFailure_gracePeriodFee_v11() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_11_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_11_MAP)); } @Test public void testFailure_gracePeriodFee_v12() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_12_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_12_MAP)); } @Test public void testFailure_appliedFee_v06() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_applied.xml", FEE_06_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_06_MAP)); } @Test public void testFailure_appliedFee_v11() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_applied.xml", FEE_11_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_11_MAP)); } @Test public void testFailure_appliedFee_v12() throws Exception { setupDomain("example", "tld"); - thrown.expect(UnsupportedFeeAttributeException.class); - doFailingTest("domain_transfer_request_fee_applied.xml", FEE_12_MAP); + assertThrows( + UnsupportedFeeAttributeException.class, + () -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_12_MAP)); } @Test @@ -739,8 +750,9 @@ public class DomainTransferRequestFlowTest public void testFailure_multiYearPeriod() throws Exception { setupDomain("example", "tld"); clock.advanceOneMilli(); - thrown.expect(TransferPeriodMustBeOneYearException.class); - doFailingTest("domain_transfer_request_2_years.xml"); + assertThrows( + TransferPeriodMustBeOneYearException.class, + () -> doFailingTest("domain_transfer_request_2_years.xml")); } @Test @@ -826,11 +838,13 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); eppRequestSource = EppRequestSource.TOOL; clock.advanceOneMilli(); - thrown.expect(InvalidTransferPeriodValueException.class); - runTest( - "domain_transfer_request_superuser_extension.xml", - UserPrivileges.SUPERUSER, - ImmutableMap.of("PERIOD", "2", "AUTOMATIC_TRANSFER_LENGTH", "5")); + assertThrows( + InvalidTransferPeriodValueException.class, + () -> + runTest( + "domain_transfer_request_superuser_extension.xml", + UserPrivileges.SUPERUSER, + ImmutableMap.of("PERIOD", "2", "AUTOMATIC_TRANSFER_LENGTH", "5"))); } @Test @@ -838,11 +852,13 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); eppRequestSource = EppRequestSource.TOOL; clock.advanceOneMilli(); - thrown.expect(TransferPeriodZeroAndFeeTransferExtensionException.class); - runTest( - "domain_transfer_request_fee_and_superuser_extension.xml", - UserPrivileges.SUPERUSER, - ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "5")); + assertThrows( + TransferPeriodZeroAndFeeTransferExtensionException.class, + () -> + runTest( + "domain_transfer_request_fee_and_superuser_extension.xml", + UserPrivileges.SUPERUSER, + ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "5"))); } @Test @@ -894,8 +910,11 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); persistResource( loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - thrown.expect(NotAuthorizedForTldException.class); - doSuccessfulTest("domain_transfer_request.xml", "domain_transfer_request_response.xml"); + assertThrows( + NotAuthorizedForTldException.class, + () -> + doSuccessfulTest( + "domain_transfer_request.xml", "domain_transfer_request_response.xml")); } @Test @@ -1035,8 +1054,9 @@ public class DomainTransferRequestFlowTest .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .setServerStatusChangeBillingCost(Money.of(EUR, 19)) .build()); - thrown.expect(CurrencyUnitMismatchException.class); - doFailingTest("domain_transfer_request_fee.xml", substitutions); + assertThrows( + CurrencyUnitMismatchException.class, + () -> doFailingTest("domain_transfer_request_fee.xml", substitutions)); } @Test @@ -1060,22 +1080,25 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_feeGivenInWrongScale_v06() throws Exception { setupDomain("example", "tld"); - thrown.expect(CurrencyValueScaleException.class); - doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_06_MAP); + assertThrows( + CurrencyValueScaleException.class, + () -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_06_MAP)); } @Test public void testFailure_feeGivenInWrongScale_v11() throws Exception { setupDomain("example", "tld"); - thrown.expect(CurrencyValueScaleException.class); - doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_11_MAP); + assertThrows( + CurrencyValueScaleException.class, + () -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_11_MAP)); } @Test public void testFailure_feeGivenInWrongScale_v12() throws Exception { setupDomain("example", "tld"); - thrown.expect(CurrencyValueScaleException.class); - doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_12_MAP); + assertThrows( + CurrencyValueScaleException.class, + () -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_12_MAP)); } private void runWrongFeeAmountTest(Map substitutions) throws Exception { @@ -1084,8 +1107,9 @@ public class DomainTransferRequestFlowTest .asBuilder() .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .build()); - thrown.expect(FeesMismatchException.class); - doFailingTest("domain_transfer_request_fee.xml", substitutions); + assertThrows( + FeesMismatchException.class, + () -> doFailingTest("domain_transfer_request_fee.xml", substitutions)); } @Test @@ -1112,22 +1136,25 @@ public class DomainTransferRequestFlowTest // Modify the Registrar to block premium names. persistResource( loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build()); - thrown.expect(PremiumNameBlockedException.class); - doFailingTest("domain_transfer_request_premium.xml"); + assertThrows( + PremiumNameBlockedException.class, + () -> doFailingTest("domain_transfer_request_premium.xml")); } @Test public void testFailure_feeNotProvidedOnPremiumName() throws Exception { setupDomain("rich", "example"); - thrown.expect(FeesRequiredForPremiumNameException.class); - doFailingTest("domain_transfer_request_premium.xml"); + assertThrows( + FeesRequiredForPremiumNameException.class, + () -> doFailingTest("domain_transfer_request_premium.xml")); } @Test public void testFailure_noAuthInfo() throws Exception { setupDomain("example", "tld"); - thrown.expect(MissingTransferRequestAuthInfoException.class); - doFailingTest("domain_transfer_request_no_authinfo.xml"); + assertThrows( + MissingTransferRequestAuthInfoException.class, + () -> doFailingTest("domain_transfer_request_no_authinfo.xml")); } @Test @@ -1138,8 +1165,8 @@ public class DomainTransferRequestFlowTest contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_request.xml"); + assertThrows( + BadAuthInfoForResourceException.class, () -> doFailingTest("domain_transfer_request.xml")); } @Test @@ -1148,8 +1175,8 @@ public class DomainTransferRequestFlowTest // Set the contact to a different ROID, but don't persist it; this is just so the substitution // code above will write the wrong ROID into the file. contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build(); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_request.xml"); + assertThrows( + BadAuthInfoForResourceException.class, () -> doFailingTest("domain_transfer_request.xml")); } @Test @@ -1196,8 +1223,8 @@ public class DomainTransferRequestFlowTest .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .build()) .build()); - thrown.expect(AlreadyPendingTransferException.class); - doFailingTest("domain_transfer_request.xml"); + assertThrows( + AlreadyPendingTransferException.class, () -> doFailingTest("domain_transfer_request.xml")); } @Test @@ -1207,16 +1234,17 @@ public class DomainTransferRequestFlowTest domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); - thrown.expect(BadAuthInfoForResourceException.class); - doFailingTest("domain_transfer_request_domain_authinfo.xml"); + assertThrows( + BadAuthInfoForResourceException.class, + () -> doFailingTest("domain_transfer_request_domain_authinfo.xml")); } @Test public void testFailure_sponsoringClient() throws Exception { setupDomain("example", "tld"); setClientIdForFlow("TheRegistrar"); - thrown.expect(ObjectAlreadySponsoredException.class); - doFailingTest("domain_transfer_request.xml"); + assertThrows( + ObjectAlreadySponsoredException.class, () -> doFailingTest("domain_transfer_request.xml")); } @Test @@ -1224,9 +1252,11 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); domain = persistResource( domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - doFailingTest("domain_transfer_request.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("domain_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -1237,25 +1267,29 @@ public class DomainTransferRequestFlowTest ImmutableMap.of("YEARS", "1", "DOMAIN", "--invalid", "EXDATE", "2002-09-08T22:00:00.0Z")); eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); assertTransactionalFlow(true); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage("(--invalid)"); - runFlow(CommitMode.LIVE, UserPrivileges.NORMAL); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> runFlow(CommitMode.LIVE, UserPrivileges.NORMAL)); + assertThat(thrown).hasMessageThat().contains("(--invalid)"); } @Test public void testFailure_nonexistentDomain() throws Exception { createTld("tld"); contact = persistActiveContact("jd1234"); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", "example.tld")); - doFailingTest("domain_transfer_request.xml"); + ResourceDoesNotExistException thrown = + expectThrows( + ResourceDoesNotExistException.class, + () -> doFailingTest("domain_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", "example.tld")); } @Test public void testFailure_periodInMonths() throws Exception { setupDomain("example", "tld"); - thrown.expect(BadPeriodUnitException.class); - doFailingTest("domain_transfer_request_months.xml"); + assertThrows( + BadPeriodUnitException.class, () -> doFailingTest("domain_transfer_request_months.xml")); } @Test @@ -1263,9 +1297,11 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); domain = persistResource( domain.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("clientTransferProhibited"); - doFailingTest("domain_transfer_request.xml"); + ResourceStatusProhibitsOperationException thrown = + expectThrows( + ResourceStatusProhibitsOperationException.class, + () -> doFailingTest("domain_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains("clientTransferProhibited"); } @Test @@ -1273,9 +1309,11 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); domain = persistResource( domain.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("serverTransferProhibited"); - doFailingTest("domain_transfer_request.xml"); + ResourceStatusProhibitsOperationException thrown = + expectThrows( + ResourceStatusProhibitsOperationException.class, + () -> doFailingTest("domain_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains("serverTransferProhibited"); } @Test @@ -1283,9 +1321,11 @@ public class DomainTransferRequestFlowTest setupDomain("example", "tld"); domain = persistResource( domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build()); - thrown.expect(ResourceStatusProhibitsOperationException.class); - thrown.expectMessage("pendingDelete"); - doFailingTest("domain_transfer_request.xml"); + ResourceStatusProhibitsOperationException thrown = + expectThrows( + ResourceStatusProhibitsOperationException.class, + () -> doFailingTest("domain_transfer_request.xml")); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test diff --git a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java index eb2e767db..b13b3d7bd 100644 --- a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -440,8 +440,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -795,8 +794,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -806,8 +804,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -815,25 +812,24 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_neverExisted() throws Exception { persistReferencedEntities(); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistReferencedEntities(); persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -842,9 +838,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("(ns2.example.foo)"); } @Test @@ -853,9 +849,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("(sh8013)"); } @Test @@ -871,8 +867,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -880,8 +875,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -941,8 +935,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -952,9 +945,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited"); } @Test @@ -965,9 +958,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test @@ -975,8 +968,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -985,8 +977,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -994,8 +985,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1014,8 +1004,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1038,8 +1027,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1053,8 +1041,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1067,8 +1054,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1081,8 +1067,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1096,9 +1081,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("mak21"); } @Test @@ -1113,9 +1099,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.foo"); } @Test @@ -1127,8 +1114,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1140,8 +1126,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1223,8 +1208,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1252,9 +1237,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.foo"); } @Test @@ -1269,8 +1254,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1314,9 +1299,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.foo"); } @Test @@ -1349,9 +1334,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.foo"); } @Test @@ -1367,9 +1352,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.foo"); } @Test @@ -1387,8 +1372,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1403,8 +1387,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1458,8 +1441,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } // This test should throw an exception, because the fee extension is required when the fee is not @@ -1469,8 +1451,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/host/HostCheckFlowTest.java b/javatests/google/registry/flows/host/HostCheckFlowTest.java index b7fbf8f9c..a2a6bb2cd 100644 --- a/javatests/google/registry/flows/host/HostCheckFlowTest.java +++ b/javatests/google/registry/flows/host/HostCheckFlowTest.java @@ -17,6 +17,7 @@ package google.registry.flows.host; import static google.registry.model.eppoutput.CheckData.HostCheck.create; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost; +import static google.registry.testing.JUnitBackports.assertThrows; import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.exceptions.TooManyResourceChecksException; @@ -75,8 +76,7 @@ public class HostCheckFlowTest extends ResourceCheckFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/host/HostCreateFlowTest.java b/javatests/google/registry/flows/host/HostCreateFlowTest.java index 2f7baf989..cc13b907d 100644 --- a/javatests/google/registry/flows/host/HostCreateFlowTest.java +++ b/javatests/google/registry/flows/host/HostCreateFlowTest.java @@ -26,6 +26,7 @@ import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; @@ -125,8 +126,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -154,8 +154,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -163,17 +162,16 @@ public class HostCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_superordinateMissing() throws Exception { setEppHostCreateInput("ns1.example.tld", null); createTld("tld"); - thrown.expect(SuperordinateDomainDoesNotExistException.class); - thrown.expectMessage("(example.tld)"); - runFlow(); + SuperordinateDomainDoesNotExistException thrown = + expectThrows(SuperordinateDomainDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("(example.tld)"); } @Test @@ -186,48 +184,49 @@ public class HostCreateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown) + .hasMessageThat() + .contains("Superordinate domain for this hostname is in pending delete"); } @Test public void testFailure_alreadyExists() throws Exception { setEppHostCreateInput("ns1.example.tld", null); persistActiveHost(getUniqueIdFromCommand()); - thrown.expect(ResourceAlreadyExistsException.class); - thrown.expectMessage( - String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); - runFlow(); + ResourceAlreadyExistsException thrown = + expectThrows(ResourceAlreadyExistsException.class, () -> runFlow()); + assertThat(thrown) + .hasMessageThat() + .contains( + String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); } @Test public void testFailure_nonLowerCaseHostname() throws Exception { setEppHostCreateInput("ns1.EXAMPLE.tld", null); - thrown.expect(HostNameNotLowerCaseException.class); - runFlow(); + assertThrows(HostNameNotLowerCaseException.class, () -> runFlow()); } @Test public void testFailure_nonPunyCodedHostname() throws Exception { setEppHostCreateInput("ns1.çauçalito.みんな", null); - thrown.expect(HostNameNotPunyCodedException.class); - thrown.expectMessage("expected ns1.xn--aualito-txac.xn--q9jyb4c"); - runFlow(); + HostNameNotPunyCodedException thrown = + expectThrows(HostNameNotPunyCodedException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.xn--q9jyb4c"); } @Test public void testFailure_nonCanonicalHostname() throws Exception { setEppHostCreateInput("ns1.example.tld.", null); - thrown.expect(HostNameNotNormalizedException.class); - runFlow(); + assertThrows(HostNameNotNormalizedException.class, () -> runFlow()); } @Test public void testFailure_longHostName() throws Exception { setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld"); - thrown.expect(HostNameTooLongException.class); - runFlow(); + assertThrows(HostNameTooLongException.class, () -> runFlow()); } @Test @@ -237,8 +236,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase192.0.2.2\n" + "192.0.2.29\n" + "1080:0:0:0:8:800:200C:417A"); - thrown.expect(IpAddressVersionMismatchException.class); - runFlow(); + assertThrows(IpAddressVersionMismatchException.class, () -> runFlow()); } private void doFailingHostNameTest(String hostName, Class exception) @@ -281,8 +279,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/host/HostDeleteFlowTest.java b/javatests/google/registry/flows/host/HostDeleteFlowTest.java index 2639fb4e2..07868960b 100644 --- a/javatests/google/registry/flows/host/HostDeleteFlowTest.java +++ b/javatests/google/registry/flows/host/HostDeleteFlowTest.java @@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.HostResourceSubject.assertAboutHosts; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; @@ -83,17 +84,17 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("(ns1.example.tld)"); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage("(ns1.example.tld)"); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("(ns1.example.tld)"); } private void doFailingStatusTest(StatusValue statusValue, Class exception) @@ -129,8 +130,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -181,8 +181,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -237,8 +236,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -248,8 +246,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -259,30 +256,27 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase runFlow()); } @Test public void testFailure_nonLowerCaseHostname() throws Exception { setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET")); - thrown.expect(HostNameNotLowerCaseException.class); - runFlow(); + assertThrows(HostNameNotLowerCaseException.class, () -> runFlow()); } @Test public void testFailure_nonPunyCodedHostname() throws Exception { setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld")); - thrown.expect(HostNameNotPunyCodedException.class); - thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); - runFlow(); + HostNameNotPunyCodedException thrown = + expectThrows(HostNameNotPunyCodedException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld"); } @Test public void testFailure_nonCanonicalHostname() throws Exception { setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld.")); - thrown.expect(HostNameNotNormalizedException.class); - runFlow(); + assertThrows(HostNameNotNormalizedException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/host/HostInfoFlowTest.java b/javatests/google/registry/flows/host/HostInfoFlowTest.java index ddd78237d..bb3703b1c 100644 --- a/javatests/google/registry/flows/host/HostInfoFlowTest.java +++ b/javatests/google/registry/flows/host/HostInfoFlowTest.java @@ -14,10 +14,13 @@ package google.registry.flows.host; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -143,40 +146,38 @@ public class HostInfoFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistResource( persistHostResource().asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_nonLowerCaseHostname() throws Exception { setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET")); - thrown.expect(HostNameNotLowerCaseException.class); - runFlow(); + assertThrows(HostNameNotLowerCaseException.class, () -> runFlow()); } @Test public void testFailure_nonPunyCodedHostname() throws Exception { setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld")); - thrown.expect(HostNameNotPunyCodedException.class); - thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); - runFlow(); + HostNameNotPunyCodedException thrown = + expectThrows(HostNameNotPunyCodedException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld"); } @Test public void testFailure_nonCanonicalHostname() throws Exception { setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld.")); - thrown.expect(HostNameNotNormalizedException.class); - runFlow(); + assertThrows(HostNameNotNormalizedException.class, () -> runFlow()); } @Test diff --git a/javatests/google/registry/flows/host/HostUpdateFlowTest.java b/javatests/google/registry/flows/host/HostUpdateFlowTest.java index 598779d32..5a66883ec 100644 --- a/javatests/google/registry/flows/host/HostUpdateFlowTest.java +++ b/javatests/google/registry/flows/host/HostUpdateFlowTest.java @@ -408,8 +408,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -760,9 +759,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("(example.tld)"); } @Test @@ -781,32 +780,34 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown) + .hasMessageThat() + .contains("Superordinate domain for this hostname is in pending delete"); } @Test public void testFailure_neverExisted() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_neverExisted_updateWithoutNameChange() throws Exception { setEppInput("host_update_name_unchanged.xml"); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedHost(oldHostName(), clock.nowUtc().minusDays(1)); - thrown.expect(ResourceDoesNotExistException.class); - thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); - runFlow(); + ResourceDoesNotExistException thrown = + expectThrows(ResourceDoesNotExistException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); } @Test @@ -815,9 +816,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns1.example.tld"); } @Test @@ -825,57 +826,53 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("ns2.example.tld"); } @Test public void testFailure_referToNonLowerCaseHostname() throws Exception { setEppHostUpdateInput("ns1.EXAMPLE.tld", "ns2.example.tld", null, null); - thrown.expect(HostNameNotLowerCaseException.class); - runFlow(); + assertThrows(HostNameNotLowerCaseException.class, () -> runFlow()); } @Test public void testFailure_renameToNonLowerCaseHostname() throws Exception { persistActiveHost("ns1.example.tld"); setEppHostUpdateInput("ns1.example.tld", "ns2.EXAMPLE.tld", null, null); - thrown.expect(HostNameNotLowerCaseException.class); - runFlow(); + assertThrows(HostNameNotLowerCaseException.class, () -> runFlow()); } @Test public void testFailure_referToNonPunyCodedHostname() throws Exception { setEppHostUpdateInput("ns1.çauçalito.tld", "ns1.sausalito.tld", null, null); - thrown.expect(HostNameNotPunyCodedException.class); - thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); - runFlow(); + HostNameNotPunyCodedException thrown = + expectThrows(HostNameNotPunyCodedException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld"); } @Test public void testFailure_renameToNonPunyCodedHostname() throws Exception { persistActiveHost("ns1.sausalito.tld"); setEppHostUpdateInput("ns1.sausalito.tld", "ns1.çauçalito.tld", null, null); - thrown.expect(HostNameNotPunyCodedException.class); - thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); - runFlow(); + HostNameNotPunyCodedException thrown = + expectThrows(HostNameNotPunyCodedException.class, () -> runFlow()); + assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld"); } @Test public void testFailure_referToNonCanonicalHostname() throws Exception { persistActiveHost("ns1.example.tld."); setEppHostUpdateInput("ns1.example.tld.", "ns2.example.tld", null, null); - thrown.expect(HostNameNotNormalizedException.class); - runFlow(); + assertThrows(HostNameNotNormalizedException.class, () -> runFlow()); } @Test public void testFailure_renameToNonCanonicalHostname() throws Exception { persistActiveHost("ns1.example.tld"); setEppHostUpdateInput("ns1.example.tld", "ns2.example.tld.", null, null); - thrown.expect(HostNameNotNormalizedException.class); - runFlow(); + assertThrows(HostNameNotNormalizedException.class, () -> runFlow()); } @Test @@ -887,8 +884,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase1080:0:0:0:8:800:200C:417A"); createTld("tld"); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); - thrown.expect(CannotRemoveSubordinateHostLastIpException.class); - runFlow(); + assertThrows(CannotRemoveSubordinateHostLastIpException.class, () -> runFlow()); } @Test @@ -900,8 +896,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -913,8 +908,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -927,8 +921,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase", ""); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); - thrown.expect(AddRemoveSameValueException.class); - runFlow(); + assertThrows(AddRemoveSameValueException.class, () -> runFlow()); } @Test @@ -940,8 +933,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase192.0.2.22", "192.0.2.22"); - thrown.expect(AddRemoveSameValueException.class); - runFlow(); + assertThrows(AddRemoveSameValueException.class, () -> runFlow()); } @Test @@ -965,8 +957,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -977,9 +968,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited"); } @Test @@ -990,9 +981,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); + assertThat(thrown).hasMessageThat().contains("pendingDelete"); } @Test @@ -1000,8 +991,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1022,8 +1012,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1070,8 +1059,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1104,8 +1092,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1125,8 +1112,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test @@ -1146,8 +1132,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase runFlow()); } @Test diff --git a/javatests/google/registry/flows/poll/PollRequestFlowTest.java b/javatests/google/registry/flows/poll/PollRequestFlowTest.java index 7f0a364c4..4afe651ff 100644 --- a/javatests/google/registry/flows/poll/PollRequestFlowTest.java +++ b/javatests/google/registry/flows/poll/PollRequestFlowTest.java @@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import com.google.common.collect.ImmutableList; import google.registry.flows.FlowTestCase; @@ -220,7 +221,6 @@ public class PollRequestFlowTest extends FlowTestCase { public void testFailure_messageIdProvided() throws Exception { setEppInput("poll_with_id.xml"); assertTransactionalFlow(false); - thrown.expect(UnexpectedMessageIdException.class); - runFlow(); + assertThrows(UnexpectedMessageIdException.class, () -> runFlow()); } } diff --git a/javatests/google/registry/flows/session/LogoutFlowTest.java b/javatests/google/registry/flows/session/LogoutFlowTest.java index d8e01d8e1..da6b8d38e 100644 --- a/javatests/google/registry/flows/session/LogoutFlowTest.java +++ b/javatests/google/registry/flows/session/LogoutFlowTest.java @@ -15,6 +15,7 @@ package google.registry.flows.session; import static google.registry.testing.DatastoreHelper.createTld; +import static google.registry.testing.JUnitBackports.assertThrows; import google.registry.flows.FlowTestCase; import google.registry.flows.FlowUtils.NotLoggedInException; @@ -43,7 +44,6 @@ public class LogoutFlowTest extends FlowTestCase { @Test public void testFailure() throws Exception { sessionMetadata.setClientId(null); // Turn off the implicit login - thrown.expect(NotLoggedInException.class); - runFlow(); + assertThrows(NotLoggedInException.class, () -> runFlow()); } } diff --git a/javatests/google/registry/tools/AllocateDomainCommandTest.java b/javatests/google/registry/tools/AllocateDomainCommandTest.java index 65480b7b9..f715d541b 100644 --- a/javatests/google/registry/tools/AllocateDomainCommandTest.java +++ b/javatests/google/registry/tools/AllocateDomainCommandTest.java @@ -28,6 +28,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.beust.jcommander.ParameterException; @@ -131,20 +132,21 @@ public class AllocateDomainCommandTest extends CommandTestCase runCommand("--ids=1-TLD", "--force")); } @Test public void testFailure_forceAndDryRunIncompatible() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--ids=1-TLD", "--force", "--dry_run", "--superuser"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--ids=1-TLD", "--force", "--dry_run", "--superuser")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--ids=1-TLD", "--force", "--unrecognized=foo", "--superuser"); + assertThrows( + ParameterException.class, + () -> runCommand("--ids=1-TLD", "--force", "--unrecognized=foo", "--superuser")); } @Test diff --git a/javatests/google/registry/tools/AuthModuleTest.java b/javatests/google/registry/tools/AuthModuleTest.java index d180432a7..a817c67b3 100644 --- a/javatests/google/registry/tools/AuthModuleTest.java +++ b/javatests/google/registry/tools/AuthModuleTest.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,9 +29,7 @@ import com.google.api.client.util.store.DataStore; import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.io.Serializable; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -61,9 +60,6 @@ public class AuthModuleTest { return result; } } - - @Rule public final ExpectedException thrown = ExpectedException.none(); - @Test public void test_clientScopeQualifier() { AuthModule authModule = new AuthModule(); @@ -129,9 +125,8 @@ public class AuthModuleTest { @Test public void test_provideCredential_notStored() { - thrown.expect(AuthModule.LoginRequiredException.class); // Doing this without the mock setup should cause us to throw an exception because the // credential has not been stored. - getCredential(); + assertThrows(AuthModule.LoginRequiredException.class, () -> getCredential()); } } diff --git a/javatests/google/registry/tools/CommandTestCase.java b/javatests/google/registry/tools/CommandTestCase.java index 70ae53864..bdb475006 100644 --- a/javatests/google/registry/tools/CommandTestCase.java +++ b/javatests/google/registry/tools/CommandTestCase.java @@ -39,7 +39,6 @@ import java.io.PrintStream; import java.util.List; import org.junit.Before; import org.junit.Rule; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; @@ -63,9 +62,6 @@ public abstract class CommandTestCase { .withTaskQueue() .build(); - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @Rule public TemporaryFolder tmpDir = new TemporaryFolder(); diff --git a/javatests/google/registry/tools/CreateAnchorTenantCommandTest.java b/javatests/google/registry/tools/CreateAnchorTenantCommandTest.java index e28b089de..31a002be5 100644 --- a/javatests/google/registry/tools/CreateAnchorTenantCommandTest.java +++ b/javatests/google/registry/tools/CreateAnchorTenantCommandTest.java @@ -17,6 +17,7 @@ package google.registry.tools; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import com.beust.jcommander.ParameterException; import google.registry.model.registry.Registry; @@ -83,43 +84,80 @@ public class CreateAnchorTenantCommandTest @Test public void testFailure_mainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--tld=tld", "--client=NewRegistrar", "--superuser", - "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld", "foo"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--tld=tld", + "--client=NewRegistrar", + "--superuser", + "--reason=anchor-tenant-test", + "--contact=jd1234", + "--domain_name=example.tld", + "foo")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--superuser", - "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--superuser", + "--reason=anchor-tenant-test", + "--contact=jd1234", + "--domain_name=example.tld")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--foo=bar", "--client=NewRegistrar", "--superuser", - "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--foo=bar", + "--client=NewRegistrar", + "--superuser", + "--reason=anchor-tenant-test", + "--contact=jd1234", + "--domain_name=example.tld")); } @Test public void testFailure_missingDomainName() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--superuser", - "--reason=anchor-tenant-test", "--contact=jd1234", "foo"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--superuser", + "--reason=anchor-tenant-test", + "--contact=jd1234", + "foo")); } @Test public void testFailure_missingContact() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--superuser", - "--reason=anchor-tenant-test", "--domain_name=example.tld", "foo"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--superuser", + "--reason=anchor-tenant-test", + "--domain_name=example.tld", + "foo")); } @Test public void testFailure_notAsSuperuser() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced("--client=NewRegistrar", - "--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--reason=anchor-tenant-test", + "--contact=jd1234", + "--domain_name=example.tld")); } } diff --git a/javatests/google/registry/tools/CreateContactCommandTest.java b/javatests/google/registry/tools/CreateContactCommandTest.java index c49737a38..e277db2e1 100644 --- a/javatests/google/registry/tools/CreateContactCommandTest.java +++ b/javatests/google/registry/tools/CreateContactCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import google.registry.testing.DeterministicStringGenerator; import org.junit.Before; @@ -58,30 +60,31 @@ public class CreateContactCommandTest extends EppToolCommandTestCase runCommandForced()); } @Test public void testFailure_tooManyStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--client=NewRegistrar", - "--street=\"123 Example Dr.\"", - "--street=\"Floor 3\"", - "--street=\"Suite 100\"", - "--street=\"Office 1\""); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--street=\"123 Example Dr.\"", + "--street=\"Floor 3\"", + "--street=\"Suite 100\"", + "--street=\"Office 1\"")); } @Test public void testFailure_badPhone() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--phone=3"); + assertThrows( + ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--phone=3")); } @Test public void testFailure_badFax() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--fax=3"); + assertThrows( + ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--fax=3")); } } diff --git a/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java b/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java index 92145e789..8305c6432 100644 --- a/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java +++ b/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java @@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.money.CurrencyUnit.USD; import static org.joda.time.DateTimeZone.UTC; @@ -80,75 +81,96 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase + runCommandForced( + "--registrar=FakeRegistrar", + "--credit_id=" + creditId, + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found"); } @Test public void testFailure_nonexistentCreditId() throws Exception { long badId = creditId + 1; - thrown.expect(NullPointerException.class); - thrown.expectMessage("ID " + badId); - runCommandForced( - "--registrar=TheRegistrar", - "--credit_id=" + badId, - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + NullPointerException thrown = + expectThrows( + NullPointerException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--credit_id=" + badId, + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("ID " + badId); } @Test public void testFailure_negativeBalance() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("negative"); - runCommandForced( - "--registrar=TheRegistrar", - "--credit_id=" + creditId, - "--balance=\"USD -1\"", - "--effective_time=2014-11-01T01:02:03Z"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--credit_id=" + creditId, + "--balance=\"USD -1\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("negative"); } @Test public void testFailure_noRegistrar() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--registrar"); - runCommandForced( - "--credit_id=" + creditId, - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--credit_id=" + creditId, + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--registrar"); } @Test public void testFailure_noCreditId() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--credit_id"); - runCommandForced( - "--registrar=TheRegistrar", - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--credit_id"); } @Test public void testFailure_noBalance() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--balance"); - runCommandForced( - "--registrar=TheRegistrar", - "--credit_id=" + creditId, - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--credit_id=" + creditId, + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--balance"); } @Test public void testFailure_noEffectiveTime() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--effective_time"); - runCommandForced( - "--registrar=TheRegistrar", - "--credit_id=" + creditId, - "--balance=\"USD 100\""); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--credit_id=" + creditId, + "--balance=\"USD 100\"")); + assertThat(thrown).hasMessageThat().contains("--effective_time"); } } diff --git a/javatests/google/registry/tools/CreateCreditCommandTest.java b/javatests/google/registry/tools/CreateCreditCommandTest.java index 862a45ea6..efd1299fe 100644 --- a/javatests/google/registry/tools/CreateCreditCommandTest.java +++ b/javatests/google/registry/tools/CreateCreditCommandTest.java @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadRegistrar; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.money.CurrencyUnit.USD; import static org.joda.time.DateTimeZone.UTC; @@ -93,104 +94,131 @@ public class CreateCreditCommandTest extends CommandTestCase + runCommandForced( + "--registrar=FakeRegistrar", + "--type=PROMOTION", + "--tld=tld", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found"); } @Test public void testFailure_nonexistentTld() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("faketld"); - runCommandForced( - "--registrar=TheRegistrar", - "--type=PROMOTION", - "--tld=faketld", - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--type=PROMOTION", + "--tld=faketld", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("faketld"); } @Test public void testFailure_nonexistentType() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Invalid value for --type"); - runCommandForced( - "--registrar=TheRegistrar", - "--type=BADTYPE", - "--tld=tld", - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--type=BADTYPE", + "--tld=tld", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("Invalid value for --type"); } @Test public void testFailure_negativeBalance() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("negative"); - runCommandForced( - "--registrar=TheRegistrar", - "--type=PROMOTION", - "--tld=tld", - "--balance=\"USD -1\"", - "--effective_time=2014-11-01T01:02:03Z"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--type=PROMOTION", + "--tld=tld", + "--balance=\"USD -1\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("negative"); } @Test public void testFailure_noRegistrar() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--registrar"); - runCommandForced( - "--type=PROMOTION", - "--tld=tld", - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--type=PROMOTION", + "--tld=tld", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--registrar"); } @Test public void testFailure_noType() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--type"); - runCommandForced( - "--registrar=TheRegistrar", - "--tld=tld", - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--tld=tld", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--type"); } @Test public void testFailure_noTld() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--tld"); - runCommandForced( - "--registrar=TheRegistrar", - "--type=PROMOTION", - "--balance=\"USD 100\"", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--type=PROMOTION", + "--balance=\"USD 100\"", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--tld"); } @Test public void testFailure_noBalance() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--balance"); - runCommandForced( - "--registrar=TheRegistrar", - "--type=PROMOTION", - "--tld=tld", - "--effective_time=2014-11-01T01:02:03Z"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--type=PROMOTION", + "--tld=tld", + "--effective_time=2014-11-01T01:02:03Z")); + assertThat(thrown).hasMessageThat().contains("--balance"); } @Test public void testFailure_noEffectiveTime() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--effective_time"); - runCommandForced( - "--registrar=TheRegistrar", - "--type=PROMOTION", - "--tld=tld", - "--balance=\"USD 100\""); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=TheRegistrar", + "--type=PROMOTION", + "--tld=tld", + "--balance=\"USD 100\"")); + assertThat(thrown).hasMessageThat().contains("--effective_time"); } } diff --git a/javatests/google/registry/tools/CreateDomainCommandTest.java b/javatests/google/registry/tools/CreateDomainCommandTest.java index 36f6e4317..6729adfb5 100644 --- a/javatests/google/registry/tools/CreateDomainCommandTest.java +++ b/javatests/google/registry/tools/CreateDomainCommandTest.java @@ -14,6 +14,9 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; + import com.beust.jcommander.ParameterException; import google.registry.testing.DeterministicStringGenerator; import org.junit.Before; @@ -69,86 +72,122 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admins=crr-admin", + "--techs=crr-tech", + "example.tld", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("Duplicate arguments found: \'example.tld\'"); } @Test public void testFailure_missingDomain() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Main parameters are required"); - runCommandForced( - "--client=NewRegistrar", - "--registrant=crr-admin", - "--admins=crr-admin", - "--techs=crr-tech"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admins=crr-admin", + "--techs=crr-tech")); + assertThat(thrown).hasMessageThat().contains("Main parameters are required"); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--client"); - runCommandForced( - "--admins=crr-admin", "--techs=crr-tech", "--registrant=crr-admin", "example.tld"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--admins=crr-admin", + "--techs=crr-tech", + "--registrant=crr-admin", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("--client"); } @Test public void testFailure_missingRegistrant() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrant must be specified"); - runCommandForced( - "--client=NewRegistrar", "--admins=crr-admin", "--techs=crr-tech", "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--admins=crr-admin", + "--techs=crr-tech", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("Registrant must be specified"); } @Test public void testFailure_missingAdmins() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("At least one admin must be specified"); - runCommandForced( - "--client=NewRegistrar", "--registrant=crr-admin", "--techs=crr-tech", "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--techs=crr-tech", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("At least one admin must be specified"); } @Test public void testFailure_missingTechs() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("At least one tech must be specified"); - runCommandForced( - "--client=NewRegistrar", "--registrant=crr-admin", "--admins=crr-admin", "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admins=crr-admin", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("At least one tech must be specified"); } @Test public void testFailure_tooManyNameServers() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("There can be at most 13 nameservers"); - runCommandForced( - "--client=NewRegistrar", - "--registrant=crr-admin", - "--admins=crr-admin", - "--techs=crr-tech", - "--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google," - + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google," - + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google," - + "ns13.zdns.google,ns14.zdns.google", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admins=crr-admin", + "--techs=crr-tech", + "--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google," + + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google," + + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google," + + "ns13.zdns.google,ns14.zdns.google", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("There can be at most 13 nameservers"); } @Test public void testFailure_badPeriod() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--period"); - runCommandForced( - "--client=NewRegistrar", - "--registrant=crr-admin", - "--admins=crr-admin", - "--techs=crr-tech", - "--period=x", - "--domain=example.tld"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admins=crr-admin", + "--techs=crr-tech", + "--period=x", + "--domain=example.tld")); + assertThat(thrown).hasMessageThat().contains("--period"); } } diff --git a/javatests/google/registry/tools/CreateHostCommandTest.java b/javatests/google/registry/tools/CreateHostCommandTest.java index b62c3cf46..e387a799a 100644 --- a/javatests/google/registry/tools/CreateHostCommandTest.java +++ b/javatests/google/registry/tools/CreateHostCommandTest.java @@ -14,7 +14,10 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTld; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -43,18 +46,18 @@ public class CreateHostCommandTest extends EppToolCommandTestCase runCommandForced("--client=NewRegistrar")); } @Test public void testFailure_invalidIpAddress() throws Exception { createTld("tld"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("'a.b.c.d' is not an IP string literal."); - runCommandForced( - "--client=NewRegistrar", - "--host=example.tld", - "--addresses=a.b.c.d"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", "--host=example.tld", "--addresses=a.b.c.d")); + assertThat(thrown).hasMessageThat().contains("'a.b.c.d' is not an IP string literal."); } } diff --git a/javatests/google/registry/tools/CreateLrpTokensCommandTest.java b/javatests/google/registry/tools/CreateLrpTokensCommandTest.java index 8d82aca44..fab6e6a90 100644 --- a/javatests/google/registry/tools/CreateLrpTokensCommandTest.java +++ b/javatests/google/registry/tools/CreateLrpTokensCommandTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static java.nio.charset.StandardCharsets.UTF_8; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -226,45 +227,69 @@ public class CreateLrpTokensCommandTest extends CommandTestCase runCommand("--tlds=tld")); + assertThat(thrown) + .hasMessageThat() + .contains("Exactly one of either assignee or filename must be specified."); } @Test public void testFailure_bothAssigneeAndFile() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Exactly one of either assignee or filename must be specified."); - runCommand("--assignee=domain.tld", "--tlds=tld", "--input=" + assigneeFilePath); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommand("--assignee=domain.tld", "--tlds=tld", "--input=" + assigneeFilePath)); + assertThat(thrown) + .hasMessageThat() + .contains("Exactly one of either assignee or filename must be specified."); } @Test public void testFailure_bothMetadataAndFile() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Metadata cannot be specified along with a filename."); - runCommand("--tlds=tld", "--input=" + assigneeFilePath, "--metadata=key=foo"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommand("--tlds=tld", "--input=" + assigneeFilePath, "--metadata=key=foo")); + assertThat(thrown) + .hasMessageThat() + .contains("Metadata cannot be specified along with a filename."); } @Test public void testFailure_bothAssigneeAndMetadataColumns() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Metadata columns cannot be specified along with an assignee."); - runCommand("--assignee=domain.tld", "--tlds=tld", "--metadata_columns=foo=1"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommand("--assignee=domain.tld", "--tlds=tld", "--metadata_columns=foo=1")); + assertThat(thrown) + .hasMessageThat() + .contains("Metadata columns cannot be specified along with an assignee."); } @Test public void testFailure_badTld() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("TLDs do not exist: foo"); - runCommand("--assignee=domain.tld", "--tlds=foo"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommand("--assignee=domain.tld", "--tlds=foo")); + assertThat(thrown).hasMessageThat().contains("TLDs do not exist: foo"); } @Test public void testFailure_oneAssignee_byFile_insufficientMetadata() throws Exception { Files.asCharSink(assigneeFile, UTF_8).write("domain.tld,foo"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Entry for domain.tld does not have a value for key2 (index 2)"); - runCommand("--input=" + assigneeFilePath, "--tlds=tld", "--metadata_columns=key=1,key2=2"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--input=" + assigneeFilePath, + "--tlds=tld", + "--metadata_columns=key=1,key2=2")); + assertThat(thrown) + .hasMessageThat() + .contains("Entry for domain.tld does not have a value for key2 (index 2)"); } private void assertLrpTokens(LrpTokenEntity... expected) throws Exception { diff --git a/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java b/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java index f608d2a25..f1298cb2f 100644 --- a/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java +++ b/javatests/google/registry/tools/CreateOrUpdateReservedListCommandTestCase.java @@ -14,6 +14,7 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.util.ResourceUtils.readResourceUtf8; import static java.nio.charset.StandardCharsets.UTF_8; @@ -50,17 +51,17 @@ public abstract class CreateOrUpdateReservedListCommandTestCase @Test public void testFailure_fileDoesntExist() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=xn--q9jyb4c-blah", - "--input=" + reservedTermsPath + "-nonexistent"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=xn--q9jyb4c-blah", "--input=" + reservedTermsPath + "-nonexistent")); } @Test public void testFailure_fileDoesntParse() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=xn--q9jyb4c-blork", - "--input=" + invalidReservedTermsPath); + assertThrows( + IllegalArgumentException.class, + () -> runCommandForced("--name=xn--q9jyb4c-blork", "--input=" + invalidReservedTermsPath)); } } diff --git a/javatests/google/registry/tools/CreatePremiumListCommandTest.java b/javatests/google/registry/tools/CreatePremiumListCommandTest.java index b5b7daf74..1dfdb9e91 100644 --- a/javatests/google/registry/tools/CreatePremiumListCommandTest.java +++ b/javatests/google/registry/tools/CreatePremiumListCommandTest.java @@ -14,7 +14,9 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.ResourceUtils.readResourceUtf8; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyMapOf; @@ -92,16 +94,16 @@ public class CreatePremiumListCommandTest any(byte[].class))) .thenReturn( JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}"); - thrown.expect(VerifyException.class); - thrown.expectMessage("Server error:"); - runCommandForced("-i=" + premiumTermsPath, "-n=foo"); + VerifyException thrown = + expectThrows( + VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo")); + assertThat(thrown).hasMessageThat().contains("Server error:"); } @Test public void testRun_noInputFileSpecified_throwsException() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("The following option is required"); - runCommand(); + ParameterException thrown = expectThrows(ParameterException.class, () -> runCommand()); + assertThat(thrown).hasMessageThat().contains("The following option is required"); } @Test @@ -110,8 +112,10 @@ public class CreatePremiumListCommandTest "tmp_file2", readResourceUtf8( CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv")); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Could not parse line in premium list"); - runCommandForced("-i=" + premiumTermsPath, "-n=foo"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo")); + assertThat(thrown).hasMessageThat().contains("Could not parse line in premium list"); } } diff --git a/javatests/google/registry/tools/CreateRegistrarCommandTest.java b/javatests/google/registry/tools/CreateRegistrarCommandTest.java index c0c39f3ea..0c8f2a986 100644 --- a/javatests/google/registry/tools/CreateRegistrarCommandTest.java +++ b/javatests/google/registry/tools/CreateRegistrarCommandTest.java @@ -21,6 +21,8 @@ import static google.registry.testing.CertificateSamples.SAMPLE_CERT; import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH; import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.persistNewRegistrar; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; @@ -441,23 +443,26 @@ public class CreateRegistrarCommandTest extends CommandTestCase + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--billing_account_map=JPY=789xyz", + "--allowed_tlds=foo", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("USD"); } @Test @@ -695,42 +700,48 @@ public class CreateRegistrarCommandTest extends CommandTestCase + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--phone=+1.112.555.6342", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("phone"); } @Test public void testFailure_badPhoneNumber2() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("phone"); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--phone=+1.5555555555e", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--phone=+1.5555555555e", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("phone"); } @Test @@ -757,807 +768,913 @@ public class CreateRegistrarCommandTest extends CommandTestCase + runCommandForced( + "--name=blobio", + "--password=some_password", + "--iana_id=8", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("Registrar type cannot be null"); } @Test public void testFailure_invalidRegistrarType() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=INVALID_TYPE", - "--iana_id=8", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=INVALID_TYPE", + "--iana_id=8", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_invalidRegistrarState() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--registrar_state=INVALID_STATE", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--registrar_state=INVALID_STATE", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_allowedTldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--allowed_tlds=foobar", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--allowed_tlds=foobar", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_invalidIpWhitelistFlag() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--ip_whitelist=foobarbaz", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--ip_whitelist=foobarbaz", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testSuccess_ipWhitelistFlagWithNull() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--ip_whitelist=192.168.1.1,192.168.0.2/16,null", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--ip_whitelist=192.168.1.1,192.168.0.2/16,null", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_invalidCertFileContents() throws Exception { - thrown.expect(Exception.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--cert_file=" + writeToTmpFile("ABCDEF"), - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + Exception.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--cert_file=" + writeToTmpFile("ABCDEF"), + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_invalidFailoverCertFileContents() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--failover_cert_file=" + writeToTmpFile("ABCDEF"), - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--failover_cert_file=" + writeToTmpFile("ABCDEF"), + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_certHashAndCertFile() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--cert_file=" + getCertFilename(), - "--cert_hash=ABCDEF", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--cert_file=" + getCertFilename(), + "--cert_hash=ABCDEF", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_certHashNotBase64() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("base64"); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--cert_hash=!", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--cert_hash=!", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("base64"); } @Test public void testFailure_certHashNotA256BitValue() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("256"); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--cert_hash=abc", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--cert_hash=abc", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("256"); } @Test public void testFailure_missingName() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("--name is a required field"); - runCommandForced( - "--password=blobio", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--password=blobio", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("--name is a required field"); } @Test public void testFailure_missingPassword() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("--password is a required field"); - runCommandForced( - "--name=blobio", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("--password is a required field"); } @Test public void testFailure_emptyPassword() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("--password is a required field"); - runCommandForced( - "--name=blobio", - "--password=\"\"", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=\"\"", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("--password is a required field"); } @Test public void testFailure_clientIdTooShort() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "ab"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "ab")); } @Test public void testFailure_clientIdTooLong() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientabcdefghijk"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientabcdefghijk")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "--force"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "--force")); } @Test public void testFailure_missingStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--city Brooklyn", - "--state NY", - "--zip 11223", - "--cc US", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc US", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_missingCity() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street=\"1234 Main St\"", - "--street \"4th Floor\"", - "--street \"Suite 1\"", - "--state NY", - "--zip 11223", - "--cc US", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--state NY", + "--zip 11223", + "--cc US", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_missingState() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street=\"1234 Main St\"", - "--street \"4th Floor\"", - "--street \"Suite 1\"", - "--city Brooklyn", - "--zip 11223", - "--cc US", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--zip 11223", + "--cc US", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_missingZip() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street=\"1234 Main St\"", - "--street \"4th Floor\"", - "--street \"Suite 1\"", - "--city Brooklyn", - "--state NY", - "--cc US", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--cc US", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_missingCc() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street=\"1234 Main St\"", - "--street \"4th Floor\"", - "--street \"Suite 1\"", - "--city Brooklyn", - "--state NY", - "--zip 11223", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_invalidCc() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street=\"1234 Main St\"", - "--street \"4th Floor\"", - "--street \"Suite 1\"", - "--city Brooklyn", - "--state NY", - "--zip 11223", - "--cc USA", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc USA", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_tooManyStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street=\"Attn:Hey You Guys\"", - "--street=\"1234 Main St\"", - "--street \"4th Floor\"", - "--street \"Suite 1\"", - "--city Brooklyn", - "--state NY", - "--zip 11223", - "--cc US", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street=\"Attn:Hey You Guys\"", + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc US", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_tooFewStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--street", - "--city Brooklyn", - "--state NY", - "--zip 11223", - "--cc US", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--street", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc US", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "clientz")); } @Test public void testFailure_missingIanaIdForRealRegistrar() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_negativeIanaId() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=-1", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=-1", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_nonIntegerIanaId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=ABC12345", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=ABC12345", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_negativeBillingId() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--billing_id=-1", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--billing_id=-1", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_nonIntegerBillingId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--billing_id=ABC12345", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--billing_id=ABC12345", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_missingPhonePasscode() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_missingIcannReferralEmail() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("--icann_referral_email"); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown).hasMessageThat().contains("--icann_referral_email"); } @Test public void testFailure_passcodeTooShort() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=0123", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=0123", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_passcodeTooLong() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=0123", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=0123", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_invalidPasscode() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=code1", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=code1", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_twoClientsSpecified() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "ClientY", - "clientz"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "ClientY", + "clientz")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--unrecognized_flag=foo", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--unrecognized_flag=foo", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_alreadyExists() throws Exception { persistNewRegistrar("existing", "Existing Registrar", Registrar.Type.REAL, 1L); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Registrar existing already exists"); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "existing"); + IllegalStateException thrown = + expectThrows( + IllegalStateException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "existing")); + assertThat(thrown).hasMessageThat().contains("Registrar existing already exists"); } @Test public void testFailure_registrarNameSimilarToExisting() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The registrar name tHeRe GiStRaR normalizes " - + "identically to existing registrar name The Registrar"); - // Normalizes identically to "The Registrar" which is created by AppEngineRule. - runCommandForced( - "--name=tHeRe GiStRaR", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + // Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by + // AppEngineRule. + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=tHeRe GiStRaR", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); + assertThat(thrown) + .hasMessageThat() + .contains( + "The registrar name tHeRe GiStRaR normalizes " + + "identically to existing registrar name The Registrar"); } @Test public void testFailure_clientIdNormalizesToExisting() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The registrar client identifier theregistrar " - + "normalizes identically to existing registrar TheRegistrar"); - runCommandForced( - "--name=blahhh", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "theregistrar"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blahhh", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "theregistrar")); + assertThat(thrown) + .hasMessageThat() + .contains( + "The registrar client identifier theregistrar " + + "normalizes identically to existing registrar TheRegistrar"); } @Test public void testFailure_clientIdIsInvalidFormat() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "Client identifier (.L33T) can only contain lowercase letters, numbers, and hyphens"); - runCommandForced( - "--name=blahhh", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - ".L33T"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--name=blahhh", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + ".L33T")); + assertThat(thrown) + .hasMessageThat() + .contains( + "Client identifier (.L33T) can only contain lowercase letters, numbers, and hyphens"); } @Test public void testFailure_phone() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--phone=3", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--phone=3", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } @Test public void testFailure_fax() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced( - "--name=blobio", - "--password=some_password", - "--registrar_type=REAL", - "--iana_id=8", - "--fax=3", - "--passcode=01234", - "--icann_referral_email=foo@bar.test", - "--street=\"123 Fake St\"", - "--city Fakington", - "--state MA", - "--zip 00351", - "--cc US", - "clientz"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--name=blobio", + "--password=some_password", + "--registrar_type=REAL", + "--iana_id=8", + "--fax=3", + "--passcode=01234", + "--icann_referral_email=foo@bar.test", + "--street=\"123 Fake St\"", + "--city Fakington", + "--state MA", + "--zip 00351", + "--cc US", + "clientz")); } } diff --git a/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java b/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java index bbb6fb999..0949fa0c6 100644 --- a/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java +++ b/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; @@ -54,9 +56,12 @@ public class CreateRegistrarGroupsCommandTest extends @Test public void test_throwsExceptionForNonExistentRegistrar() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "Could not load registrar with id FakeRegistrarThatDefinitelyDoesNotExist"); - runCommandForced("FakeRegistrarThatDefinitelyDoesNotExist"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("FakeRegistrarThatDefinitelyDoesNotExist")); + assertThat(thrown) + .hasMessageThat() + .contains("Could not load registrar with id FakeRegistrarThatDefinitelyDoesNotExist"); } } diff --git a/javatests/google/registry/tools/CreateReservedListCommandTest.java b/javatests/google/registry/tools/CreateReservedListCommandTest.java index 4c325e50a..bbd4c5187 100644 --- a/javatests/google/registry/tools/CreateReservedListCommandTest.java +++ b/javatests/google/registry/tools/CreateReservedListCommandTest.java @@ -21,6 +21,7 @@ import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE; import static org.joda.time.DateTimeZone.UTC; @@ -90,9 +91,11 @@ public class CreateReservedListCommandTest extends public void testFailure_reservedListWithThatNameAlreadyExists() throws Exception { ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED"); persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("A reserved list already exists by this name"); - runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath)); + assertThat(thrown).hasMessageThat().contains("A reserved list already exists by this name"); } @Test diff --git a/javatests/google/registry/tools/CreateTldCommandTest.java b/javatests/google/registry/tools/CreateTldCommandTest.java index 5ebb5e670..e192ceca9 100644 --- a/javatests/google/registry/tools/CreateTldCommandTest.java +++ b/javatests/google/registry/tools/CreateTldCommandTest.java @@ -78,16 +78,24 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_multipleArguments() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Can't create more than one TLD at a time"); - runCommandForced("--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c", "test"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c", "test")); + assertThat(thrown).hasMessageThat().contains("Can't create more than one TLD at a time"); } @Test public void testFailure_multipleDuplicateArguments() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Can't create more than one TLD at a time"); - runCommandForced("--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "test", "test"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "test", "test")); + assertThat(thrown).hasMessageThat().contains("Can't create more than one TLD at a time"); } @Test @@ -303,13 +311,16 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidAddGracePeriod() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"5m\""); - runCommandForced( - "--add_grace_period=5m", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--add_grace_period=5m", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\""); } @Test @@ -327,101 +338,131 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidRedemptionGracePeriod() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"5m\""); - runCommandForced( - "--redemption_grace_period=5m", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--redemption_grace_period=5m", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\""); } @Test public void testFailure_invalidPendingDeleteLength() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"5m\""); - runCommandForced( - "--pending_delete_length=5m", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--pending_delete_length=5m", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\""); } @Test public void testFailure_invalidTldState() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Invalid value for --initial_tld_state parameter"); - runCommandForced( - "--initial_tld_state=INVALID_STATE", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--initial_tld_state=INVALID_STATE", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid value for --initial_tld_state parameter"); } @Test public void testFailure_bothTldStateFlags() throws Exception { DateTime now = DateTime.now(UTC); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Don't pass both --initial_tld_state and --tld_state_transitions"); - runCommandForced( - String.format( - "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", - now, now.plus(Duration.millis(1))), - "--initial_tld_state=GENERAL_AVAILABILITY", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + String.format( + "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", + now, now.plus(Duration.millis(1))), + "--initial_tld_state=GENERAL_AVAILABILITY", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("Don't pass both --initial_tld_state and --tld_state_transitions"); } @Test public void testFailure_negativeInitialRenewBillingCost() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Renew billing cost cannot be negative"); - runCommandForced( - "--initial_renew_billing_cost=USD -42", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--initial_renew_billing_cost=USD -42", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Renew billing cost cannot be negative"); } @Test public void testFailure_invalidEapCurrency() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("All EAP fees must be in the registry's currency"); - runCommandForced( - String.format( - "--eap_fee_schedule=\"%s=JPY 123456\"", START_OF_TIME.toString(DATETIME_FORMAT)), - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + String.format( + "--eap_fee_schedule=\"%s=JPY 123456\"", + START_OF_TIME.toString(DATETIME_FORMAT)), + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("All EAP fees must be in the registry's currency"); } @Test public void testFailure_noTldName() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")"); - runCommandForced(); + ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced()); + assertThat(thrown) + .hasMessageThat() + .contains("Main parameters are required (\"Names of the TLDs\")"); } @Test public void testFailure_noDnsWriter() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("At least one DNS writer must be specified"); - runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C")); + assertThat(thrown).hasMessageThat().contains("At least one DNS writer must be specified"); } @Test public void testFailure_alreadyExists() throws Exception { createTld("xn--q9jyb4c"); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("TLD 'xn--q9jyb4c' already exists"); - runCommandForced("--roid_suffix=NOTDUPE", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c"); + IllegalStateException thrown = + expectThrows( + IllegalStateException.class, + () -> + runCommandForced( + "--roid_suffix=NOTDUPE", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("TLD 'xn--q9jyb4c' already exists"); } @Test public void testFailure_tldStartsWithDigit() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("TLDs cannot begin with a number"); - runCommandForced("1foo", "--roid_suffix=1FOO", "--dns_writers=VoidDnsWriter"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("1foo", "--roid_suffix=1FOO", "--dns_writers=VoidDnsWriter")); + assertThat(thrown).hasMessageThat().contains("TLDs cannot begin with a number"); } @Test @@ -556,43 +597,60 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_setPremiumListThatDoesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The premium list 'phonies' doesn't exist"); - runCommandForced( - "--premium_list=phonies", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--premium_list=phonies", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("The premium list 'phonies' doesn't exist"); } @Test public void testFailure_addLrpPeriod_backwardsInterval() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage( - "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval"); - runCommandForced( - "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains( + "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval"); } @Test public void testFailure_addLrpPeriod_badInterval() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval"); - runCommandForced( - "--lrp_period=foobar", - "--roid_suffix=Q9JYB4C", - "--dns_writers=VoidDnsWriter", - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--lrp_period=foobar", + "--roid_suffix=Q9JYB4C", + "--dns_writers=VoidDnsWriter", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("--lrp_period=foobar not an ISO-8601 interval"); } @Test public void testFailure_specifiedDnsWriters_dontExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid DNS writer name(s) specified: [Deadbeef, Invalid]"); - runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=Invalid,Deadbeef"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=Invalid,Deadbeef")); + assertThat(thrown) + .hasMessageThat() + .contains("Invalid DNS writer name(s) specified: [Deadbeef, Invalid]"); } private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { diff --git a/javatests/google/registry/tools/DeleteCreditCommandTest.java b/javatests/google/registry/tools/DeleteCreditCommandTest.java index dc4a15b0a..aa23eb689 100644 --- a/javatests/google/registry/tools/DeleteCreditCommandTest.java +++ b/javatests/google/registry/tools/DeleteCreditCommandTest.java @@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.money.CurrencyUnit.USD; import com.beust.jcommander.ParameterException; @@ -111,30 +112,34 @@ public class DeleteCreditCommandTest extends CommandTestCase runCommandForced("--registrar=TheRegistrar")); + assertThat(thrown).hasMessageThat().contains("--credit_id"); } } diff --git a/javatests/google/registry/tools/DeleteDomainCommandTest.java b/javatests/google/registry/tools/DeleteDomainCommandTest.java index fb08985e0..7d56a2b39 100644 --- a/javatests/google/registry/tools/DeleteDomainCommandTest.java +++ b/javatests/google/registry/tools/DeleteDomainCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -57,33 +59,48 @@ public class DeleteDomainCommandTest extends EppToolCommandTestCase runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--domain_name=example.tld", "--force", "--reason=Test"); + assertThrows( + ParameterException.class, + () -> runCommand("--domain_name=example.tld", "--force", "--reason=Test")); } @Test public void testFailure_missingDomainName() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--client=NewRegistrar", "--force", "--reason=Test"); + assertThrows( + ParameterException.class, + () -> runCommand("--client=NewRegistrar", "--force", "--reason=Test")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--client=NewRegistrar", "--domain_name=example.tld", "--force", "--reason=Test", "--foo"); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--domain_name=example.tld", + "--force", + "--reason=Test", + "--foo")); } @Test public void testFailure_mainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--client=NewRegistrar", "--domain_name=example.tld", "--force", "--reason=Test", "foo"); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--domain_name=example.tld", + "--force", + "--reason=Test", + "foo")); } } diff --git a/javatests/google/registry/tools/DeleteHostCommandTest.java b/javatests/google/registry/tools/DeleteHostCommandTest.java index 6938271f8..8891edfde 100644 --- a/javatests/google/registry/tools/DeleteHostCommandTest.java +++ b/javatests/google/registry/tools/DeleteHostCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -57,33 +59,48 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--host=ns1.example.tld", "--force", "--reason=Test"); + assertThrows( + ParameterException.class, + () -> runCommand("--host=ns1.example.tld", "--force", "--reason=Test")); } @Test public void testFailure_missingHostName() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--client=NewRegistrar", "--force", "--reason=Test"); + assertThrows( + ParameterException.class, + () -> runCommand("--client=NewRegistrar", "--force", "--reason=Test")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test", "--foo"); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--host=ns1.example.tld", + "--force", + "--reason=Test", + "--foo")); } @Test public void testFailure_mainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test", "foo"); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--host=ns1.example.tld", + "--force", + "--reason=Test", + "foo")); } } diff --git a/javatests/google/registry/tools/DeletePremiumListCommandTest.java b/javatests/google/registry/tools/DeletePremiumListCommandTest.java index 2bfae222d..2a0202fc2 100644 --- a/javatests/google/registry/tools/DeletePremiumListCommandTest.java +++ b/javatests/google/registry/tools/DeletePremiumListCommandTest.java @@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadPremiumListEntries; import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.model.registry.Registry; import google.registry.model.registry.label.PremiumList; @@ -48,9 +49,11 @@ public class DeletePremiumListCommandTest extends CommandTestCase runCommandForced("--name=foo")); + assertThat(thrown) + .hasMessageThat() + .contains("Cannot delete the premium list foo because it doesn't exist."); } @Test diff --git a/javatests/google/registry/tools/DeleteReservedListCommandTest.java b/javatests/google/registry/tools/DeleteReservedListCommandTest.java index e9a7d0535..a9193828c 100644 --- a/javatests/google/registry/tools/DeleteReservedListCommandTest.java +++ b/javatests/google/registry/tools/DeleteReservedListCommandTest.java @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth8.assertThat; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.model.registry.Registry; import google.registry.model.registry.label.ReservedList; @@ -47,9 +48,11 @@ public class DeleteReservedListCommandTest extends CommandTestCase runCommandForced("--name=doesntExistReservedList")); + assertThat(thrown).hasMessageThat().contains(expectedError); } @Test diff --git a/javatests/google/registry/tools/DeleteTldCommandTest.java b/javatests/google/registry/tools/DeleteTldCommandTest.java index 51063050f..6570d0ef4 100644 --- a/javatests/google/registry/tools/DeleteTldCommandTest.java +++ b/javatests/google/registry/tools/DeleteTldCommandTest.java @@ -18,6 +18,7 @@ import static google.registry.testing.DatastoreHelper.allowRegistrarAccess; import static google.registry.testing.DatastoreHelper.newRegistry; import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.base.Ascii; @@ -57,35 +58,30 @@ public class DeleteTldCommandTest extends CommandTestCase { runCommandForced("--tld=" + TLD_TEST); Registry.get(TLD_REAL); - thrown.expect(RegistryNotFoundException.class); - Registry.get(TLD_TEST); + assertThrows(RegistryNotFoundException.class, () -> Registry.get(TLD_TEST)); } @Test public void testFailure_whenTldDoesNotExist() throws Exception { - thrown.expect(RegistryNotFoundException.class); - runCommandForced("--tld=nonexistenttld"); + assertThrows(RegistryNotFoundException.class, () -> runCommandForced("--tld=nonexistenttld")); } @Test public void testFailure_whenTldIsReal() throws Exception { - thrown.expect(IllegalStateException.class); - runCommandForced("--tld=" + TLD_REAL); + assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_REAL)); } @Test public void testFailure_whenDomainsArePresent() throws Exception { persistDeletedDomain("domain." + TLD_TEST, DateTime.parse("2000-01-01TZ")); - thrown.expect(IllegalStateException.class); - runCommandForced("--tld=" + TLD_TEST); + assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST)); } @Test public void testFailure_whenRegistrarLinksToTld() throws Exception { allowRegistrarAccess("TheRegistrar", TLD_TEST); - thrown.expect(IllegalStateException.class); - runCommandForced("--tld=" + TLD_TEST); + assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST)); } } diff --git a/javatests/google/registry/tools/DomainApplicationInfoCommandTest.java b/javatests/google/registry/tools/DomainApplicationInfoCommandTest.java index d3ba78b7f..49da69c6b 100644 --- a/javatests/google/registry/tools/DomainApplicationInfoCommandTest.java +++ b/javatests/google/registry/tools/DomainApplicationInfoCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -38,41 +40,62 @@ public class DomainApplicationInfoCommandTest @Test public void testFailure_invalidPhase() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", - "--phase=landrise", "--id=123"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--domain_name=example.tld", + "--phase=landrise", + "--id=123")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--domain_name=example.tld", "--phase=sunrush", "--id=123"); + assertThrows( + ParameterException.class, + () -> runCommandForced("--domain_name=example.tld", "--phase=sunrush", "--id=123")); } @Test public void testFailure_missingPhase() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--id=123"); + assertThrows( + ParameterException.class, + () -> runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--id=123")); } @Test public void testFailure_missingApplicationId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", - "--phase=landrush"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", "--domain_name=example.tld", "--phase=landrush")); } @Test public void testFailure_mainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", - "--phase=landrush", "--id=123", "foo"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--domain_name=example.tld", + "--phase=landrush", + "--id=123", + "foo")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", - "--phase=landrush", "--id=123", "--foo=bar"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--domain_name=example.tld", + "--phase=landrush", + "--id=123", + "--foo=bar")); } } diff --git a/javatests/google/registry/tools/DomainCheckClaimsCommandTest.java b/javatests/google/registry/tools/DomainCheckClaimsCommandTest.java index bf609687a..eb9a293e8 100644 --- a/javatests/google/registry/tools/DomainCheckClaimsCommandTest.java +++ b/javatests/google/registry/tools/DomainCheckClaimsCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -59,19 +61,18 @@ public class DomainCheckClaimsCommandTest extends EppToolCommandTestCase runCommandForced("example.tld")); } @Test public void testFailure_NoMainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar"); + assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"); + assertThrows( + ParameterException.class, + () -> runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld")); } } diff --git a/javatests/google/registry/tools/DomainCheckCommandTest.java b/javatests/google/registry/tools/DomainCheckCommandTest.java index 471600153..aae879b11 100644 --- a/javatests/google/registry/tools/DomainCheckCommandTest.java +++ b/javatests/google/registry/tools/DomainCheckCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -59,19 +61,18 @@ public class DomainCheckCommandTest extends EppToolCommandTestCase runCommandForced("example.tld")); } @Test public void testFailure_NoMainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar"); + assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"); + assertThrows( + ParameterException.class, + () -> runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld")); } } diff --git a/javatests/google/registry/tools/DomainCheckFeeCommandTest.java b/javatests/google/registry/tools/DomainCheckFeeCommandTest.java index 28551b1c1..ef829b054 100644 --- a/javatests/google/registry/tools/DomainCheckFeeCommandTest.java +++ b/javatests/google/registry/tools/DomainCheckFeeCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -59,19 +61,18 @@ public class DomainCheckFeeCommandTest extends EppToolCommandTestCase runCommandForced("example.tld")); } @Test public void testFailure_NoMainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar"); + assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"); + assertThrows( + ParameterException.class, + () -> runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld")); } } diff --git a/javatests/google/registry/tools/EppToolCommandTest.java b/javatests/google/registry/tools/EppToolCommandTest.java index b8e417fb4..931c7f4eb 100644 --- a/javatests/google/registry/tools/EppToolCommandTest.java +++ b/javatests/google/registry/tools/EppToolCommandTest.java @@ -14,6 +14,9 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; + import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.tools.server.ToolsTestData; @@ -71,8 +74,10 @@ public class EppToolCommandTest extends EppToolCommandTestCase { @Test public void testFailure_nonexistentClientId() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("fakeclient"); - runCommandForced("--client=fakeclient", "fake-xml"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--client=fakeclient", "fake-xml")); + assertThat(thrown).hasMessageThat().contains("fakeclient"); } } diff --git a/javatests/google/registry/tools/ExecuteEppCommandTest.java b/javatests/google/registry/tools/ExecuteEppCommandTest.java index bcd91a6dd..7976e202c 100644 --- a/javatests/google/registry/tools/ExecuteEppCommandTest.java +++ b/javatests/google/registry/tools/ExecuteEppCommandTest.java @@ -14,6 +14,7 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; import static java.nio.charset.StandardCharsets.UTF_8; import com.beust.jcommander.ParameterException; @@ -77,19 +78,20 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase runCommand("--force", "foo.xml")); } @Test public void testFailure_forceAndDryRunIncompatible() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile)); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml"); + assertThrows( + ParameterException.class, + () -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml")); } } diff --git a/javatests/google/registry/tools/GenerateAuctionDataCommandTest.java b/javatests/google/registry/tools/GenerateAuctionDataCommandTest.java index 9dc63dfd6..1a9c91da1 100644 --- a/javatests/google/registry/tools/GenerateAuctionDataCommandTest.java +++ b/javatests/google/registry/tools/GenerateAuctionDataCommandTest.java @@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.newSunriseApplication; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static java.nio.charset.StandardCharsets.UTF_8; import static org.joda.time.DateTimeZone.UTC; @@ -320,19 +321,16 @@ public class GenerateAuctionDataCommandTest extends CommandTestCase runCommand()); } @Test public void testFailure_tooManyParameters() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("xn--q9jyb4c", "foobar"); + assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "foobar")); } @Test public void testFailure_nonexistentTld() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("foobarbaz"); + assertThrows(IllegalArgumentException.class, () -> runCommand("foobarbaz")); } } diff --git a/javatests/google/registry/tools/GenerateDnsReportCommandTest.java b/javatests/google/registry/tools/GenerateDnsReportCommandTest.java index e413a0b0d..c4b427f91 100644 --- a/javatests/google/registry/tools/GenerateDnsReportCommandTest.java +++ b/javatests/google/registry/tools/GenerateDnsReportCommandTest.java @@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.newHostResource; import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static java.nio.charset.StandardCharsets.UTF_8; import static org.joda.time.DateTimeZone.UTC; @@ -203,13 +204,11 @@ public class GenerateDnsReportCommandTest extends CommandTestCase runCommand("--tld=foobar")); } @Test public void testFailure_missingTldParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommand(""); + assertThrows(ParameterException.class, () -> runCommand("")); } } diff --git a/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java b/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java index 69e2adcbc..60c7a8183 100644 --- a/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java +++ b/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java @@ -15,7 +15,9 @@ package google.registry.tools; import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTld; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; import static org.mockito.Mockito.when; @@ -51,89 +53,135 @@ public class GenerateEscrowDepositCommandTest @Test public void testCommand_missingTld() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("The following option is required: -t, --tld"); - runCommand("--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommand("--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test")); + assertThat(thrown).hasMessageThat().contains("The following option is required: -t, --tld"); } @Test public void testCommand_emptyTld() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Null or empty TLD specified"); - runCommand("--tld=", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--tld=", + "--watermark=2017-01-01T00:00:00Z", + "--mode=thin", + "-r 42", + "-o test")); + assertThat(thrown).hasMessageThat().contains("Null or empty TLD specified"); } @Test public void testCommand_invalidTld() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("TLDs do not exist: invalid"); - runCommand( - "--tld=invalid", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--tld=invalid", + "--watermark=2017-01-01T00:00:00Z", + "--mode=thin", + "-r 42", + "-o test")); + assertThat(thrown).hasMessageThat().contains("TLDs do not exist: invalid"); } @Test public void testCommand_missingWatermark() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("The following option is required: -w, --watermark"); - runCommand("--tld=tld", "--mode=full", "-r 42", "-o test"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> runCommand("--tld=tld", "--mode=full", "-r 42", "-o test")); + assertThat(thrown) + .hasMessageThat() + .contains("The following option is required: -w, --watermark"); } @Test public void testCommand_emptyWatermark() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"\""); - runCommand("--tld=tld", "--watermark=", "--mode=full", "-r 42", "-o test"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommand("--tld=tld", "--watermark=", "--mode=full", "-r 42", "-o test")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"\""); } @Test public void testCommand_missingOutdir() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("The following option is required: -o, --outdir"); - runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommand( + "--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42")); + assertThat(thrown).hasMessageThat().contains("The following option is required: -o, --outdir"); } @Test public void testCommand_emptyOutdir() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Output subdirectory must not be empty"); - runCommand( - "--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "--outdir=", "-r 42"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommand( + "--tld=tld", + "--watermark=2017-01-01T00:00:00Z", + "--mode=thin", + "--outdir=", + "-r 42")); + assertThat(thrown).hasMessageThat().contains("Output subdirectory must not be empty"); } @Test public void testCommand_invalidWatermark() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Each watermark date must be the start of a day"); - runCommand( - "--tld=tld", - "--watermark=2017-01-01T10:00:00Z,2017-01-02T00:00:00Z", - "--mode=thin", - "-r 42", - "-o test"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommand( + "--tld=tld", + "--watermark=2017-01-01T10:00:00Z,2017-01-02T00:00:00Z", + "--mode=thin", + "-r 42", + "-o test")); + assertThat(thrown).hasMessageThat().contains("Each watermark date must be the start of a day"); } @Test public void testCommand_invalidMode() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Invalid value for -m parameter. Allowed values:[FULL, THIN]"); - runCommand( - "--tld=tld", - "--watermark=2017-01-01T00:00:00Z", - "--mode=thing", - "-r 42", - "-o test"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommand( + "--tld=tld", + "--watermark=2017-01-01T00:00:00Z", + "--mode=thing", + "-r 42", + "-o test")); + assertThat(thrown) + .hasMessageThat() + .contains("Invalid value for -m parameter. Allowed values:[FULL, THIN]"); } @Test public void testCommand_invalidRevision() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Revision must be greater than or equal to zero"); - runCommand( - "--tld=tld", - "--watermark=2017-01-01T00:00:00Z", - "--mode=thin", - "-r -1", - "-o test"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommand( + "--tld=tld", + "--watermark=2017-01-01T00:00:00Z", + "--mode=thin", + "-r -1", + "-o test")); + assertThat(thrown).hasMessageThat().contains("Revision must be greater than or equal to zero"); } @Test diff --git a/javatests/google/registry/tools/GetApplicationCommandTest.java b/javatests/google/registry/tools/GetApplicationCommandTest.java index 02df23012..13841b2e6 100644 --- a/javatests/google/registry/tools/GetApplicationCommandTest.java +++ b/javatests/google/registry/tools/GetApplicationCommandTest.java @@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistDeletedDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -87,8 +88,7 @@ public class GetApplicationCommandTest extends CommandTestCase runCommand()); } @Test diff --git a/javatests/google/registry/tools/GetApplicationIdsCommandTest.java b/javatests/google/registry/tools/GetApplicationIdsCommandTest.java index 4adb140bb..64f38720e 100644 --- a/javatests/google/registry/tools/GetApplicationIdsCommandTest.java +++ b/javatests/google/registry/tools/GetApplicationIdsCommandTest.java @@ -14,10 +14,13 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -60,9 +63,9 @@ public class GetApplicationIdsCommandTest extends CommandTestCase runCommand("example.foo")); + assertThat(thrown).hasMessageThat().contains("Domain name is not under a recognized TLD"); } @Test @@ -75,8 +78,7 @@ public class GetApplicationIdsCommandTest extends CommandTestCase runCommand()); } private void persistDomainApplication(String domainName, String repoId) { diff --git a/javatests/google/registry/tools/GetContactCommandTest.java b/javatests/google/registry/tools/GetContactCommandTest.java index 7405d8010..b7b22f4e2 100644 --- a/javatests/google/registry/tools/GetContactCommandTest.java +++ b/javatests/google/registry/tools/GetContactCommandTest.java @@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newContactResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -79,8 +80,7 @@ public class GetContactCommandTest extends CommandTestCase { @Test public void testFailure_noContact() throws Exception { - thrown.expect(ParameterException.class); - runCommand(); + assertThrows(ParameterException.class, () -> runCommand()); } @Test diff --git a/javatests/google/registry/tools/GetDomainCommandTest.java b/javatests/google/registry/tools/GetDomainCommandTest.java index 4c5db340d..3e9503dab 100644 --- a/javatests/google/registry/tools/GetDomainCommandTest.java +++ b/javatests/google/registry/tools/GetDomainCommandTest.java @@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -95,8 +96,7 @@ public class GetDomainCommandTest extends CommandTestCase { @Test public void testFailure_noDomainName() throws Exception { - thrown.expect(ParameterException.class); - runCommand(); + assertThrows(ParameterException.class, () -> runCommand()); } @Test diff --git a/javatests/google/registry/tools/GetHostCommandTest.java b/javatests/google/registry/tools/GetHostCommandTest.java index e4975a5f7..50e7b50e6 100644 --- a/javatests/google/registry/tools/GetHostCommandTest.java +++ b/javatests/google/registry/tools/GetHostCommandTest.java @@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newHostResource; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -106,7 +107,6 @@ public class GetHostCommandTest extends CommandTestCase { @Test public void testFailure_noHostName() throws Exception { - thrown.expect(ParameterException.class); - runCommand(); + assertThrows(ParameterException.class, () -> runCommand()); } } diff --git a/javatests/google/registry/tools/GetLrpTokenCommandTest.java b/javatests/google/registry/tools/GetLrpTokenCommandTest.java index 9037cf5cc..a1174bcef 100644 --- a/javatests/google/registry/tools/GetLrpTokenCommandTest.java +++ b/javatests/google/registry/tools/GetLrpTokenCommandTest.java @@ -14,9 +14,11 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import com.googlecode.objectify.Key; import google.registry.model.domain.DomainApplication; @@ -79,8 +81,10 @@ public class GetLrpTokenCommandTest extends CommandTestCase @Test public void testFailure_noArgs() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Exactly one of either token or assignee must be specified."); - runCommand(); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommand()); + assertThat(thrown) + .hasMessageThat() + .contains("Exactly one of either token or assignee must be specified."); } } diff --git a/javatests/google/registry/tools/GetRegistrarCommandTest.java b/javatests/google/registry/tools/GetRegistrarCommandTest.java index 67eeecdb3..5213061d6 100644 --- a/javatests/google/registry/tools/GetRegistrarCommandTest.java +++ b/javatests/google/registry/tools/GetRegistrarCommandTest.java @@ -14,6 +14,10 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -34,21 +38,20 @@ public class GetRegistrarCommandTest extends CommandTestCase runCommand("ClientZ")); + assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist"); } @Test public void testFailure_noRegistrarName() throws Exception { - thrown.expect(ParameterException.class); - runCommand(); + assertThrows(ParameterException.class, () -> runCommand()); } @Test public void testFailure_oneRegistrarDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar with id ClientZ does not exist"); - runCommand("NewRegistrar", "ClientZ"); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommand("NewRegistrar", "ClientZ")); + assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist"); } } diff --git a/javatests/google/registry/tools/GetResourceByKeyCommandTest.java b/javatests/google/registry/tools/GetResourceByKeyCommandTest.java index effd2e557..33c80dae7 100644 --- a/javatests/google/registry/tools/GetResourceByKeyCommandTest.java +++ b/javatests/google/registry/tools/GetResourceByKeyCommandTest.java @@ -14,6 +14,7 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveDomain; @@ -21,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistDeletedHost; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -68,10 +71,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(DomainBase(\"4-TLD\"))"); - runCommand( - "agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw", "agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw"); + NullPointerException thrown = + expectThrows( + NullPointerException.class, + () -> + runCommand( + "agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw", + "agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw")); + assertThat(thrown) + .hasMessageThat() + .contains("Could not load resource for key: Key(DomainBase(\"4-TLD\"))"); } @Test @@ -111,11 +120,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(ContactResource(\"3-ROID\"))"); - runCommand( - "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw", - "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw"); + NullPointerException thrown = + expectThrows( + NullPointerException.class, + () -> + runCommand( + "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw", + "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw")); + assertThat(thrown) + .hasMessageThat() + .contains("Could not load resource for key: Key(ContactResource(\"3-ROID\"))"); } @Test @@ -155,11 +169,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(HostResource(\"3-ROID\"))"); - runCommand( - "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw", - "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw"); + NullPointerException thrown = + expectThrows( + NullPointerException.class, + () -> + runCommand( + "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw", + "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw")); + assertThat(thrown) + .hasMessageThat() + .contains("Could not load resource for key: Key(HostResource(\"3-ROID\"))"); } @Test @@ -186,21 +205,25 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(DomainBase(\"2-TLD\"))"); - runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw"); + NullPointerException thrown = + expectThrows( + NullPointerException.class, + () -> runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw")); + assertThat(thrown) + .hasMessageThat() + .contains("Could not load resource for key: Key(DomainBase(\"2-TLD\"))"); } @Test public void testFailure_nonsenseKey() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Could not parse Reference"); - runCommand("agR0ZXN0chULEgpEb21haW5CYXN"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, () -> runCommand("agR0ZXN0chULEgpEb21haW5CYXN")); + assertThat(thrown).hasMessageThat().contains("Could not parse Reference"); } @Test public void testFailure_noParameters() throws Exception { - thrown.expect(ParameterException.class); - runCommand(); + assertThrows(ParameterException.class, () -> runCommand()); } } diff --git a/javatests/google/registry/tools/GetTldCommandTest.java b/javatests/google/registry/tools/GetTldCommandTest.java index 52eb7a83b..2297db4b9 100644 --- a/javatests/google/registry/tools/GetTldCommandTest.java +++ b/javatests/google/registry/tools/GetTldCommandTest.java @@ -16,6 +16,7 @@ package google.registry.tools; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTlds; +import static google.registry.testing.JUnitBackports.assertThrows; import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -38,20 +39,17 @@ public class GetTldCommandTest extends CommandTestCase { @Test public void testFailure_tldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("xn--q9jyb4c"); + assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c")); } @Test public void testFailure_noTldName() throws Exception { - thrown.expect(ParameterException.class); - runCommand(); + assertThrows(ParameterException.class, () -> runCommand()); } @Test public void testFailure_oneTldDoesNotExist() throws Exception { createTld("xn--q9jyb4c"); - thrown.expect(IllegalArgumentException.class); - runCommand("xn--q9jyb4c", "example"); + assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "example")); } } diff --git a/javatests/google/registry/tools/ListCursorsCommandTest.java b/javatests/google/registry/tools/ListCursorsCommandTest.java index 29d1d09ac..be5320e22 100644 --- a/javatests/google/registry/tools/ListCursorsCommandTest.java +++ b/javatests/google/registry/tools/ListCursorsCommandTest.java @@ -17,6 +17,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import com.beust.jcommander.ParameterException; import google.registry.model.common.Cursor; @@ -49,9 +50,9 @@ public class ListCursorsCommandTest extends CommandTestCase @Test public void testListCursors_badCursor_throwsIae() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Invalid value for --type parameter."); - runCommand("--type=love"); + ParameterException thrown = + expectThrows(ParameterException.class, () -> runCommand("--type=love")); + assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter."); } @Test diff --git a/javatests/google/registry/tools/ListDomainsCommandTest.java b/javatests/google/registry/tools/ListDomainsCommandTest.java index d06fb1dc1..a63ddcd7f 100644 --- a/javatests/google/registry/tools/ListDomainsCommandTest.java +++ b/javatests/google/registry/tools/ListDomainsCommandTest.java @@ -14,6 +14,9 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; + import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import google.registry.tools.server.ListDomainsAction; @@ -43,8 +46,10 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase runCommand(tldsParam)); + assertThat(thrown) + .hasMessageThat() + .contains("Total length of TLDs is too long for URL parameter"); } } diff --git a/javatests/google/registry/tools/LoadTestCommandTest.java b/javatests/google/registry/tools/LoadTestCommandTest.java index 77c081f6c..35da1058b 100644 --- a/javatests/google/registry/tools/LoadTestCommandTest.java +++ b/javatests/google/registry/tools/LoadTestCommandTest.java @@ -92,13 +92,6 @@ public class LoadTestCommandTest extends CommandTestCase { eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0])); } - @Test - public void test_prompt() throws Exception { - thrown.expect(IllegalStateException.class); - runCommand(); - verifyZeroInteractions(connection); - assertInStderr("Unable to access stdin (are you running with bazel run?)"); - } @Test public void test_badTLD() throws Exception { diff --git a/javatests/google/registry/tools/MutatingCommandTest.java b/javatests/google/registry/tools/MutatingCommandTest.java index a56d55e7c..4a69c312b 100644 --- a/javatests/google/registry/tools/MutatingCommandTest.java +++ b/javatests/google/registry/tools/MutatingCommandTest.java @@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistNewRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; import google.registry.model.host.HostResource; @@ -32,7 +34,6 @@ import org.joda.time.DateTime; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -44,10 +45,6 @@ public class MutatingCommandTest { public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastore() .build(); - - @Rule - public final ExpectedException thrown = ExpectedException.none(); - Registrar registrar1; Registrar registrar2; Registrar newRegistrar1; @@ -298,8 +295,7 @@ public class MutatingCommandTest { stageEntityChange(null, null); } }; - thrown.expect(IllegalArgumentException.class); - command.init(); + assertThrows(IllegalArgumentException.class, () -> command.init()); } @Test @@ -313,9 +309,11 @@ public class MutatingCommandTest { .build()); } }; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Cannot apply multiple changes for the same entity"); - command.init(); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> command.init()); + assertThat(thrown) + .hasMessageThat() + .contains("Cannot apply multiple changes for the same entity"); } @Test @@ -326,9 +324,11 @@ public class MutatingCommandTest { stageEntityChange(host1, host2); } }; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Both entity versions in an update must have the same Key."); - command.init(); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> command.init()); + assertThat(thrown) + .hasMessageThat() + .contains("Both entity versions in an update must have the same Key."); } @Test @@ -339,9 +339,11 @@ public class MutatingCommandTest { stageEntityChange(registrar1, registrar2); } }; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Both entity versions in an update must have the same Key."); - command.init(); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> command.init()); + assertThat(thrown) + .hasMessageThat() + .contains("Both entity versions in an update must have the same Key."); } @Test @@ -352,9 +354,11 @@ public class MutatingCommandTest { stageEntityChange(host1, registrar1); } }; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Both entity versions in an update must have the same Key."); - command.init(); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> command.init()); + assertThat(thrown) + .hasMessageThat() + .contains("Both entity versions in an update must have the same Key."); } @Test @@ -367,9 +371,9 @@ public class MutatingCommandTest { }; command.init(); persistResource(newHost1); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Entity changed since init() was called."); - command.execute(); + IllegalStateException thrown = + expectThrows(IllegalStateException.class, () -> command.execute()); + assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); } @Test @@ -382,9 +386,9 @@ public class MutatingCommandTest { }; command.init(); persistResource(newHost1); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Entity changed since init() was called."); - command.execute(); + IllegalStateException thrown = + expectThrows(IllegalStateException.class, () -> command.execute()); + assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); } @Test @@ -397,9 +401,9 @@ public class MutatingCommandTest { }; command.init(); persistResource(newHost1); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Entity changed since init() was called."); - command.execute(); + IllegalStateException thrown = + expectThrows(IllegalStateException.class, () -> command.execute()); + assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); } @Test @@ -412,8 +416,8 @@ public class MutatingCommandTest { }; command.init(); deleteResource(host1); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Entity changed since init() was called."); - command.execute(); + IllegalStateException thrown = + expectThrows(IllegalStateException.class, () -> command.execute()); + assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); } } diff --git a/javatests/google/registry/tools/RegistryToolEnvironmentTest.java b/javatests/google/registry/tools/RegistryToolEnvironmentTest.java index 35494f5e3..4ff23f349 100644 --- a/javatests/google/registry/tools/RegistryToolEnvironmentTest.java +++ b/javatests/google/registry/tools/RegistryToolEnvironmentTest.java @@ -15,10 +15,9 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.assertThrows; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -26,13 +25,9 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class RegistryToolEnvironmentTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testGet_withoutSetup_throws() throws Exception { - thrown.expect(IllegalStateException.class); - RegistryToolEnvironment.get(); + assertThrows(IllegalStateException.class, () -> RegistryToolEnvironment.get()); } @Test @@ -72,16 +67,18 @@ public class RegistryToolEnvironmentTest { @Test public void testFromArgs_envFlagAfterCommandName_getsIgnored() throws Exception { - thrown.expect(IllegalArgumentException.class); - RegistryToolEnvironment.parseFromArgs(new String[] { - "registrar_activity_report", - "-e", "1406851199"}); + assertThrows( + IllegalArgumentException.class, + () -> + RegistryToolEnvironment.parseFromArgs( + new String[] {"registrar_activity_report", "-e", "1406851199"})); } @Test public void testFromArgs_missingEnvironmentFlag_throwsIae() throws Exception { - thrown.expect(IllegalArgumentException.class); - RegistryToolEnvironment.parseFromArgs(new String[] {}); + assertThrows( + IllegalArgumentException.class, + () -> RegistryToolEnvironment.parseFromArgs(new String[] {})); } @Test @@ -106,7 +103,8 @@ public class RegistryToolEnvironmentTest { @Test public void testFromArgs_badName_throwsIae() throws Exception { - thrown.expect(IllegalArgumentException.class); - RegistryToolEnvironment.parseFromArgs(new String[] { "-e", "alphaville" }); + assertThrows( + IllegalArgumentException.class, + () -> RegistryToolEnvironment.parseFromArgs(new String[] {"-e", "alphaville"})); } } diff --git a/javatests/google/registry/tools/SetupOteCommandTest.java b/javatests/google/registry/tools/SetupOteCommandTest.java index 7c2de5617..83f5630ae 100644 --- a/javatests/google/registry/tools/SetupOteCommandTest.java +++ b/javatests/google/registry/tools/SetupOteCommandTest.java @@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -203,132 +204,168 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_missingIpWhitelist() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("option is required: -w, --ip_whitelist"); - runCommandForced( - "--registrar=blobio", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--registrar=blobio", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("option is required: -w, --ip_whitelist"); } @Test public void testFailure_missingRegistrar() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("option is required: -r, --registrar"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("option is required: -r, --registrar"); } @Test public void testFailure_missingCertificateFile() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("option is required: -c, --certfile"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--dns_writers=VoidDnsWriter", - "--registrar=blobio"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", "--dns_writers=VoidDnsWriter", "--registrar=blobio")); + assertThat(thrown).hasMessageThat().contains("option is required: -c, --certfile"); } @Test public void testFailure_missingDnsWriter() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("option is required: --dns_writers"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--certfile=" + getCertFilename(), - "--registrar=blobio"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--certfile=" + getCertFilename(), + "--registrar=blobio")); + assertThat(thrown).hasMessageThat().contains("option is required: --dns_writers"); } @Test public void testFailure_invalidCert() throws Exception { - thrown.expect(CertificateParsingException.class); - thrown.expectMessage("No X509Certificate found"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blobio", - "--dns_writers=VoidDnsWriter", - "--certfile=/dev/null"); + CertificateParsingException thrown = + expectThrows( + CertificateParsingException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blobio", + "--dns_writers=VoidDnsWriter", + "--certfile=/dev/null")); + assertThat(thrown).hasMessageThat().contains("No X509Certificate found"); } @Test public void testFailure_invalidRegistrar() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar name is invalid"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=3blobio", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=3blobio", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("Registrar name is invalid"); } @Test public void testFailure_invalidDnsWriter() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blobio", - "--dns_writers=InvalidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blobio", + "--dns_writers=InvalidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown) + .hasMessageThat() + .contains("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); } @Test public void testFailure_registrarTooShort() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar name is invalid"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=bl", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=bl", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("Registrar name is invalid"); } @Test public void testFailure_registrarTooLong() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar name is invalid"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blobiotoooolong", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blobiotoooolong", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("Registrar name is invalid"); } @Test public void testFailure_registrarInvalidCharacter() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar name is invalid"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blo#bio", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blo#bio", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("Registrar name is invalid"); } @Test public void testFailure_invalidPremiumList() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The premium list 'foo' doesn't exist"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blobio", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename(), - "--premium_list=foo"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blobio", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename(), + "--premium_list=foo")); + assertThat(thrown).hasMessageThat().contains("The premium list 'foo' doesn't exist"); } @Test public void testFailure_tldExists() throws Exception { createTld("blobio-sunrise"); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("TLD 'blobio-sunrise' already exists"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blobio", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalStateException thrown = + expectThrows( + IllegalStateException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blobio", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("TLD 'blobio-sunrise' already exists"); } @Test @@ -338,12 +375,15 @@ public class SetupOteCommandTest extends CommandTestCase { .setRegistrarName("blobio-1") .build(); persistResource(registrar); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Registrar blobio-1 already exists"); - runCommandForced( - "--ip_whitelist=1.1.1.1", - "--registrar=blobio", - "--dns_writers=VoidDnsWriter", - "--certfile=" + getCertFilename()); + IllegalStateException thrown = + expectThrows( + IllegalStateException.class, + () -> + runCommandForced( + "--ip_whitelist=1.1.1.1", + "--registrar=blobio", + "--dns_writers=VoidDnsWriter", + "--certfile=" + getCertFilename())); + assertThat(thrown).hasMessageThat().contains("Registrar blobio-1 already exists"); } } diff --git a/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java b/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java index c7e889575..c3c649872 100644 --- a/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java +++ b/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java @@ -14,11 +14,13 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import com.beust.jcommander.ParameterException; import com.google.common.collect.ImmutableSet; @@ -150,46 +152,58 @@ public class UniformRapidSuspensionCommandTest @Test public void testFailure_locksToPreserveWithoutUndo() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("--undo"); - runCommandForced("--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited")); + assertThat(thrown).hasMessageThat().contains("--undo"); } @Test public void testFailure_domainNameRequired() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(ParameterException.class); - thrown.expectMessage("--domain_name"); - runCommandForced("--hosts=urs1.example.com,urs2.example.com"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> runCommandForced("--hosts=urs1.example.com,urs2.example.com")); + assertThat(thrown).hasMessageThat().contains("--domain_name"); } @Test public void testFailure_extraFieldInDsData() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Incorrect fields on --dsdata JSON"); - runCommandForced( - "--domain_name=evil.tld", - "--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1,\"digest\":\"abc\",\"foo\":1}"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--domain_name=evil.tld", + "--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1,\"digest\":\"abc\",\"foo\":1}")); + assertThat(thrown).hasMessageThat().contains("Incorrect fields on --dsdata JSON"); } @Test public void testFailure_missingFieldInDsData() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Incorrect fields on --dsdata JSON"); - runCommandForced( - "--domain_name=evil.tld", - "--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--domain_name=evil.tld", + "--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}")); + assertThat(thrown).hasMessageThat().contains("Incorrect fields on --dsdata JSON"); } @Test public void testFailure_malformedDsData() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid --dsdata JSON"); - runCommandForced( - "--domain_name=evil.tld", - "--dsdata=[1,2,3]"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--domain_name=evil.tld", "--dsdata=[1,2,3]")); + assertThat(thrown).hasMessageThat().contains("Invalid --dsdata JSON"); } } diff --git a/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java b/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java index 5df4674ac..6b3d460e5 100644 --- a/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java +++ b/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java @@ -27,6 +27,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; @@ -270,16 +271,25 @@ public class UpdateApplicationStatusCommandTest @Test public void testFailure_applicationDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced("--ids=555-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--ids=555-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED")); } @Test public void testFailure_historyClientIdDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("fakeclient"); - runCommandForced( - "--history_client_id=fakeclient", "--ids=2-Q9JYB4C", "--msg=Ignored", "--status=REJECTED"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--history_client_id=fakeclient", + "--ids=2-Q9JYB4C", + "--msg=Ignored", + "--status=REJECTED")); + assertThat(thrown).hasMessageThat().contains("fakeclient"); } } diff --git a/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java b/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java index 7516cc4ee..0e44c1765 100644 --- a/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java +++ b/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java @@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; +import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -131,12 +132,14 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase + runCommand( + "--id=1-Q9JYB4C", + "--tcn_id=foobarbaz", + "--expiration_time=2010-08-16T09:00:00.0Z", + "--accepted_time=2009-08-16T09:00:00.0Z")); } @Test @@ -160,12 +163,13 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase + runCommand( + "--id=1-Q9JYB4C", + "--tcn_id=370d0b7c9223372036854775807", + "--expiration_time=2010-08-16T09:00:00.0Z", + "--accepted_time=2009-08-16T09:00:00.0Z")); } } diff --git a/javatests/google/registry/tools/UpdateCursorsCommandTest.java b/javatests/google/registry/tools/UpdateCursorsCommandTest.java index 00bbf16da..7f2ea047d 100644 --- a/javatests/google/registry/tools/UpdateCursorsCommandTest.java +++ b/javatests/google/registry/tools/UpdateCursorsCommandTest.java @@ -18,6 +18,8 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import com.beust.jcommander.ParameterException; import google.registry.model.common.Cursor; @@ -110,14 +112,17 @@ public class UpdateCursorsCommandTest extends CommandTestCase runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar")); } @Test public void testFailure_badCursorType() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Invalid value for --type parameter"); - runCommandForced("--type=rbda", "--timestamp=1984-12-18T00:00:00Z", "foo"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> runCommandForced("--type=rbda", "--timestamp=1984-12-18T00:00:00Z", "foo")); + assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter"); } } diff --git a/javatests/google/registry/tools/UpdateDomainCommandTest.java b/javatests/google/registry/tools/UpdateDomainCommandTest.java index 43b1856f8..720f4d15a 100644 --- a/javatests/google/registry/tools/UpdateDomainCommandTest.java +++ b/javatests/google/registry/tools/UpdateDomainCommandTest.java @@ -192,130 +192,197 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--password=2fooBAR", + "example.tld", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("Duplicate arguments found"); } @Test public void testFailure_missingDomain() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Main parameters are required"); - runCommandForced("--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR")); + assertThat(thrown).hasMessageThat().contains("Main parameters are required"); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--client"); - runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld")); + assertThat(thrown).hasMessageThat().contains("--client"); } @Test public void testFailure_addTooManyNameServers() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("You can add at most 13 nameservers"); - runCommandForced( - "--client=NewRegistrar", - "--add_nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google," - + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google," - + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google," - + "ns13.zdns.google,ns14.zdns.google", - "--add_admins=crr-admin2", - "--add_techs=crr-tech2", - "--add_statuses=serverDeleteProhibited", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--add_nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google," + + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google," + + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google," + + "ns13.zdns.google,ns14.zdns.google", + "--add_admins=crr-admin2", + "--add_techs=crr-tech2", + "--add_statuses=serverDeleteProhibited", + "example.tld")); + assertThat(thrown).hasMessageThat().contains("You can add at most 13 nameservers"); } @Test public void testFailure_providedNameserversAndAddNameservers() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("If you provide the nameservers flag, " - + "you cannot use the add_nameservers and remove_nameservers flags."); - runCommandForced( - "--client=NewRegistrar", - "--add_nameservers=ns1.zdns.google", - "--nameservers=ns2.zdns.google,ns3.zdns.google", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--add_nameservers=ns1.zdns.google", + "--nameservers=ns2.zdns.google,ns3.zdns.google", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .contains( + "If you provide the nameservers flag, " + + "you cannot use the add_nameservers and remove_nameservers flags."); } @Test public void testFailure_providedNameserversAndRemoveNameservers() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("If you provide the nameservers flag, " - + "you cannot use the add_nameservers and remove_nameservers flags."); - runCommandForced( - "--client=NewRegistrar", - "--remove_nameservers=ns1.zdns.google", - "--nameservers=ns2.zdns.google,ns3.zdns.google", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--remove_nameservers=ns1.zdns.google", + "--nameservers=ns2.zdns.google,ns3.zdns.google", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .contains( + "If you provide the nameservers flag, " + + "you cannot use the add_nameservers and remove_nameservers flags."); } @Test public void testFailure_providedAdminsAndAddAdmins() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); - runCommandForced( - "--client=NewRegistrar", "--add_admins=crr-admin2", "--admins=crr-admin2", "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--add_admins=crr-admin2", + "--admins=crr-admin2", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .isEqualTo( + "If you provide the admins flag, " + + "you cannot use the add_admins and remove_admins flags."); } @Test public void testFailure_providedAdminsAndRemoveAdmins() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); - runCommandForced( - "--client=NewRegistrar", - "--remove_admins=crr-admin2", - "--admins=crr-admin2", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--remove_admins=crr-admin2", + "--admins=crr-admin2", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .isEqualTo( + "If you provide the admins flag, " + + "you cannot use the add_admins and remove_admins flags."); } @Test public void testFailure_providedTechsAndAddTechs() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); - runCommandForced( - "--client=NewRegistrar", "--add_techs=crr-tech2", "--techs=crr-tech2", "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--add_techs=crr-tech2", + "--techs=crr-tech2", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .contains( + "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); } @Test public void testFailure_providedTechsAndRemoveTechs() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); - runCommandForced( - "--client=NewRegistrar", "--remove_techs=crr-tech2", "--techs=crr-tech2", "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--remove_techs=crr-tech2", + "--techs=crr-tech2", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .contains( + "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); } @Test public void testFailure_providedStatusesAndAddStatuses() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("If you provide the statuses flag, " - + "you cannot use the add_statuses and remove_statuses flags."); - runCommandForced( - "--client=NewRegistrar", - "--add_statuses=serverHold", - "--statuses=crr-serverHold", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--add_statuses=serverHold", + "--statuses=crr-serverHold", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .contains( + "If you provide the statuses flag, " + + "you cannot use the add_statuses and remove_statuses flags."); } @Test public void testFailure_providedStatusesAndRemoveStatuses() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("If you provide the statuses flag, " - + "you cannot use the add_statuses and remove_statuses flags."); - runCommandForced( - "--client=NewRegistrar", - "--remove_statuses=serverHold", - "--statuses=crr-serverHold", - "example.tld"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--remove_statuses=serverHold", + "--statuses=crr-serverHold", + "example.tld")); + assertThat(thrown) + .hasMessageThat() + .contains( + "If you provide the statuses flag, " + + "you cannot use the add_statuses and remove_statuses flags."); } } diff --git a/javatests/google/registry/tools/UpdateRegistrarCommandTest.java b/javatests/google/registry/tools/UpdateRegistrarCommandTest.java index e6697d773..1e81255c7 100644 --- a/javatests/google/registry/tools/UpdateRegistrarCommandTest.java +++ b/javatests/google/registry/tools/UpdateRegistrarCommandTest.java @@ -21,6 +21,8 @@ import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH; import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.ParameterException; @@ -70,9 +72,11 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--registrar_type=REAL", "--iana_id=1000", "--force", "NewRegistrar")); + assertThat(thrown).hasMessageThat().contains("--passcode is required for REAL registrars."); } @Test @@ -217,14 +221,17 @@ public class UpdateRegistrarCommandTest extends CommandTestCase + runCommand( + "--billing_account_map=JPY=789xyz", + "--allowed_tlds=foo", + "--force", + "--registrar_type=REAL", + "NewRegistrar")); + assertThat(thrown).hasMessageThat().contains("USD"); } @Test @@ -276,11 +283,15 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--billing_method=braintree", "--force", "NewRegistrar")); + assertThat(thrown) + .hasMessageThat() + .isEqualTo( + "Refusing to change billing method on Registrar 'NewRegistrar' from EXTERNAL to " + + "BRAINTREE because current balance is non-zero: {USD=USD 10.00}"); } @Test @@ -437,174 +448,267 @@ public class UpdateRegistrarCommandTest extends CommandTestCase runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar")); } @Test public void testFailure_invalidRegistrarState() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar"); + assertThrows( + ParameterException.class, + () -> runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar")); } @Test public void testFailure_negativeIanaId() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--iana_id=-1", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--iana_id=-1", "--force", "NewRegistrar")); } @Test public void testFailure_nonIntegerIanaId() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--iana_id=ABC123", "--force", "NewRegistrar"); + assertThrows( + ParameterException.class, () -> runCommand("--iana_id=ABC123", "--force", "NewRegistrar")); } @Test public void testFailure_negativeBillingId() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--billing_id=-1", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--billing_id=-1", "--force", "NewRegistrar")); } @Test public void testFailure_nonIntegerBillingId() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--billing_id=ABC123", "--force", "NewRegistrar"); + assertThrows( + ParameterException.class, + () -> runCommand("--billing_id=ABC123", "--force", "NewRegistrar")); } @Test public void testFailure_passcodeTooShort() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--passcode=0123", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--passcode=0123", "--force", "NewRegistrar")); } @Test public void testFailure_passcodeTooLong() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--passcode=012345", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--passcode=012345", "--force", "NewRegistrar")); } @Test public void testFailure_invalidPasscode() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--passcode=code1", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--passcode=code1", "--force", "NewRegistrar")); } @Test public void testFailure_allowedTldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar")); } @Test public void testFailure_addAllowedTldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar")); } @Test public void testFailure_allowedTldsAndAddAllowedTlds() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--allowed_tlds=bar", "--add_allowed_tlds=foo", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand("--allowed_tlds=bar", "--add_allowed_tlds=foo", "--force", "NewRegistrar")); } @Test public void testFailure_invalidIpWhitelist() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--ip_whitelist=foobarbaz", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--ip_whitelist=foobarbaz", "--force", "NewRegistrar")); } @Test public void testFailure_invalidCertFileContents() throws Exception { - thrown.expect(Exception.class); - runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar"); + assertThrows( + Exception.class, + () -> runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar")); } @Test public void testFailure_certHashAndCertFile() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--cert_file=" + getCertFilename(), "--cert_hash=ABCDEF", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--cert_file=" + getCertFilename(), + "--cert_hash=ABCDEF", + "--force", + "NewRegistrar")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--force"); + assertThrows(ParameterException.class, () -> runCommand("--force")); } @Test public void testFailure_missingStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--city Brooklyn", "--state NY", "--zip 11223", "--cc US", "--force", - "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc US", + "--force", + "NewRegistrar")); } @Test public void testFailure_missingCity() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", - "--state NY", "--zip 11223", "--cc US", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--state NY", + "--zip 11223", + "--cc US", + "--force", + "NewRegistrar")); } @Test public void testFailure_missingState() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", - "--city Brooklyn", "--zip 11223", "--cc US", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--zip 11223", + "--cc US", + "--force", + "NewRegistrar")); } @Test public void testFailure_missingZip() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", - "--city Brooklyn", "--state NY", "--cc US", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--cc US", + "--force", + "NewRegistrar")); } @Test public void testFailure_missingCc() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", - "--city Brooklyn", "--state NY", "--zip 11223", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--force", + "NewRegistrar")); } @Test public void testFailure_missingInvalidCc() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", - "--city Brooklyn", "--state NY", "--zip 11223", "--cc USA", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street=\"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc USA", + "--force", + "NewRegistrar")); } @Test public void testFailure_tooManyStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street \"Attn:Hey You Guys\"", "--street \"1234 Main St\"", - "--street \"4th Floor\"", "--street \"Suite 1\"", "--city Brooklyn", "--state NY", - "--zip 11223", "--cc USA", "--force", "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street \"Attn:Hey You Guys\"", + "--street \"1234 Main St\"", + "--street \"4th Floor\"", + "--street \"Suite 1\"", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc USA", + "--force", + "NewRegistrar")); } @Test public void testFailure_tooFewStreetLines() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--street", "--city Brooklyn", "--state NY", "--zip 11223", "--cc USA", "--force", - "NewRegistrar"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--street", + "--city Brooklyn", + "--state NY", + "--zip 11223", + "--cc USA", + "--force", + "NewRegistrar")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar"); + assertThrows( + ParameterException.class, + () -> runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar")); } @Test public void testFailure_doesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar ClientZ not found"); - runCommand("--force", "ClientZ"); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommand("--force", "ClientZ")); + assertThat(thrown).hasMessageThat().contains("Registrar ClientZ not found"); } @Test public void testFailure_registrarNameSimilarToExisting() throws Exception { - thrown.expect(IllegalArgumentException.class); - // Normalizes identically to "The Registrar" which is created by AppEngineRule. - runCommand("--name tHeRe GiStRaR", "--force", "NewRegistrar"); + // Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by + // AppEngineRule. + assertThrows( + IllegalArgumentException.class, + () -> runCommand("--name tHeRe GiStRaR", "--force", "NewRegistrar")); } } diff --git a/javatests/google/registry/tools/UpdateReservedListCommandTest.java b/javatests/google/registry/tools/UpdateReservedListCommandTest.java index e6da06c2e..961895b29 100644 --- a/javatests/google/registry/tools/UpdateReservedListCommandTest.java +++ b/javatests/google/registry/tools/UpdateReservedListCommandTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableList; @@ -92,8 +93,11 @@ public class UpdateReservedListCommandTest extends public void testFailure_reservedListDoesntExist() throws Exception { String errorMessage = "Could not update reserved list xn--q9jyb4c_poobah because it doesn't exist."; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(errorMessage); - runCommand("--force", "--name=xn--q9jyb4c_poobah", "--input=" + reservedTermsPath); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommand("--force", "--name=xn--q9jyb4c_poobah", "--input=" + reservedTermsPath)); + assertThat(thrown).hasMessageThat().contains(errorMessage); } } diff --git a/javatests/google/registry/tools/UpdateServerLocksCommandTest.java b/javatests/google/registry/tools/UpdateServerLocksCommandTest.java index aa137f86a..07a88512d 100644 --- a/javatests/google/registry/tools/UpdateServerLocksCommandTest.java +++ b/javatests/google/registry/tools/UpdateServerLocksCommandTest.java @@ -14,6 +14,8 @@ package google.registry.tools; +import static google.registry.testing.JUnitBackports.assertThrows; + import com.beust.jcommander.ParameterException; import org.junit.Test; @@ -57,69 +59,123 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase + runCommandForced( + "--client=NewRegistrar", + "--registrar_request=true", + "--reason=Test", + "--domain_name=example.tld", + "--apply=all", + "--remove=serverRenewProhibited")); } @Test public void testFailure_illegalStatus() throws Exception { // The EPP status is a valid one by RFC, but invalid for this command. - thrown.expect(IllegalArgumentException.class); - runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", - "--domain_name=example.tld", "--apply=clientRenewProhibited"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrar_request=true", + "--reason=Test", + "--domain_name=example.tld", + "--apply=clientRenewProhibited")); } @Test public void testFailure_unrecognizedStatus() throws Exception { // Handles a status passed to the command that doesn't correspond to any // EPP-valid status. - thrown.expect(IllegalArgumentException.class); - runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", - "--domain_name=example.tld", "--apply=foo"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrar_request=true", + "--reason=Test", + "--domain_name=example.tld", + "--apply=foo")); } @Test public void testFailure_mainParameter() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", - "--domain_name=example.tld", "example2.tld", "--apply=serverRenewProhibited"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrar_request=true", + "--reason=Test", + "--domain_name=example.tld", + "example2.tld", + "--apply=serverRenewProhibited")); } @Test public void testFailure_noOp() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--apply=all", - "--remove=serverRenewProhibited,serverTransferProhibited," - + "serverDeleteProhibited,serverUpdateProhibited,serverHold", - "--registrar_request=true", "--reason=Test"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--domain_name=example.tld", + "--apply=all", + "--remove=serverRenewProhibited,serverTransferProhibited," + + "serverDeleteProhibited,serverUpdateProhibited,serverHold", + "--registrar_request=true", + "--reason=Test")); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--domain_name=example.tld", "--registrar_request=true", - "--apply=serverRenewProhibited", "--reason=Test"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--domain_name=example.tld", + "--registrar_request=true", + "--apply=serverRenewProhibited", + "--reason=Test")); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", - "--domain_name=example.tld", "--apply=serverRenewProhibited", "--foo=bar"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrar_request=true", + "--reason=Test", + "--domain_name=example.tld", + "--apply=serverRenewProhibited", + "--foo=bar")); } @Test public void testFailure_noReasonWhenNotRegistrarRequested() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommandForced("--client=NewRegistrar", "--registrar_request=false", - "--domain_name=example.tld", "--apply=serverRenewProhibited"); + assertThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--registrar_request=false", + "--domain_name=example.tld", + "--apply=serverRenewProhibited")); } @Test public void testFailure_missingRegistrarRequest() throws Exception { - thrown.expect(ParameterException.class); - runCommandForced("--client=NewRegistrar", "--reason=Test", - "--domain_name=example.tld", "--apply=serverRenewProhibited"); + assertThrows( + ParameterException.class, + () -> + runCommandForced( + "--client=NewRegistrar", + "--reason=Test", + "--domain_name=example.tld", + "--apply=serverRenewProhibited")); } } diff --git a/javatests/google/registry/tools/UpdateTldCommandTest.java b/javatests/google/registry/tools/UpdateTldCommandTest.java index 3cfbe80fa..0bb39aa52 100644 --- a/javatests/google/registry/tools/UpdateTldCommandTest.java +++ b/javatests/google/registry/tools/UpdateTldCommandTest.java @@ -465,88 +465,128 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidAddGracePeriod() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"5m\""); - runCommandForced("--add_grace_period=5m", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--add_grace_period=5m", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\""); } @Test public void testFailure_invalidRedemptionGracePeriod() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"5m\""); - runCommandForced("--redemption_grace_period=5m", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--redemption_grace_period=5m", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\""); } @Test public void testFailure_invalidPendingDeleteLength() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid format: \"5m\""); - runCommandForced("--pending_delete_length=5m", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--pending_delete_length=5m", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\""); } @Test public void testFailure_invalidTldState() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage( - "INVALID_STATE not formatted correctly or has transition times out of order"); - runCommandForced("--tld_state_transitions=" + START_OF_TIME + "=INVALID_STATE", "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--tld_state_transitions=" + START_OF_TIME + "=INVALID_STATE", "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("INVALID_STATE not formatted correctly or has transition times out of order"); } @Test public void testFailure_invalidTldStateTransitionTime() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage( - "INVALID_STATE not formatted correctly or has transition times out of order"); - runCommandForced("--tld_state_transitions=tomorrow=INVALID_STATE", "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced("--tld_state_transitions=tomorrow=INVALID_STATE", "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("INVALID_STATE not formatted correctly or has transition times out of order"); } @Test public void testFailure_tldStatesOutOfOrder() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The TLD states are chronologically out of order"); - runCommandForced( - String.format( - "--tld_state_transitions=%s=SUNRISE,%s=PREDELEGATION", now, now.plusMonths(1)), - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + String.format( + "--tld_state_transitions=%s=SUNRISE,%s=PREDELEGATION", + now, now.plusMonths(1)), + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order"); } @Test public void testFailure_duplicateTldStateTransitions() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The TLD states are chronologically out of order"); - runCommandForced( - String.format("--tld_state_transitions=%s=SUNRISE,%s=SUNRISE", now, now.plusMonths(1)), - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + String.format( + "--tld_state_transitions=%s=SUNRISE,%s=SUNRISE", now, now.plusMonths(1)), + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order"); } @Test public void testFailure_duplicateTldStateTransitionTimes() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("not formatted correctly or has transition times out of order"); - runCommandForced( - String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now), - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now), + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("not formatted correctly or has transition times out of order"); } @Test public void testFailure_outOfOrderTldStateTransitionTimes() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("not formatted correctly or has transition times out of order"); - runCommandForced( - String.format( - "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", - now, now.minus(Duration.millis(1))), - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + String.format( + "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", + now, now.minus(Duration.millis(1))), + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("not formatted correctly or has transition times out of order"); } @Test public void testFailure_bothTldStateFlags() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Don't pass both --set_current_tld_state and --tld_state_transitions"); - runCommandForced( - String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plusDays(1)), - "--set_current_tld_state=GENERAL_AVAILABILITY", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + String.format( + "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", + now, now.plusDays(1)), + "--set_current_tld_state=GENERAL_AVAILABILITY", + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("Don't pass both --set_current_tld_state and --tld_state_transitions"); } @Test @@ -558,9 +598,11 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The TLD states are chronologically out of order"); - runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order"); } @Test @@ -572,9 +614,13 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.plusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(" when there is a later transition already scheduled"); - runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains(" when there is a later transition already scheduled"); } @Test @@ -586,99 +632,139 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("--set_current_tld_state is not safe to use in production."); - runCommandInEnvironment( - RegistryToolEnvironment.PRODUCTION, - "--set_current_tld_state=SUNRISE", - "xn--q9jyb4c", - "--force"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandInEnvironment( + RegistryToolEnvironment.PRODUCTION, + "--set_current_tld_state=SUNRISE", + "xn--q9jyb4c", + "--force")); + assertThat(thrown) + .hasMessageThat() + .contains("--set_current_tld_state is not safe to use in production."); } @Test public void testFailure_invalidRenewBillingCost() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("not formatted correctly or has transition times out of order"); - runCommandForced( - String.format("--renew_billing_cost_transitions=%s=US42", START_OF_TIME), "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + String.format("--renew_billing_cost_transitions=%s=US42", START_OF_TIME), + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("not formatted correctly or has transition times out of order"); } @Test public void testFailure_negativeRenewBillingCost() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Renew billing cost cannot be negative"); - runCommandForced( - String.format("--renew_billing_cost_transitions=%s=USD-42", START_OF_TIME), - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + String.format("--renew_billing_cost_transitions=%s=USD-42", START_OF_TIME), + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Renew billing cost cannot be negative"); } @Test public void testFailure_invalidRenewCostTransitionTime() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("not formatted correctly or has transition times out of order"); - runCommandForced("--renew_billing_cost_transitions=tomorrow=USD 1", "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced("--renew_billing_cost_transitions=tomorrow=USD 1", "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("not formatted correctly or has transition times out of order"); } @Test public void testFailure_duplicateRenewCostTransitionTimes() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("not formatted correctly or has transition times out of order"); - runCommandForced( - String.format("--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", now, now), - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + String.format( + "--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", now, now), + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("not formatted correctly or has transition times out of order"); } @Test public void testFailure_outOfOrderRenewCostTransitionTimes() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("not formatted correctly or has transition times out of order"); - runCommandForced( - String.format( - "--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", - now, now.minus(Duration.millis(1))), - "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + String.format( + "--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", + now, now.minus(Duration.millis(1))), + "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("not formatted correctly or has transition times out of order"); } @Test public void testFailure_noTldName() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")"); - runCommandForced(); + ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced()); + assertThat(thrown) + .hasMessageThat() + .contains("Main parameters are required (\"Names of the TLDs\")"); } @Test public void testFailure_oneTldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("TLD foo does not exist"); - runCommandForced("foo", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommandForced("foo", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("TLD foo does not exist"); } @Test public void testFailure_duplicateArguments() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Duplicate arguments found: 'xn--q9jyb4c'"); - runCommandForced("xn--q9jyb4c", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, () -> runCommandForced("xn--q9jyb4c", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("Duplicate arguments found: 'xn--q9jyb4c'"); } @Test public void testFailure_tldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("TLD foobarbaz does not exist"); - runCommandForced("foobarbaz"); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommandForced("foobarbaz")); + assertThat(thrown).hasMessageThat().contains("TLD foobarbaz does not exist"); } @Test public void testFailure_specifiedDnsWriter_doesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); - runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter")); + assertThat(thrown) + .hasMessageThat() + .contains("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); } @Test public void testFailure_setNonExistentReservedLists() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld"); - runCommandForced("--reserved_lists", "xn--q9jyb4c_ZZZ", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--reserved_lists", "xn--q9jyb4c_ZZZ", "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains("Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld"); } @Test @@ -686,9 +772,11 @@ public class UpdateTldCommandTest extends CommandTestCase { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("xn--q9jyb4c_r1"); - runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_r1"); } @Test @@ -696,19 +784,24 @@ public class UpdateTldCommandTest extends CommandTestCase { persistResource(Registry.get("xn--q9jyb4c").asBuilder() .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("xn--q9jyb4c_Z"); - runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_Z"); } @Test public void testFailure_cantAddAndRemoveSameReservedListSimultaneously() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("xn--q9jyb4c_r1"); - runCommandForced( - "--add_reserved_lists=xn--q9jyb4c_r1", - "--remove_reserved_lists=xn--q9jyb4c_r1", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--add_reserved_lists=xn--q9jyb4c_r1", + "--remove_reserved_lists=xn--q9jyb4c_r1", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_r1"); } @Test @@ -717,9 +810,11 @@ public class UpdateTldCommandTest extends CommandTestCase { Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob")) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("alice"); - runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("alice"); } @Test @@ -728,19 +823,24 @@ public class UpdateTldCommandTest extends CommandTestCase { Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice")) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("bob"); - runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("bob"); } @Test public void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("alice"); - runCommandForced( - "--add_allowed_registrants=alice", - "--remove_allowed_registrants=alice", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--add_allowed_registrants=alice", + "--remove_allowed_registrants=alice", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("alice"); } @Test @@ -750,9 +850,11 @@ public class UpdateTldCommandTest extends CommandTestCase { .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns1.example.com", "ns2.example.com")) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("ns1.example.com"); - runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("ns1.example.com"); } @Test @@ -762,19 +864,24 @@ public class UpdateTldCommandTest extends CommandTestCase { .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns1.example.com")) .build()); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("ns2.example.com"); - runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("ns2.example.com"); } @Test public void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("ns1.example.com"); - runCommandForced( - "--add_allowed_nameservers=ns1.example.com", - "--remove_allowed_nameservers=ns1.example.com", - "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> + runCommandForced( + "--add_allowed_nameservers=ns1.example.com", + "--remove_allowed_nameservers=ns1.example.com", + "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("ns1.example.com"); } @Test @@ -895,9 +1002,11 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_setPremiumListThatDoesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("The premium list 'phonies' doesn't exist"); - runCommandForced("--premium_list=phonies", "xn--q9jyb4c"); + IllegalArgumentException thrown = + expectThrows( + IllegalArgumentException.class, + () -> runCommandForced("--premium_list=phonies", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("The premium list 'phonies' doesn't exist"); } @Test @@ -910,17 +1019,24 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_updateLrpPeriod_backwardsInterval() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage( - "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval"); - runCommandForced("--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, + () -> + runCommandForced( + "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", "xn--q9jyb4c")); + assertThat(thrown) + .hasMessageThat() + .contains( + "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval"); } @Test public void testFailure_updateLrpPeriod_badInterval() throws Exception { - thrown.expect(ParameterException.class); - thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval"); - runCommandForced("--lrp_period=foobar", "xn--q9jyb4c"); + ParameterException thrown = + expectThrows( + ParameterException.class, () -> runCommandForced("--lrp_period=foobar", "xn--q9jyb4c")); + assertThat(thrown).hasMessageThat().contains("--lrp_period=foobar not an ISO-8601 interval"); } private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { diff --git a/javatests/google/registry/tools/UploadClaimsListCommandTest.java b/javatests/google/registry/tools/UploadClaimsListCommandTest.java index 938a601fd..8e48371c6 100644 --- a/javatests/google/registry/tools/UploadClaimsListCommandTest.java +++ b/javatests/google/registry/tools/UploadClaimsListCommandTest.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.assertThrows; import google.registry.model.tmch.ClaimsListShard; import java.io.FileNotFoundException; @@ -52,8 +53,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -64,8 +64,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -76,8 +75,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -88,8 +86,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -100,8 +97,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -112,8 +108,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -124,8 +119,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -136,8 +130,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test @@ -148,25 +141,21 @@ public class UploadClaimsListCommandTest extends CommandTestCase runCommand("--force", filename)); } @Test public void testFailure_fileDoesNotExist() throws Exception { - thrown.expect(FileNotFoundException.class); - runCommand("--force", "nonexistent_file.csv"); + assertThrows(FileNotFoundException.class, () -> runCommand("--force", "nonexistent_file.csv")); } @Test public void testFailure_noFileNamePassed() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--force"); + assertThrows(IllegalArgumentException.class, () -> runCommand("--force")); } @Test public void testFailure_tooManyArguments() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand("--force", "foo", "bar"); + assertThrows(IllegalArgumentException.class, () -> runCommand("--force", "foo", "bar")); } } diff --git a/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java b/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java index eca7d182d..f1acbbc54 100644 --- a/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java +++ b/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; import google.registry.rde.RdeTestData; import google.registry.xml.XmlException; @@ -101,9 +102,11 @@ public class ValidateEscrowDepositCommandTest @Test public void testRun_badXml() throws Exception { String file = writeToTmpFile(RdeTestData.loadFile("deposit_full.xml").substring(0, 2000)); - thrown.expect(XmlException.class); - thrown.expectMessage("Syntax error at line 46, column 38: " - + "XML document structures must start and end within the same entity."); - runCommand("--input=" + file); + XmlException thrown = expectThrows(XmlException.class, () -> runCommand("--input=" + file)); + assertThat(thrown) + .hasMessageThat() + .contains( + "Syntax error at line 46, column 38: " + + "XML document structures must start and end within the same entity."); } } diff --git a/javatests/google/registry/tools/ValidateLoginCredentialsCommandTest.java b/javatests/google/registry/tools/ValidateLoginCredentialsCommandTest.java index 253fa6df4..7889bca31 100644 --- a/javatests/google/registry/tools/ValidateLoginCredentialsCommandTest.java +++ b/javatests/google/registry/tools/ValidateLoginCredentialsCommandTest.java @@ -18,6 +18,7 @@ import static google.registry.model.registrar.Registrar.State.ACTIVE; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.assertThrows; import com.beust.jcommander.ParameterException; import com.google.common.collect.ImmutableList; @@ -62,71 +63,81 @@ public class ValidateLoginCredentialsCommandTest @Test public void testFailure_loginWithBadPassword() throws Exception { - thrown.expect(BadRegistrarPasswordException.class); - runCommand( - "--client=NewRegistrar", - "--password=" + new StringBuffer(PASSWORD).reverse(), - "--cert_hash=" + CERT_HASH, - "--ip_address=" + CLIENT_IP); + assertThrows( + BadRegistrarPasswordException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--password=" + new StringBuilder(PASSWORD).reverse(), + "--cert_hash=" + CERT_HASH, + "--ip_address=" + CLIENT_IP)); } @Test public void testFailure_loginWithBadCertificateHash() throws Exception { - thrown.expect(EppException.class); - runCommand( - "--client=NewRegistrar", - "--password=" + PASSWORD, - "--cert_hash=" + new StringBuffer(CERT_HASH).reverse(), - "--ip_address=" + CLIENT_IP); + assertThrows( + EppException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--password=" + PASSWORD, + "--cert_hash=" + new StringBuilder(CERT_HASH).reverse(), + "--ip_address=" + CLIENT_IP)); } @Test public void testFailure_loginWithBadIp() throws Exception { - thrown.expect(EppException.class); - runCommand( - "--client=NewRegistrar", - "--password=" + PASSWORD, - "--cert_hash=" + CERT_HASH, - "--ip_address=" + new StringBuffer(CLIENT_IP).reverse()); + assertThrows( + EppException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--password=" + PASSWORD, + "--cert_hash=" + CERT_HASH, + "--ip_address=" + new StringBuilder(CLIENT_IP).reverse())); } @Test public void testFailure_missingClientId() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--password=" + PASSWORD, - "--cert_hash=" + CERT_HASH, - "--ip_address=" + CLIENT_IP); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--password=" + PASSWORD, "--cert_hash=" + CERT_HASH, "--ip_address=" + CLIENT_IP)); } @Test public void testFailure_missingPassword() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--client=NewRegistrar", - "--cert_hash=" + CERT_HASH, - "--ip_address=" + CLIENT_IP); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--client=NewRegistrar", "--cert_hash=" + CERT_HASH, "--ip_address=" + CLIENT_IP)); } @Test public void testFailure_unknownFlag() throws Exception { - thrown.expect(ParameterException.class); - runCommand( - "--client=NewRegistrar", - "--password=" + PASSWORD, - "--cert_hash=" + CERT_HASH, - "--ip_address=" + CLIENT_IP, - "--unrecognized_flag=foo"); + assertThrows( + ParameterException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--password=" + PASSWORD, + "--cert_hash=" + CERT_HASH, + "--ip_address=" + CLIENT_IP, + "--unrecognized_flag=foo")); } @Test public void testFailure_certHashAndCertFile() throws Exception { - thrown.expect(IllegalArgumentException.class); - runCommand( - "--client=NewRegistrar", - "--password=" + PASSWORD, - "--cert_hash=" + CERT_HASH, - "--cert_file=" + tmpDir.newFile(), - "--ip_address=" + CLIENT_IP); + assertThrows( + IllegalArgumentException.class, + () -> + runCommand( + "--client=NewRegistrar", + "--password=" + PASSWORD, + "--cert_hash=" + CERT_HASH, + "--cert_file=" + tmpDir.newFile(), + "--ip_address=" + CLIENT_IP)); } } diff --git a/javatests/google/registry/tools/VerifyOteCommandTest.java b/javatests/google/registry/tools/VerifyOteCommandTest.java index aac13dd60..0f4cd4584 100644 --- a/javatests/google/registry/tools/VerifyOteCommandTest.java +++ b/javatests/google/registry/tools/VerifyOteCommandTest.java @@ -14,8 +14,10 @@ package google.registry.tools; +import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; +import static google.registry.testing.JUnitBackports.expectThrows; import static org.mockito.Matchers.anyMapOf; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -66,16 +68,17 @@ public class VerifyOteCommandTest extends CommandTestCase { @Test public void testFailure_registrarDoesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Registrar blobio does not exist."); - runCommand("blobio"); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommand("blobio")); + assertThat(thrown).hasMessageThat().contains("Registrar blobio does not exist."); } @Test public void testFailure_noRegistrarsNoCheckAll() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "Must provide at least one registrar name, or supply --check-all with no names."); - runCommand(""); + IllegalArgumentException thrown = + expectThrows(IllegalArgumentException.class, () -> runCommand("")); + assertThat(thrown) + .hasMessageThat() + .contains("Must provide at least one registrar name, or supply --check-all with no names."); } }