diff --git a/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java b/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java index 05a60d23a..436406525 100644 --- a/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java +++ b/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java @@ -649,8 +649,8 @@ public class ExpandRecurringBillingEventsActionTest @Test public void testFailure_cursorAfterExecutionTime() throws Exception { action.cursorTimeParam = Optional.of(clock.nowUtc().plusYears(1)); - thrown.expect( - IllegalArgumentException.class, "Cursor time must be earlier than execution time."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Cursor time must be earlier than execution time."); runMapreduce(); } @@ -658,8 +658,8 @@ public class ExpandRecurringBillingEventsActionTest public void testFailure_cursorAtExecutionTime() throws Exception { // The clock advances one milli on runMapreduce. action.cursorTimeParam = Optional.of(clock.nowUtc().plusMillis(1)); - thrown.expect( - IllegalArgumentException.class, "Cursor time must be earlier than execution time."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Cursor time must be earlier than execution time."); runMapreduce(); } diff --git a/javatests/google/registry/dns/DnsInjectionTest.java b/javatests/google/registry/dns/DnsInjectionTest.java index 0f27efff6..cb50ffd42 100644 --- a/javatests/google/registry/dns/DnsInjectionTest.java +++ b/javatests/google/registry/dns/DnsInjectionTest.java @@ -97,7 +97,8 @@ public final class DnsInjectionTest { public void testRefreshDns_missingDomain_throwsNotFound() throws Exception { when(req.getParameter("type")).thenReturn("domain"); when(req.getParameter("name")).thenReturn("example.lol"); - thrown.expect(NotFoundException.class, "domain example.lol not found"); + thrown.expect(NotFoundException.class); + thrown.expectMessage("domain example.lol not found"); component.refreshDns().run(); } @@ -114,7 +115,8 @@ public final class DnsInjectionTest { public void testRefreshDns_missingHost_throwsNotFound() throws Exception { when(req.getParameter("type")).thenReturn("host"); when(req.getParameter("name")).thenReturn("ns1.example.lol"); - thrown.expect(NotFoundException.class, "host ns1.example.lol not found"); + thrown.expect(NotFoundException.class); + thrown.expectMessage("host ns1.example.lol not found"); component.refreshDns().run(); } } diff --git a/javatests/google/registry/dns/DnsQueueTest.java b/javatests/google/registry/dns/DnsQueueTest.java index 5871240c2..57039ac5a 100644 --- a/javatests/google/registry/dns/DnsQueueTest.java +++ b/javatests/google/registry/dns/DnsQueueTest.java @@ -62,8 +62,8 @@ public class DnsQueueTest { @Test public void test_addHostRefreshTask_failsOnUnknownTld() throws Exception { - thrown.expect(IllegalArgumentException.class, - "octopus.notatld is not a subordinate host to a known tld"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("octopus.notatld is not a subordinate host to a known tld"); try { dnsQueue.addHostRefreshTask("octopus.notatld"); } finally { @@ -85,7 +85,8 @@ public class DnsQueueTest { @Test public void test_addDomainRefreshTask_failsOnUnknownTld() throws Exception { - thrown.expect(IllegalArgumentException.class, "TLD notatld does not exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("TLD notatld does not exist"); try { dnsQueue.addDomainRefreshTask("fake.notatld"); } finally { diff --git a/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java b/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java index b19db2834..f119f57fa 100644 --- a/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java +++ b/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java @@ -187,7 +187,8 @@ public class PublishDnsUpdatesActionTest { @Test public void testLockIsntAvailable() throws Exception { - thrown.expect(ServiceUnavailableException.class, "Lock failure"); + thrown.expect(ServiceUnavailableException.class); + thrown.expectMessage("Lock failure"); action = createAction("xn--q9jyb4c"); action.domains = ImmutableSet.of("example.com", "example2.com"); action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com"); diff --git a/javatests/google/registry/dns/RefreshDnsActionTest.java b/javatests/google/registry/dns/RefreshDnsActionTest.java index eb2809418..7848821c2 100644 --- a/javatests/google/registry/dns/RefreshDnsActionTest.java +++ b/javatests/google/registry/dns/RefreshDnsActionTest.java @@ -78,8 +78,8 @@ public class RefreshDnsActionTest { public void testSuccess_externalHostNotEnqueued() throws Exception { persistActiveDomain("example.xn--q9jyb4c"); persistActiveHost("ns1.example.xn--q9jyb4c"); - thrown.expect(BadRequestException.class, - "ns1.example.xn--q9jyb4c isn't a subordinate hostname"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("ns1.example.xn--q9jyb4c isn't a subordinate hostname"); try { run(TargetType.HOST, "ns1.example.xn--q9jyb4c"); } finally { diff --git a/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java b/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java index 31390816a..30e1c35fa 100644 --- a/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java +++ b/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java @@ -16,7 +16,7 @@ package google.registry.dns.writer.dnsupdate; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; -import static google.registry.testing.JUnitBackports.expectThrows; +import static google.registry.testing.JUnitBackports.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -129,8 +129,7 @@ public class DnsMessageTransportTest { Duration testTimeout = Duration.standardSeconds(1); DnsMessageTransport resolver = new DnsMessageTransport(mockFactory, UPDATE_HOST, testTimeout); Message expectedQuery = new Message(); - SocketTimeoutException e = - expectThrows(SocketTimeoutException.class, () -> resolver.send(expectedQuery)); + assertThrows(SocketTimeoutException.class, () -> resolver.send(expectedQuery)); verify(mockSocket).setSoTimeout((int) testTimeout.getMillis()); } @@ -146,7 +145,8 @@ public class DnsMessageTransportTest { } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); when(mockSocket.getOutputStream()).thenReturn(outputStream); - thrown.expect(IllegalArgumentException.class, "message larger than maximum"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("message larger than maximum"); resolver.send(oversize); } @@ -157,9 +157,8 @@ public class DnsMessageTransportTest { when(mockSocket.getInputStream()) .thenReturn(new ByteArrayInputStream(messageToBytesWithLength(expectedResponse))); when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream()); - thrown.expect( - VerifyException.class, - "response ID " + thrown.expect(VerifyException.class); + thrown.expectMessage("response ID " + expectedResponse.getHeader().getID() + " does not match query ID " + simpleQuery.getHeader().getID()); @@ -174,8 +173,8 @@ public class DnsMessageTransportTest { when(mockSocket.getInputStream()) .thenReturn(new ByteArrayInputStream(messageToBytesWithLength(expectedResponse))); when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream()); - thrown.expect( - VerifyException.class, "response opcode 'STATUS' does not match query opcode 'QUERY'"); + thrown.expect(VerifyException.class); + thrown.expectMessage("response opcode 'STATUS' does not match query opcode 'QUERY'"); resolver.send(simpleQuery); } diff --git a/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java b/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java index c11ea7c84..72fcbed8a 100644 --- a/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java +++ b/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java @@ -390,7 +390,8 @@ public class DnsUpdateWriterTest { .build(); persistResource(domain); when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL)); - thrown.expect(VerifyException.class, "SERVFAIL"); + thrown.expect(VerifyException.class); + thrown.expectMessage("SERVFAIL"); writer.publishDomain("example.tld"); writer.commit(); @@ -405,7 +406,8 @@ public class DnsUpdateWriterTest { .build(); persistResource(host); when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL)); - thrown.expect(VerifyException.class, "SERVFAIL"); + thrown.expect(VerifyException.class); + thrown.expectMessage("SERVFAIL"); writer.publishHost("ns1.example.tld"); writer.commit(); diff --git a/javatests/google/registry/export/BigqueryPollJobActionTest.java b/javatests/google/registry/export/BigqueryPollJobActionTest.java index bcd226705..e29777d57 100644 --- a/javatests/google/registry/export/BigqueryPollJobActionTest.java +++ b/javatests/google/registry/export/BigqueryPollJobActionTest.java @@ -208,7 +208,8 @@ public class BigqueryPollJobActionTest { when(bigqueryJobsGet.execute()).thenReturn( new Job().setStatus(new JobStatus().setState("DONE"))); action.payload = "payload".getBytes(UTF_8); - thrown.expect(BadRequestException.class, "Cannot deserialize task from payload"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Cannot deserialize task from payload"); action.run(); } } diff --git a/javatests/google/registry/export/CheckSnapshotActionTest.java b/javatests/google/registry/export/CheckSnapshotActionTest.java index 58e1a141f..e4483a822 100644 --- a/javatests/google/registry/export/CheckSnapshotActionTest.java +++ b/javatests/google/registry/export/CheckSnapshotActionTest.java @@ -124,7 +124,8 @@ public class CheckSnapshotActionTest { public void testPost_forPendingBackup_returnsNotModified() throws Exception { setPendingBackup(); - thrown.expect(NotModifiedException.class, "Datastore backup some_backup still pending"); + thrown.expect(NotModifiedException.class); + thrown.expectMessage("Datastore backup some_backup still pending"); action.run(); } @@ -140,9 +141,8 @@ public class CheckSnapshotActionTest { .plus(Duration.standardMinutes(3)) .plus(Duration.millis(1234))); - thrown.expect( - NoContentException.class, - "Datastore backup some_backup abandoned - " + thrown.expect(NoContentException.class); + thrown.expectMessage("Datastore backup some_backup abandoned - " + "not complete after 20 hours, 3 minutes and 1 second"); action.run(); @@ -188,7 +188,8 @@ public class CheckSnapshotActionTest { when(backupService.findByName("some_backup")) .thenThrow(new IllegalArgumentException("No backup found")); - thrown.expect(BadRequestException.class, "Bad backup name some_backup: No backup found"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Bad backup name some_backup: No backup found"); action.run(); } @@ -219,7 +220,8 @@ public class CheckSnapshotActionTest { when(backupService.findByName("some_backup")) .thenThrow(new IllegalArgumentException("No backup found")); - thrown.expect(BadRequestException.class, "Bad backup name some_backup: No backup found"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Bad backup name some_backup: No backup found"); action.run(); } diff --git a/javatests/google/registry/export/LoadSnapshotActionTest.java b/javatests/google/registry/export/LoadSnapshotActionTest.java index a2eb35f6a..a7a23a56f 100644 --- a/javatests/google/registry/export/LoadSnapshotActionTest.java +++ b/javatests/google/registry/export/LoadSnapshotActionTest.java @@ -186,18 +186,16 @@ public class LoadSnapshotActionTest { @Test public void testFailure_doPost_badGcsFilename() throws Exception { action.snapshotFile = "gs://bucket/snapshot"; - thrown.expect( - BadRequestException.class, - "Error calling load snapshot: backup info file extension missing"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Error calling load snapshot: backup info file extension missing"); action.run(); } @Test public void testFailure_doPost_bigqueryThrowsException() throws Exception { when(bigqueryJobsInsert.execute()).thenThrow(new IOException("The Internet has gone missing")); - thrown.expect( - InternalServerErrorException.class, - "Error loading snapshot: The Internet has gone missing"); + thrown.expect(InternalServerErrorException.class); + thrown.expectMessage("Error loading snapshot: The Internet has gone missing"); action.run(); } } diff --git a/javatests/google/registry/export/PublishDetailReportActionTest.java b/javatests/google/registry/export/PublishDetailReportActionTest.java index ccd5c1b3f..cfdf0a0df 100644 --- a/javatests/google/registry/export/PublishDetailReportActionTest.java +++ b/javatests/google/registry/export/PublishDetailReportActionTest.java @@ -108,7 +108,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_noRegistrarParameter() throws Exception { - thrown.expect(BadRequestException.class, REGISTRAR_ID_PARAM); + thrown.expect(BadRequestException.class); + thrown.expectMessage(REGISTRAR_ID_PARAM); action.handleJsonRequest(ImmutableMap.of( GCS_BUCKET_PARAM, "mah-buckit", GCS_FOLDER_PREFIX_PARAM, "some/folder/", @@ -117,7 +118,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_noGcsBucketParameter() throws Exception { - thrown.expect(BadRequestException.class, GCS_BUCKET_PARAM); + thrown.expect(BadRequestException.class); + thrown.expectMessage(GCS_BUCKET_PARAM); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_FOLDER_PREFIX_PARAM, "some/folder/", @@ -126,7 +128,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_noGcsFolderPrefixParameter() throws Exception { - thrown.expect(BadRequestException.class, GCS_FOLDER_PREFIX_PARAM); + thrown.expect(BadRequestException.class); + thrown.expectMessage(GCS_FOLDER_PREFIX_PARAM); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_BUCKET_PARAM, "mah-buckit", @@ -135,7 +138,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_noReportNameParameter() throws Exception { - thrown.expect(BadRequestException.class, DETAIL_REPORT_NAME_PARAM); + thrown.expect(BadRequestException.class); + thrown.expectMessage(DETAIL_REPORT_NAME_PARAM); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_BUCKET_PARAM, "mah-buckit", @@ -144,7 +148,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_registrarNotFound() throws Exception { - thrown.expect(BadRequestException.class, "FakeRegistrar"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("FakeRegistrar"); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "FakeRegistrar", GCS_BUCKET_PARAM, "mah-buckit", @@ -156,7 +161,8 @@ public class PublishDetailReportActionTest { public void testFailure_registrarHasNoDriveFolder() throws Exception { persistResource( loadRegistrar("TheRegistrar").asBuilder().setDriveFolderId(null).build()); - thrown.expect(BadRequestException.class, "drive folder"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("drive folder"); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_BUCKET_PARAM, "mah-buckit", @@ -166,7 +172,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_gcsBucketNotFound() throws Exception { - thrown.expect(BadRequestException.class, "fake-buckit"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("fake-buckit"); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_BUCKET_PARAM, "fake-buckit", @@ -176,7 +183,8 @@ public class PublishDetailReportActionTest { @Test public void testFailure_gcsFileNotFound() throws Exception { - thrown.expect(BadRequestException.class, "some/folder/fake_file.csv"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("some/folder/fake_file.csv"); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_BUCKET_PARAM, "mah-buckit", @@ -189,7 +197,8 @@ public class PublishDetailReportActionTest { when(driveConnection.createFile( anyString(), any(MediaType.class), anyString(), any(byte[].class))) .thenThrow(new IOException("Drive is down")); - thrown.expect(InternalServerErrorException.class, "Drive is down"); + thrown.expect(InternalServerErrorException.class); + thrown.expectMessage("Drive is down"); action.handleJsonRequest(ImmutableMap.of( REGISTRAR_ID_PARAM, "TheRegistrar", GCS_BUCKET_PARAM, "mah-buckit", diff --git a/javatests/google/registry/export/UpdateSnapshotViewActionTest.java b/javatests/google/registry/export/UpdateSnapshotViewActionTest.java index a28be2a92..881477bb1 100644 --- a/javatests/google/registry/export/UpdateSnapshotViewActionTest.java +++ b/javatests/google/registry/export/UpdateSnapshotViewActionTest.java @@ -127,7 +127,8 @@ public class UpdateSnapshotViewActionTest { public void testFailure_bigqueryConnectionThrowsError() throws Exception { when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class))) .thenThrow(new IOException("I'm sorry Dave, I can't let you do that")); - thrown.expect(InternalServerErrorException.class, "Error in update snapshot view action"); + thrown.expect(InternalServerErrorException.class); + thrown.expectMessage("Error in update snapshot view action"); action.run(); } } diff --git a/javatests/google/registry/flows/TlsCredentialsTest.java b/javatests/google/registry/flows/TlsCredentialsTest.java index 327aff2be..f1fa913d1 100644 --- a/javatests/google/registry/flows/TlsCredentialsTest.java +++ b/javatests/google/registry/flows/TlsCredentialsTest.java @@ -42,7 +42,8 @@ public final class TlsCredentialsTest { @Test public void testProvideClientCertificateHash_missing() { - thrown.expect(BadRequestException.class, "Missing header: X-SSL-Certificate"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Missing header: X-SSL-Certificate"); HttpServletRequest req = mock(HttpServletRequest.class); TlsCredentials.EppTlsModule.provideClientCertificateHash(req); } @@ -57,7 +58,8 @@ public final class TlsCredentialsTest { @Test public void testProvideRequestedServername_missing() { - thrown.expect(BadRequestException.class, "Missing header: X-Requested-Servername-SNI"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Missing header: X-Requested-Servername-SNI"); HttpServletRequest req = mock(HttpServletRequest.class); TlsCredentials.EppTlsModule.provideRequestedServername(req); } diff --git a/javatests/google/registry/flows/contact/ContactCreateFlowTest.java b/javatests/google/registry/flows/contact/ContactCreateFlowTest.java index cc32d40d7..122cdf246 100644 --- a/javatests/google/registry/flows/contact/ContactCreateFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactCreateFlowTest.java @@ -66,8 +66,8 @@ public class ContactCreateFlowTest @Test public void testFailure_alreadyExists() throws Exception { persistActiveContact(getUniqueIdFromCommand()); - thrown.expect( - ResourceAlreadyExistsException.class, + thrown.expect(ResourceAlreadyExistsException.class); + thrown.expectMessage( String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); runFlow(); } diff --git a/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java b/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java index c87fa9efb..6c724469f 100644 --- a/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java @@ -69,18 +69,16 @@ public class ContactDeleteFlowTest @Test public void testFailure_neverExisted() throws Exception { - thrown.expect( - ResourceDoesNotExistException.class, - String.format("(%s)", getUniqueIdFromCommand())); + thrown.expect(ResourceDoesNotExistException.class); + thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); runFlow(); } @Test public void testFailure_existedButWasDeleted() throws Exception { persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); - thrown.expect( - ResourceDoesNotExistException.class, - String.format("(%s)", getUniqueIdFromCommand())); + thrown.expect(ResourceDoesNotExistException.class); + thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); runFlow(); } @@ -90,7 +88,8 @@ public class ContactDeleteFlowTest newContactResource(getUniqueIdFromCommand()).asBuilder() .setStatusValues(ImmutableSet.of(statusValue)) .build()); - thrown.expect(exception, statusValue.getXmlName()); + thrown.expect(exception); + thrown.expectMessage(statusValue.getXmlName()); runFlow(); } diff --git a/javatests/google/registry/flows/contact/ContactInfoFlowTest.java b/javatests/google/registry/flows/contact/ContactInfoFlowTest.java index 46aa04d7e..f027cd7ce 100644 --- a/javatests/google/registry/flows/contact/ContactInfoFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactInfoFlowTest.java @@ -163,18 +163,16 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase ofy().save().entity(Cursor.create(RDE_UPLOAD, time, domain))); } @Test public void testFailure_invalidScopeOnKeyCreate() throws Exception { createTld("tld"); - thrown.expect( - IllegalArgumentException.class, "Class required for cursor does not match scope class"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Class required for cursor does not match scope class"); Cursor.createKey(RDE_UPLOAD, persistActiveDomain("notaregistry.tld")); } @Test public void testFailure_createGlobalKeyForScopedCursorType() throws Exception { - thrown.expect(IllegalArgumentException.class, "Cursor type is not a global cursor"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Cursor type is not a global cursor"); Cursor.createGlobalKey(RDE_UPLOAD); } @Test public void testFailure_invalidScopeOnGlobalKeyCreate() throws Exception { createTld("tld"); - thrown.expect( - IllegalArgumentException.class, "Class required for cursor does not match scope class"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Class required for cursor does not match scope class"); Cursor.createKey(RECURRING_BILLING, persistActiveDomain("notaregistry.tld")); } @Test public void testFailure_nullScope() throws Exception { - thrown.expect(NullPointerException.class, "Cursor scope cannot be null"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Cursor scope cannot be null"); Cursor.create(RECURRING_BILLING, START_OF_TIME, null); } @Test public void testFailure_nullCursorType() throws Exception { createTld("tld"); - thrown.expect(NullPointerException.class, "Cursor type cannot be null"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Cursor type cannot be null"); Cursor.create(null, START_OF_TIME, Registry.get("tld")); } @Test public void testFailure_nullTime() throws Exception { createTld("tld"); - thrown.expect(NullPointerException.class, "Cursor time cannot be null"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Cursor time cannot be null"); Cursor.create(RDE_UPLOAD, null, Registry.get("tld")); } } diff --git a/javatests/google/registry/model/contact/ContactResourceTest.java b/javatests/google/registry/model/contact/ContactResourceTest.java index f43b9a473..6d5f9f54a 100644 --- a/javatests/google/registry/model/contact/ContactResourceTest.java +++ b/javatests/google/registry/model/contact/ContactResourceTest.java @@ -206,7 +206,8 @@ public class ContactResourceTest extends EntityTestCase { @Test public void testSetCreationTime_cantBeCalledTwice() { - thrown.expect(IllegalStateException.class, "creationTime can only be set once"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("creationTime can only be set once"); contactResource.asBuilder().setCreationTime(END_OF_TIME); } diff --git a/javatests/google/registry/model/domain/DomainResourceTest.java b/javatests/google/registry/model/domain/DomainResourceTest.java index 5f1e55a7c..1e027ab50 100644 --- a/javatests/google/registry/model/domain/DomainResourceTest.java +++ b/javatests/google/registry/model/domain/DomainResourceTest.java @@ -445,15 +445,15 @@ public class DomainResourceTest extends EntityTestCase { @Test public void testFailure_uppercaseDomainName() { - thrown.expect( - IllegalArgumentException.class, "Domain name must be in puny-coded, lower-case form"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Domain name must be in puny-coded, lower-case form"); domain.asBuilder().setFullyQualifiedDomainName("AAA.BBB"); } @Test public void testFailure_utf8DomainName() { - thrown.expect( - IllegalArgumentException.class, "Domain name must be in puny-coded, lower-case form"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Domain name must be in puny-coded, lower-case form"); domain.asBuilder().setFullyQualifiedDomainName("みんな.みんな"); } } diff --git a/javatests/google/registry/model/domain/GracePeriodTest.java b/javatests/google/registry/model/domain/GracePeriodTest.java index 304371a3b..97e325f01 100644 --- a/javatests/google/registry/model/domain/GracePeriodTest.java +++ b/javatests/google/registry/model/domain/GracePeriodTest.java @@ -96,13 +96,15 @@ public class GracePeriodTest { @Test public void testFailure_forBillingEvent_autoRenew() { - thrown.expect(IllegalArgumentException.class, "autorenew"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("autorenew"); GracePeriod.forBillingEvent(GracePeriodStatus.AUTO_RENEW, onetime); } @Test public void testFailure_createForRecurring_notAutoRenew() { - thrown.expect(IllegalArgumentException.class, "autorenew"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("autorenew"); GracePeriod.createForRecurring( GracePeriodStatus.RENEW, now.plusDays(1), diff --git a/javatests/google/registry/model/host/HostResourceTest.java b/javatests/google/registry/model/host/HostResourceTest.java index b67395a4c..a75957917 100644 --- a/javatests/google/registry/model/host/HostResourceTest.java +++ b/javatests/google/registry/model/host/HostResourceTest.java @@ -163,15 +163,15 @@ public class HostResourceTest extends EntityTestCase { @Test public void testFailure_uppercaseHostName() { - thrown.expect( - IllegalArgumentException.class, "Host name must be in puny-coded, lower-case form"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Host name must be in puny-coded, lower-case form"); host.asBuilder().setFullyQualifiedHostName("AAA.BBB.CCC"); } @Test public void testFailure_utf8HostName() { - thrown.expect( - IllegalArgumentException.class, "Host name must be in puny-coded, lower-case form"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Host name must be in puny-coded, lower-case form"); host.asBuilder().setFullyQualifiedHostName("みんな.みんな.みんな"); } diff --git a/javatests/google/registry/model/index/DomainApplicationIndexTest.java b/javatests/google/registry/model/index/DomainApplicationIndexTest.java index 9d5308b68..67f4dcaad 100644 --- a/javatests/google/registry/model/index/DomainApplicationIndexTest.java +++ b/javatests/google/registry/model/index/DomainApplicationIndexTest.java @@ -49,13 +49,15 @@ public class DomainApplicationIndexTest extends EntityTestCase { @Test public void testFailure_create_nullReferences() { - thrown.expect(IllegalArgumentException.class, "Keys must not be null or empty."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Keys must not be null or empty."); DomainApplicationIndex.createWithSpecifiedKeys("blah.com", null); } @Test public void testFailure_create_emptyReferences() { - thrown.expect(IllegalArgumentException.class, "Keys must not be null or empty."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Keys must not be null or empty."); createWithSpecifiedKeys("blah.com", ImmutableSet.>of()); } diff --git a/javatests/google/registry/model/ofy/CommitLogBucketTest.java b/javatests/google/registry/model/ofy/CommitLogBucketTest.java index 8cef3624d..19308c55d 100644 --- a/javatests/google/registry/model/ofy/CommitLogBucketTest.java +++ b/javatests/google/registry/model/ofy/CommitLogBucketTest.java @@ -69,13 +69,15 @@ public class CommitLogBucketTest { @Test public void test_getBucketKey_bucketNumberTooLow_throws() { - thrown.expect(IllegalArgumentException.class, "0 not in ["); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("0 not in ["); getBucketKey(0); } @Test public void test_getBucketKey_bucketNumberTooHigh_throws() { - thrown.expect(IllegalArgumentException.class, "11 not in ["); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("11 not in ["); getBucketKey(11); } diff --git a/javatests/google/registry/model/ofy/CommitLogCheckpointTest.java b/javatests/google/registry/model/ofy/CommitLogCheckpointTest.java index 4cdf4e848..25d1edb05 100644 --- a/javatests/google/registry/model/ofy/CommitLogCheckpointTest.java +++ b/javatests/google/registry/model/ofy/CommitLogCheckpointTest.java @@ -60,25 +60,29 @@ public class CommitLogCheckpointTest { @Test public void test_create_notEnoughBucketTimestamps_throws() { - thrown.expect(IllegalArgumentException.class, "Bucket ids are incorrect"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Bucket ids are incorrect"); CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2)); } @Test public void test_create_tooManyBucketTimestamps_throws() { - thrown.expect(IllegalArgumentException.class, "Bucket ids are incorrect"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Bucket ids are incorrect"); CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2, 3, T3, 4, T1)); } @Test public void test_create_wrongBucketIds_throws() { - thrown.expect(IllegalArgumentException.class, "Bucket ids are incorrect"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Bucket ids are incorrect"); CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(0, T1, 1, T2, 2, T3)); } @Test public void test_create_wrongBucketIdOrder_throws() { - thrown.expect(IllegalArgumentException.class, "Bucket ids are incorrect"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Bucket ids are incorrect"); CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(2, T2, 1, T1, 3, T3)); } } diff --git a/javatests/google/registry/model/ofy/OfyCommitLogTest.java b/javatests/google/registry/model/ofy/OfyCommitLogTest.java index b0fb4ffe4..b2d95fd67 100644 --- a/javatests/google/registry/model/ofy/OfyCommitLogTest.java +++ b/javatests/google/registry/model/ofy/OfyCommitLogTest.java @@ -163,7 +163,8 @@ public class OfyCommitLogTest { public void testTransactNew_deleteNotBackedUpKind_throws() throws Exception { final CommitLogManifest backupsArentAllowedOnMe = CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.>of()); - thrown.expect(IllegalArgumentException.class, "Can't save/delete a @NotBackedUp"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Can't save/delete a @NotBackedUp"); ofy().transactNew(() -> ofy().delete().entity(backupsArentAllowedOnMe)); } @@ -171,41 +172,47 @@ public class OfyCommitLogTest { public void testTransactNew_saveNotBackedUpKind_throws() throws Exception { final CommitLogManifest backupsArentAllowedOnMe = CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.>of()); - thrown.expect(IllegalArgumentException.class, "Can't save/delete a @NotBackedUp"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Can't save/delete a @NotBackedUp"); ofy().transactNew(() -> ofy().save().entity(backupsArentAllowedOnMe)); } @Test public void testTransactNew_deleteVirtualEntityKey_throws() throws Exception { final Key virtualEntityKey = TestVirtualObject.createKey("virtual"); - thrown.expect(IllegalArgumentException.class, "Can't save/delete a @VirtualEntity"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Can't save/delete a @VirtualEntity"); ofy().transactNew(() -> ofy().delete().key(virtualEntityKey)); } @Test public void testTransactNew_saveVirtualEntity_throws() throws Exception { final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual"); - thrown.expect(IllegalArgumentException.class, "Can't save/delete a @VirtualEntity"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Can't save/delete a @VirtualEntity"); ofy().transactNew(() -> ofy().save().entity(virtualEntity)); } @Test public void test_deleteWithoutBackup_withVirtualEntityKey_throws() throws Exception { final Key virtualEntityKey = TestVirtualObject.createKey("virtual"); - thrown.expect(IllegalArgumentException.class, "Can't save/delete a @VirtualEntity"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Can't save/delete a @VirtualEntity"); ofy().deleteWithoutBackup().key(virtualEntityKey); } @Test public void test_saveWithoutBackup_withVirtualEntity_throws() throws Exception { final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual"); - thrown.expect(IllegalArgumentException.class, "Can't save/delete a @VirtualEntity"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Can't save/delete a @VirtualEntity"); ofy().saveWithoutBackup().entity(virtualEntity); } @Test public void testTransact_twoSavesOnSameKey_throws() throws Exception { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); ofy() .transact( () -> { @@ -216,7 +223,8 @@ public class OfyCommitLogTest { @Test public void testTransact_saveAndDeleteSameKey_throws() throws Exception { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); ofy() .transact( () -> { diff --git a/javatests/google/registry/model/ofy/OfyTest.java b/javatests/google/registry/model/ofy/OfyTest.java index 62f1d485b..b9a78d9f1 100644 --- a/javatests/google/registry/model/ofy/OfyTest.java +++ b/javatests/google/registry/model/ofy/OfyTest.java @@ -92,9 +92,8 @@ public class OfyTest { .getUpdateAutoTimestamp().getTimestamp(); // Set the clock in Ofy to the same time as the backup group root's save time. Ofy ofy = new Ofy(new FakeClock(groupTimestamp)); - thrown.expect( - TimestampInversionException.class, - String.format( + thrown.expect(TimestampInversionException.class); + thrown.expectMessage(String.format( "Timestamp inversion between transaction time (%s) and entities rooted under:\n" + "{Key(ContactResource(\"2-ROID\"))=%s}", groupTimestamp, @@ -122,7 +121,8 @@ public class OfyTest { @Test public void testSavingKeyTwice() { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -133,7 +133,8 @@ public class OfyTest { @Test public void testDeletingKeyTwice() { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -144,7 +145,8 @@ public class OfyTest { @Test public void testSaveDeleteKey() { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -155,7 +157,8 @@ public class OfyTest { @Test public void testDeleteSaveKey() { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -372,13 +375,15 @@ public class OfyTest { @Test public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntity() { - thrown.expect(IllegalStateException.class, "SystemClock"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("SystemClock"); getBaseEntityClassFromEntityOrKey(new SystemClock()); } @Test public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntityKey() { - thrown.expect(IllegalArgumentException.class, "UnknownKind"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("UnknownKind"); getBaseEntityClassFromEntityOrKey(Key.create( com.google.appengine.api.datastore.KeyFactory.createKey("UnknownKind", 1))); } diff --git a/javatests/google/registry/model/rde/RdeRevisionTest.java b/javatests/google/registry/model/rde/RdeRevisionTest.java index 2c81ac6a8..4b0137032 100644 --- a/javatests/google/registry/model/rde/RdeRevisionTest.java +++ b/javatests/google/registry/model/rde/RdeRevisionTest.java @@ -70,7 +70,8 @@ public class RdeRevisionTest { @Test public void testSaveRevision_objectDoesntExist_newRevisionIsOne_throwsVe() throws Exception { - thrown.expect(VerifyException.class, "object missing"); + thrown.expect(VerifyException.class); + thrown.expectMessage("object missing"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -81,7 +82,8 @@ public class RdeRevisionTest { @Test public void testSaveRevision_objectExistsAtZero_newRevisionIsZero_throwsVe() throws Exception { save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0); - thrown.expect(VerifyException.class, "object already created"); + thrown.expect(VerifyException.class); + thrown.expectMessage("object already created"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -108,7 +110,8 @@ public class RdeRevisionTest { @Test public void testSaveRevision_objectExistsAtZero_newRevisionIsTwo_throwsVe() throws Exception { save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0); - thrown.expect(VerifyException.class, "should be at 1 "); + thrown.expect(VerifyException.class); + thrown.expectMessage("should be at 1 "); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -118,7 +121,8 @@ public class RdeRevisionTest { @Test public void testSaveRevision_negativeRevision_throwsIae() throws Exception { - thrown.expect(IllegalArgumentException.class, "Negative revision"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Negative revision"); ofy().transact(new VoidWork() { @Override public void vrun() { @@ -128,7 +132,8 @@ public class RdeRevisionTest { @Test public void testSaveRevision_callerNotInTransaction_throwsIse() throws Exception { - thrown.expect(IllegalStateException.class, "transaction"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("transaction"); saveRevision("frenzy", DateTime.parse("1984-12-18TZ"), FULL, 1); } diff --git a/javatests/google/registry/model/registrar/RegistrarTest.java b/javatests/google/registry/model/registrar/RegistrarTest.java index 1231aa7e0..9047135b6 100644 --- a/javatests/google/registry/model/registrar/RegistrarTest.java +++ b/javatests/google/registry/model/registrar/RegistrarTest.java @@ -143,19 +143,22 @@ public class RegistrarTest extends EntityTestCase { @Test public void testFailure_passwordNull() throws Exception { - thrown.expect(IllegalArgumentException.class, "Password must be 6-16 characters long."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Password must be 6-16 characters long."); new Registrar.Builder().setPassword(null); } @Test public void testFailure_passwordTooShort() throws Exception { - thrown.expect(IllegalArgumentException.class, "Password must be 6-16 characters long."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Password must be 6-16 characters long."); new Registrar.Builder().setPassword("abcde"); } @Test public void testFailure_passwordTooLong() throws Exception { - thrown.expect(IllegalArgumentException.class, "Password must be 6-16 characters long."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Password must be 6-16 characters long."); new Registrar.Builder().setPassword("abcdefghijklmnopq"); } @@ -315,21 +318,22 @@ public class RegistrarTest extends EntityTestCase { @Test public void testFailure_missingRegistrarType() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar type cannot be null"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar type cannot be null"); new Registrar.Builder().setRegistrarName("blah").build(); } @Test public void testFailure_missingRegistrarName() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar name cannot be null"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar name cannot be null"); new Registrar.Builder().setClientId("blahid").setType(Registrar.Type.TEST).build(); } @Test public void testFailure_missingAddress() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "Must specify at least one of localized or internationalized address"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Must specify at least one of localized or internationalized address"); new Registrar.Builder() .setClientId("blahid") .setType(Registrar.Type.TEST) @@ -416,25 +420,29 @@ public class RegistrarTest extends EntityTestCase { @Test public void testFailure_loadByClientId_clientIdIsNull() throws Exception { - thrown.expect(IllegalArgumentException.class, "clientId must be specified"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("clientId must be specified"); Registrar.loadByClientId(null); } @Test public void testFailure_loadByClientId_clientIdIsEmpty() throws Exception { - thrown.expect(IllegalArgumentException.class, "clientId must be specified"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("clientId must be specified"); Registrar.loadByClientId(""); } @Test public void testFailure_loadByClientIdCached_clientIdIsNull() throws Exception { - thrown.expect(IllegalArgumentException.class, "clientId must be specified"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("clientId must be specified"); Registrar.loadByClientIdCached(null); } @Test public void testFailure_loadByClientIdCached_clientIdIsEmpty() throws Exception { - thrown.expect(IllegalArgumentException.class, "clientId must be specified"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("clientId must be specified"); Registrar.loadByClientIdCached(""); } } diff --git a/javatests/google/registry/model/registry/RegistryTest.java b/javatests/google/registry/model/registry/RegistryTest.java index 74ad0fdf1..5f1a0405c 100644 --- a/javatests/google/registry/model/registry/RegistryTest.java +++ b/javatests/google/registry/model/registry/RegistryTest.java @@ -202,8 +202,8 @@ public class RegistryTest extends EntityTestCase { ReservedList rl3 = persistReservedList( "tld-reserved057", "lol,RESERVED_FOR_ANCHOR_TENANT,another_conflict"); - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "auth code conflicts for labels: [lol=[conflict1, conflict2, another_conflict]]"); @SuppressWarnings("unused") Registry unused = Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build(); @@ -354,29 +354,31 @@ public class RegistryTest extends EntityTestCase { @Test public void testFailure_tldNeverSet() { - thrown.expect(IllegalArgumentException.class, "No registry TLD specified"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("No registry TLD specified"); new Registry.Builder().build(); } @Test public void testFailure_setTldStr_null() { - thrown.expect(IllegalArgumentException.class, "TLD must not be null"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("TLD must not be null"); new Registry.Builder().setTldStr(null); } @Test public void testFailure_setTldStr_invalidTld() { - thrown.expect( - IllegalArgumentException.class, - "Cannot create registry for TLD that is not a valid, canonical domain name"); + thrown.expect(IllegalArgumentException.class); + thrown + .expectMessage("Cannot create registry for TLD that is not a valid, canonical domain name"); new Registry.Builder().setTldStr(".tld").build(); } @Test public void testFailure_setTldStr_nonCanonicalTld() { - thrown.expect( - IllegalArgumentException.class, - "Cannot create registry for TLD that is not a valid, canonical domain name"); + thrown.expect(IllegalArgumentException.class); + thrown + .expectMessage("Cannot create registry for TLD that is not a valid, canonical domain name"); new Registry.Builder().setTldStr("TLD").build(); } @@ -400,39 +402,44 @@ public class RegistryTest extends EntityTestCase { @Test public void testFailure_pricingEngineIsRequired() { - thrown.expect( - IllegalArgumentException.class, "All registries must have a configured pricing engine"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("All registries must have a configured pricing engine"); new Registry.Builder().setTldStr("invalid").build(); } @Test public void testFailure_negativeRenewBillingCostTransitionValue() { - thrown.expect(IllegalArgumentException.class, "billing cost cannot be negative"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("billing cost cannot be negative"); Registry.get("tld").asBuilder() .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, -42))); } @Test public void testFailure_negativeCreateBillingCost() { - thrown.expect(IllegalArgumentException.class, "createBillingCost cannot be negative"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("createBillingCost cannot be negative"); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, -42)); } @Test public void testFailure_negativeRestoreBillingCost() { - thrown.expect(IllegalArgumentException.class, "restoreBillingCost cannot be negative"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("restoreBillingCost cannot be negative"); Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, -42)); } @Test public void testFailure_negativeServerStatusChangeBillingCost() { - thrown.expect(IllegalArgumentException.class, "billing cost cannot be negative"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("billing cost cannot be negative"); Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(USD, -42)); } @Test public void testFailure_renewBillingCostTransitionValue_wrongCurrency() { - thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("cost must be in the registry's currency"); Registry.get("tld").asBuilder() .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 42))) .build(); @@ -440,19 +447,22 @@ public class RegistryTest extends EntityTestCase { @Test public void testFailure_createBillingCost_wrongCurrency() { - thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("cost must be in the registry's currency"); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(EUR, 42)).build(); } @Test public void testFailure_restoreBillingCost_wrongCurrency() { - thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("cost must be in the registry's currency"); Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(EUR, 42)).build(); } @Test public void testFailure_serverStatusChangeBillingCost_wrongCurrency() { - thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("cost must be in the registry's currency"); Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(EUR, 42)).build(); } @@ -483,8 +493,8 @@ public class RegistryTest extends EntityTestCase { @Test public void testFailure_eapFee_wrongCurrency() { - thrown.expect( - IllegalArgumentException.class, "All EAP fees must be in the registry's currency"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("All EAP fees must be in the registry's currency"); Registry.get("tld").asBuilder() .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .build(); diff --git a/javatests/google/registry/model/registry/label/PremiumListTest.java b/javatests/google/registry/model/registry/label/PremiumListTest.java index f97962209..06b87baed 100644 --- a/javatests/google/registry/model/registry/label/PremiumListTest.java +++ b/javatests/google/registry/model/registry/label/PremiumListTest.java @@ -80,8 +80,8 @@ public class PremiumListTest { @Test public void testParse_cannotIncludeDuplicateLabels() { - thrown.expect( - IllegalStateException.class, + thrown.expect(IllegalStateException.class); + thrown.expectMessage( "List 'tld' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]"); PremiumList.get("tld") .get() diff --git a/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java b/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java index 54dc884b3..30f3c1b03 100644 --- a/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java +++ b/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java @@ -112,7 +112,8 @@ public class PremiumListUtilsTest { public void testGetPremiumPrice_throwsExceptionWhenNonExistentPremiumListConfigured() throws Exception { deletePremiumList(PremiumList.get("tld").get()); - thrown.expect(IllegalStateException.class, "Could not load premium list 'tld'"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Could not load premium list 'tld'"); getPremiumPrice("blah", Registry.get("tld")); } diff --git a/javatests/google/registry/model/registry/label/ReservedListTest.java b/javatests/google/registry/model/registry/label/ReservedListTest.java index d112361ec..af5214edc 100644 --- a/javatests/google/registry/model/registry/label/ReservedListTest.java +++ b/javatests/google/registry/model/registry/label/ReservedListTest.java @@ -269,8 +269,8 @@ public class ReservedListTest { assertThat(matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "foo")).isTrue(); assertThat(matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "bar")).isFalse(); persistReservedList("reserved2", "lol,RESERVED_FOR_ANCHOR_TENANT,bar"); - thrown.expect( - IllegalStateException.class, "There are conflicting auth codes for domain: lol.tld"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("There are conflicting auth codes for domain: lol.tld"); matchesAnchorTenantReservation(InternetDomainName.from("lol.tld"), "bar"); } @@ -468,7 +468,8 @@ public class ReservedListTest { @Test public void testSave_badSyntax() throws Exception { - thrown.expect(IllegalArgumentException.class, "Could not parse line in reserved list"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Could not parse line in reserved list"); persistReservedList("tld", "lol,FULLY_BLOCKED,e,e # yup"); } @@ -480,9 +481,8 @@ public class ReservedListTest { @Test public void testSave_additionalRestrictionWithIncompatibleReservationType() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "Only anchor tenant and nameserver restricted reservations " + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Only anchor tenant and nameserver restricted reservations " + "should have restrictions imposed"); persistResource( Registry.get("tld") @@ -494,7 +494,8 @@ public class ReservedListTest { @Test public void testSave_badNameservers_invalidSyntax() throws Exception { - thrown.expect(IllegalArgumentException.class, "Not a valid domain name: 'ns@.domain.tld'"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Not a valid domain name: 'ns@.domain.tld'"); persistReservedList( "reserved1", "lol,NAMESERVER_RESTRICTED,ns1.domain.tld:ns2.domain.tld", @@ -503,7 +504,8 @@ public class ReservedListTest { @Test public void testSave_badNameservers_tooFewPartsForHostname() throws Exception { - thrown.expect(IllegalArgumentException.class, "domain.tld is not a valid nameserver hostname"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("domain.tld is not a valid nameserver hostname"); persistReservedList( "reserved1", "lol,NAMESERVER_RESTRICTED,ns1.domain.tld:ns2.domain.tld", @@ -512,8 +514,8 @@ public class ReservedListTest { @Test public void testSave_noPasswordWithAnchorTenantReservation() throws Exception { - thrown.expect(IllegalArgumentException.class, - "Anchor tenant reservations must have an auth code configured"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Anchor tenant reservations must have an auth code configured"); persistResource( Registry.get("tld") .asBuilder() @@ -524,8 +526,8 @@ public class ReservedListTest { @Test public void testSave_noNameserversWithNameserverRestrictedReservation() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "Nameserver restricted reservations must have at least one nameserver configured"); persistResource( Registry.get("tld") @@ -538,8 +540,8 @@ public class ReservedListTest { @Test public void testParse_cannotIncludeDuplicateLabels() { ReservedList rl = new ReservedList.Builder().setName("blah").build(); - thrown.expect( - IllegalStateException.class, + thrown.expect(IllegalStateException.class); + thrown.expectMessage( "List 'blah' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]"); rl.parse( ImmutableList.of( diff --git a/javatests/google/registry/model/server/KmsSecretRevisionTest.java b/javatests/google/registry/model/server/KmsSecretRevisionTest.java index 6547e9133..d27505793 100644 --- a/javatests/google/registry/model/server/KmsSecretRevisionTest.java +++ b/javatests/google/registry/model/server/KmsSecretRevisionTest.java @@ -49,7 +49,8 @@ public class KmsSecretRevisionTest { @Test public void test_setEncryptedValue_tooLong_throwsException() { - thrown.expect(IllegalArgumentException.class, "Secret is greater than 67108864 bytes"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Secret is greater than 67108864 bytes"); secretRevision = persistResource( new KmsSecretRevision.Builder() diff --git a/javatests/google/registry/model/server/LockTest.java b/javatests/google/registry/model/server/LockTest.java index 2f843a35f..897e3efe4 100644 --- a/javatests/google/registry/model/server/LockTest.java +++ b/javatests/google/registry/model/server/LockTest.java @@ -138,7 +138,8 @@ public class LockTest { @Test public void testFailure_emptyResourceName() throws Exception { - thrown.expect(IllegalArgumentException.class, "resourceName cannot be null or empty"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("resourceName cannot be null or empty"); Lock.acquire("", "", TWO_MILLIS, requestStatusChecker); } } diff --git a/javatests/google/registry/pricing/PricingEngineProxyTest.java b/javatests/google/registry/pricing/PricingEngineProxyTest.java index 7773954e9..8b73b7cc9 100644 --- a/javatests/google/registry/pricing/PricingEngineProxyTest.java +++ b/javatests/google/registry/pricing/PricingEngineProxyTest.java @@ -148,8 +148,8 @@ public class PricingEngineProxyTest { .asBuilder() .setPremiumPricingEngine("fake") .build()); - thrown.expect( - IllegalStateException.class, "Could not load pricing engine fake for TLD example"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Could not load pricing engine fake for TLD example"); getDomainCreateCost("bad.example", clock.nowUtc(), 1); } } diff --git a/javatests/google/registry/rde/EscrowTaskRunnerTest.java b/javatests/google/registry/rde/EscrowTaskRunnerTest.java index d292ba924..334a8c66b 100644 --- a/javatests/google/registry/rde/EscrowTaskRunnerTest.java +++ b/javatests/google/registry/rde/EscrowTaskRunnerTest.java @@ -99,7 +99,8 @@ public class EscrowTaskRunnerTest { clock.setTo(DateTime.parse("2006-06-06T00:30:00Z")); persistResource( Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-07TZ"), registry)); - thrown.expect(NoContentException.class, "Already completed"); + thrown.expect(NoContentException.class); + thrown.expectMessage("Already completed"); runner.lockRunAndRollForward( task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1)); } @@ -110,7 +111,8 @@ public class EscrowTaskRunnerTest { clock.setTo(DateTime.parse("2006-06-06T00:30:00Z")); persistResource( Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry)); - thrown.expect(ServiceUnavailableException.class, "Lock in use: " + lockName + " for TLD: lol"); + thrown.expect(ServiceUnavailableException.class); + thrown.expectMessage("Lock in use: " + lockName + " for TLD: lol"); runner.lockHandler = new FakeLockHandler(false); runner.lockRunAndRollForward( task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1)); diff --git a/javatests/google/registry/rde/GhostrydeTest.java b/javatests/google/registry/rde/GhostrydeTest.java index 11fa9a6cc..339ab2755 100644 --- a/javatests/google/registry/rde/GhostrydeTest.java +++ b/javatests/google/registry/rde/GhostrydeTest.java @@ -194,7 +194,8 @@ public class GhostrydeTest { korruption(ciphertext, ciphertext.length / 2); ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext); - thrown.expect(IllegalStateException.class, "tampering"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("tampering"); try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) { ByteStreams.copy(decryptor, ByteStreams.nullOutputStream()); } @@ -247,8 +248,8 @@ public class GhostrydeTest { } ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray()); - thrown.expect( - PGPException.class, + thrown.expect(PGPException.class); + thrown.expectMessage( "Message was encrypted for keyid a59c132f3589a1d5 but ours is c9598c84ec70b9fd"); try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) { ByteStreams.copy(decryptor, ByteStreams.nullOutputStream()); diff --git a/javatests/google/registry/rde/RdeReportActionTest.java b/javatests/google/registry/rde/RdeReportActionTest.java index 847777d7f..b66e1ac6a 100644 --- a/javatests/google/registry/rde/RdeReportActionTest.java +++ b/javatests/google/registry/rde/RdeReportActionTest.java @@ -175,7 +175,8 @@ public class RdeReportActionTest { when(httpResponse.getResponseCode()).thenReturn(SC_BAD_REQUEST); when(httpResponse.getContent()).thenReturn(IIRDEA_BAD_XML.read()); when(urlFetchService.fetch(request.capture())).thenReturn(httpResponse); - thrown.expect(InternalServerErrorException.class, "The structure of the report is invalid."); + thrown.expect(InternalServerErrorException.class); + thrown.expectMessage("The structure of the report is invalid."); createAction().runWithLock(loadRdeReportCursor()); } diff --git a/javatests/google/registry/rde/RdeUploadActionTest.java b/javatests/google/registry/rde/RdeUploadActionTest.java index f50769fa5..f0a183979 100644 --- a/javatests/google/registry/rde/RdeUploadActionTest.java +++ b/javatests/google/registry/rde/RdeUploadActionTest.java @@ -312,7 +312,8 @@ public class RdeUploadActionTest { Cursor.create(CursorType.RDE_STAGING, stagingCursor, Registry.get("tld"))); RdeUploadAction action = createAction(uploadUrl); action.lazyJsch = Lazies.of(createThrowingJSchSpy(action.lazyJsch.get(), 3)); - thrown.expect(RuntimeException.class, "The crow flies in square circles."); + thrown.expect(RuntimeException.class); + thrown.expectMessage("The crow flies in square circles."); action.runWithLock(uploadCursor); } @@ -386,7 +387,8 @@ public class RdeUploadActionTest { DateTime uploadCursor = DateTime.parse("2010-10-17TZ"); persistResource( Cursor.create(CursorType.RDE_STAGING, stagingCursor, Registry.get("tld"))); - thrown.expect(ServiceUnavailableException.class, "Waiting for RdeStagingAction to complete"); + thrown.expect(ServiceUnavailableException.class); + thrown.expectMessage("Waiting for RdeStagingAction to complete"); createAction(null).runWithLock(uploadCursor); } diff --git a/javatests/google/registry/rde/imports/RdeHostInputTest.java b/javatests/google/registry/rde/imports/RdeHostInputTest.java index 07912d692..52fdb6bcd 100644 --- a/javatests/google/registry/rde/imports/RdeHostInputTest.java +++ b/javatests/google/registry/rde/imports/RdeHostInputTest.java @@ -64,14 +64,16 @@ public class RdeHostInputTest { /** Number of shards cannot be negative */ @Test public void testNegativeShards_throwsIllegalArgumentException() throws Exception { - thrown.expect(IllegalArgumentException.class, "Number of shards must be greater than zero"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Number of shards must be greater than zero"); getInput(Optional.of(-1)); } /** Number of shards cannot be zero */ @Test public void testZeroShards_throwsIllegalArgumentException() throws Exception { - thrown.expect(IllegalArgumentException.class, "Number of shards must be greater than zero"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Number of shards must be greater than zero"); getInput(Optional.of(0)); } diff --git a/javatests/google/registry/rde/imports/RdeImportUtilsTest.java b/javatests/google/registry/rde/imports/RdeImportUtilsTest.java index 00a89d213..f2062d20b 100644 --- a/javatests/google/registry/rde/imports/RdeImportUtilsTest.java +++ b/javatests/google/registry/rde/imports/RdeImportUtilsTest.java @@ -286,7 +286,8 @@ public class RdeImportUtilsTest extends ShardableTestCase { public void testValidateEscrowFile_tldNotFound() throws Exception { xmlInput = DEPOSIT_BADTLD_XML.openBufferedStream(); when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); - thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Tld 'badtld' not found in the registry"); rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badtld.xml"); } @@ -295,9 +296,8 @@ public class RdeImportUtilsTest extends ShardableTestCase { public void testValidateEscrowFile_tldWrongState() throws Exception { xmlInput = DEPOSIT_GETLD_XML.openBufferedStream(); when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); - thrown.expect( - IllegalArgumentException.class, - "Tld 'getld' is in state GENERAL_AVAILABILITY and cannot be imported"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Tld 'getld' is in state GENERAL_AVAILABILITY and cannot be imported"); rdeImportUtils.validateEscrowFileForImport("invalid-deposit-getld.xml"); } @@ -306,8 +306,8 @@ public class RdeImportUtilsTest extends ShardableTestCase { public void testValidateEscrowFile_badRegistrar() throws Exception { xmlInput = DEPOSIT_BADREGISTRAR_XML.openBufferedStream(); when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); - thrown.expect( - IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar 'RegistrarY' not found in the registry"); rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badregistrar.xml"); } diff --git a/javatests/google/registry/rde/imports/RdeParserTest.java b/javatests/google/registry/rde/imports/RdeParserTest.java index 580446031..5e7419770 100644 --- a/javatests/google/registry/rde/imports/RdeParserTest.java +++ b/javatests/google/registry/rde/imports/RdeParserTest.java @@ -78,9 +78,8 @@ public class RdeParserTest { @Test public void testGetContactNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, - "Not at element urn:ietf:params:xml:ns:rdeContact-1.0:contact"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeContact-1.0:contact"); parser.getContact(); } } @@ -162,9 +161,8 @@ public class RdeParserTest { @Test public void testGetDomainNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, - "Not at element urn:ietf:params:xml:ns:rdeDomain-1.0:domain"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeDomain-1.0:domain"); parser.getDomain(); } } @@ -274,8 +272,8 @@ public class RdeParserTest { @Test public void testGetHostNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, "Not at element urn:ietf:params:xml:ns:rdeHost-1.0:host"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeHost-1.0:host"); parser.getHost(); } } @@ -386,9 +384,8 @@ public class RdeParserTest { @Test public void testGetRegistrarNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, - "Not at element urn:ietf:params:xml:ns:rdeRegistrar-1.0:registrar"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeRegistrar-1.0:registrar"); parser.getRegistrar(); } } @@ -425,8 +422,8 @@ public class RdeParserTest { @Test public void testGetNndnNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, "Not at element urn:ietf:params:xml:ns:rdeNNDN-1.0:NNDN"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeNNDN-1.0:NNDN"); parser.getNndn(); } } @@ -462,9 +459,8 @@ public class RdeParserTest { @Test public void testGetIdnNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, - "Not at element urn:ietf:params:xml:ns:rdeIDN-1.0:idnTableRef"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeIDN-1.0:idnTableRef"); parser.getIdn(); } } @@ -502,9 +498,8 @@ public class RdeParserTest { @Test public void testGetEppParamsNotAtElement_throwsIllegalStateException() throws Exception { try (RdeParser parser = new RdeParser(xml)) { - thrown.expect( - IllegalStateException.class, - "Not at element urn:ietf:params:xml:ns:rdeEppParams-1.0:eppParams"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Not at element urn:ietf:params:xml:ns:rdeEppParams-1.0:eppParams"); parser.getEppParams(); } } diff --git a/javatests/google/registry/rde/imports/XjcToDomainResourceConverterTest.java b/javatests/google/registry/rde/imports/XjcToDomainResourceConverterTest.java index 8a763736e..10c577ce8 100644 --- a/javatests/google/registry/rde/imports/XjcToDomainResourceConverterTest.java +++ b/javatests/google/registry/rde/imports/XjcToDomainResourceConverterTest.java @@ -216,8 +216,8 @@ public class XjcToDomainResourceConverterTest { persistActiveContact("jd1234"); persistActiveContact("sh8013"); final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_pendingRestorePeriod.xml"); - thrown.expect( - IllegalArgumentException.class, "Unsupported grace period status: PENDING_RESTORE"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Unsupported grace period status: PENDING_RESTORE"); convertDomainInTransaction(xjcDomain); } @@ -270,7 +270,8 @@ public class XjcToDomainResourceConverterTest { persistActiveHost("ns1.example.net"); persistActiveHost("ns2.example.net"); final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_host_attrs.xml"); - thrown.expect(IllegalArgumentException.class, "Host attributes are not yet supported"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Host attributes are not yet supported"); convertDomainInTransaction(xjcDomain); } @@ -280,8 +281,8 @@ public class XjcToDomainResourceConverterTest { persistActiveContact("sh8013"); persistActiveHost("ns1.example.net"); final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_host_objs.xml"); - thrown.expect( - IllegalStateException.class, "HostResource not found with name 'ns2.example.net'"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("HostResource not found with name 'ns2.example.net'"); convertDomainInTransaction(xjcDomain); } @@ -289,7 +290,8 @@ public class XjcToDomainResourceConverterTest { public void testConvertDomainResourceRegistrantNotFound() throws Exception { persistActiveContact("sh8013"); final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment.xml"); - thrown.expect(IllegalStateException.class, "Registrant not found: 'jd1234'"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Registrant not found: 'jd1234'"); convertDomainInTransaction(xjcDomain); } @@ -298,8 +300,8 @@ public class XjcToDomainResourceConverterTest { persistActiveContact("jd1234"); persistActiveContact("sh8013"); final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_registrant_missing.xml"); - thrown.expect( - IllegalArgumentException.class, "Registrant is missing for domain 'example1.example'"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrant is missing for domain 'example1.example'"); convertDomainInTransaction(xjcDomain); } @@ -307,7 +309,8 @@ public class XjcToDomainResourceConverterTest { public void testConvertDomainResourceAdminNotFound() throws Exception { persistActiveContact("jd1234"); final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment.xml"); - thrown.expect(IllegalStateException.class, "Contact not found: 'sh8013'"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Contact not found: 'sh8013'"); convertDomainInTransaction(xjcDomain); } diff --git a/javatests/google/registry/reporting/IcannHttpReporterTest.java b/javatests/google/registry/reporting/IcannHttpReporterTest.java index a6edd4a33..3271ee4cf 100644 --- a/javatests/google/registry/reporting/IcannHttpReporterTest.java +++ b/javatests/google/registry/reporting/IcannHttpReporterTest.java @@ -127,8 +127,8 @@ public class IcannHttpReporterTest { @Test public void testFail_invalidFilename_nonSixDigitYearMonth() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "Expected file format: tld-reportType-yyyyMM.csv, got test-transactions-20176.csv instead"); IcannHttpReporter reporter = createReporter(); reporter.send(FAKE_PAYLOAD, "test-transactions-20176.csv"); @@ -136,8 +136,8 @@ public class IcannHttpReporterTest { @Test public void testFail_invalidFilename_notActivityOrTransactions() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "Expected file format: tld-reportType-yyyyMM.csv, got test-invalid-201706.csv instead"); IcannHttpReporter reporter = createReporter(); reporter.send(FAKE_PAYLOAD, "test-invalid-201706.csv"); @@ -145,8 +145,8 @@ public class IcannHttpReporterTest { @Test public void testFail_invalidFilename_invalidTldName() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "Expected file format: tld-reportType-yyyyMM.csv, got n!-n-activity-201706.csv instead"); IcannHttpReporter reporter = createReporter(); reporter.send(FAKE_PAYLOAD, "n!-n-activity-201706.csv"); @@ -154,9 +154,8 @@ public class IcannHttpReporterTest { @Test public void testFail_invalidFilename_tldDoesntExist() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "TLD hello does not exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("TLD hello does not exist"); IcannHttpReporter reporter = createReporter(); reporter.send(FAKE_PAYLOAD, "hello-activity-201706.csv"); } diff --git a/javatests/google/registry/reporting/IcannReportingModuleTest.java b/javatests/google/registry/reporting/IcannReportingModuleTest.java index c110caf66..2f5db3ef8 100644 --- a/javatests/google/registry/reporting/IcannReportingModuleTest.java +++ b/javatests/google/registry/reporting/IcannReportingModuleTest.java @@ -56,8 +56,8 @@ public class IcannReportingModuleTest { @Test public void testInvalidYearMonthParameter_throwsException() { when(req.getParameter("yearMonth")).thenReturn("201705"); - thrown.expect( - BadRequestException.class, "yearMonth must be in yyyy-MM format, got 201705 instead"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("yearMonth must be in yyyy-MM format, got 201705 instead"); IcannReportingModule.provideYearMonthOptional(req); } @@ -88,9 +88,8 @@ public class IcannReportingModuleTest { @Test public void testInvalidSubdir_throwsException() { - thrown.expect( - BadRequestException.class, - "subdir must not start or end with a \"/\", got /whoops instead."); + thrown.expect(BadRequestException.class); + thrown.expectMessage("subdir must not start or end with a \"/\", got /whoops instead."); IcannReportingModule.provideSubdir(Optional.of("/whoops"), new YearMonth(2017, 6)); } diff --git a/javatests/google/registry/request/RequestModuleTest.java b/javatests/google/registry/request/RequestModuleTest.java index 25d373102..86934fe10 100644 --- a/javatests/google/registry/request/RequestModuleTest.java +++ b/javatests/google/registry/request/RequestModuleTest.java @@ -47,13 +47,15 @@ public final class RequestModuleTest { @Test public void testProvideJsonPayload_malformedInput_throws500() throws Exception { - thrown.expect(BadRequestException.class, "Malformed JSON"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Malformed JSON"); provideJsonPayload(MediaType.JSON_UTF_8, "{\"k\":"); } @Test public void testProvideJsonPayload_emptyInput_throws500() throws Exception { - thrown.expect(BadRequestException.class, "Malformed JSON"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Malformed JSON"); provideJsonPayload(MediaType.JSON_UTF_8, ""); } diff --git a/javatests/google/registry/request/RequestParametersTest.java b/javatests/google/registry/request/RequestParametersTest.java index 3921a2444..1da5f0534 100644 --- a/javatests/google/registry/request/RequestParametersTest.java +++ b/javatests/google/registry/request/RequestParametersTest.java @@ -53,14 +53,16 @@ public class RequestParametersTest { @Test public void testExtractRequiredParameter_notPresent_throwsBadRequest() throws Exception { - thrown.expect(BadRequestException.class, "spin"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("spin"); extractRequiredParameter(req, "spin"); } @Test public void testExtractRequiredParameter_empty_throwsBadRequest() throws Exception { when(req.getParameter("spin")).thenReturn(""); - thrown.expect(BadRequestException.class, "spin"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("spin"); extractRequiredParameter(req, "spin"); } @@ -144,7 +146,8 @@ public class RequestParametersTest { @Test public void testExtractEnumValue_nonExistentValue_throwsBadRequest() throws Exception { when(req.getParameter("spin")).thenReturn("sing"); - thrown.expect(BadRequestException.class, "spin"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("spin"); extractEnumParameter(req, Club.class, "spin"); } @@ -163,7 +166,8 @@ public class RequestParametersTest { @Test public void testOptionalExtractEnumValue_nonExistentValue_throwsBadRequest() throws Exception { when(req.getParameter("spin")).thenReturn("sing"); - thrown.expect(BadRequestException.class, "spin"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("spin"); extractOptionalEnumParameter(req, Club.class, "spin"); } @@ -177,7 +181,8 @@ public class RequestParametersTest { @Test public void testExtractRequiredDatetimeParameter_badValue_throwsBadRequest() throws Exception { when(req.getParameter("timeParam")).thenReturn("Tuesday at three o'clock"); - thrown.expect(BadRequestException.class, "timeParam"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("timeParam"); extractRequiredDatetimeParameter(req, "timeParam"); } @@ -191,7 +196,8 @@ public class RequestParametersTest { @Test public void testExtractOptionalDatetimeParameter_badValue_throwsBadRequest() throws Exception { when(req.getParameter("timeParam")).thenReturn("Tuesday at three o'clock"); - thrown.expect(BadRequestException.class, "timeParam"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("timeParam"); extractOptionalDatetimeParameter(req, "timeParam"); } @@ -203,7 +209,8 @@ public class RequestParametersTest { @Test public void testExtractRequiredDatetimeParameter_noValue_throwsBadRequest() throws Exception { - thrown.expect(BadRequestException.class, "timeParam"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("timeParam"); extractRequiredDatetimeParameter(req, "timeParam"); } } diff --git a/javatests/google/registry/request/RouterTest.java b/javatests/google/registry/request/RouterTest.java index 5c4857115..090c29a23 100644 --- a/javatests/google/registry/request/RouterTest.java +++ b/javatests/google/registry/request/RouterTest.java @@ -40,9 +40,8 @@ public final class RouterTest { @Test public void testRoute_noRoutes_throws() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "No routes found for class: google.registry.request.RouterTest.Empty"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("No routes found for class: google.registry.request.RouterTest.Empty"); Router.create(Empty.class); } @@ -145,8 +144,8 @@ public final class RouterTest { @Test public void testRoute_methodsInComponentAreIgnored_throws() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "No routes found for class: google.registry.request.RouterTest.WeirdMethodsComponent"); Router.create(WeirdMethodsComponent.class); } @@ -172,7 +171,8 @@ public final class RouterTest { @Test public void testCreate_twoTasksWithSameMethodAndPath_resultsInError() throws Exception { - thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Multiple entries with same key"); Router.create(DuplicateComponent.class); } } diff --git a/javatests/google/registry/request/auth/RequestAuthenticatorTest.java b/javatests/google/registry/request/auth/RequestAuthenticatorTest.java index 6ec9dd373..ff9be72e5 100644 --- a/javatests/google/registry/request/auth/RequestAuthenticatorTest.java +++ b/javatests/google/registry/request/auth/RequestAuthenticatorTest.java @@ -391,38 +391,42 @@ public class RequestAuthenticatorTest { @Test public void testCheckAuthConfig_NoMethods_failure() throws Exception { - thrown.expect(IllegalArgumentException.class, "Must specify at least one auth method"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Must specify at least one auth method"); RequestAuthenticator.checkAuthConfig(AUTH_NO_METHODS); } @Test public void testCheckAuthConfig_WrongMethodOrdering_failure() throws Exception { - thrown.expect(IllegalArgumentException.class, - "Auth methods must be unique and strictly in order - INTERNAL, API, LEGACY"); + thrown.expect(IllegalArgumentException.class); + thrown + .expectMessage("Auth methods must be unique and strictly in order - INTERNAL, API, LEGACY"); RequestAuthenticator.checkAuthConfig(AUTH_WRONG_METHOD_ORDERING); } @Test public void testCheckAuthConfig_DuplicateMethods_failure() throws Exception { - thrown.expect(IllegalArgumentException.class, - "Auth methods must be unique and strictly in order - INTERNAL, API, LEGACY"); + thrown.expect(IllegalArgumentException.class); + thrown + .expectMessage("Auth methods must be unique and strictly in order - INTERNAL, API, LEGACY"); RequestAuthenticator.checkAuthConfig(AUTH_DUPLICATE_METHODS); } @Test public void testCheckAuthConfig_InternalWithUser_failure() throws Exception { - thrown.expect(IllegalArgumentException.class, - "Actions with INTERNAL auth method may not require USER auth level"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Actions with INTERNAL auth method may not require USER auth level"); RequestAuthenticator.checkAuthConfig(AUTH_INTERNAL_WITH_USER); } @Test public void testCheckAuthConfig_WronglyIgnoringUser_failure() throws Exception { - thrown.expect(IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "Actions with auth methods beyond INTERNAL must not specify the IGNORED user policy"); RequestAuthenticator.checkAuthConfig(AUTH_WRONGLY_IGNORING_USER); diff --git a/javatests/google/registry/storage/drive/DriveConnectionTest.java b/javatests/google/registry/storage/drive/DriveConnectionTest.java index 5ec47b9f0..6713353f4 100644 --- a/javatests/google/registry/storage/drive/DriveConnectionTest.java +++ b/javatests/google/registry/storage/drive/DriveConnectionTest.java @@ -215,8 +215,8 @@ public class DriveConnectionTest { new ChildReference().setId("id2"))) .setNextPageToken(null); when(childrenList.execute()).thenReturn(childList); - thrown.expect(IllegalStateException.class, - "Could not update file 'title' in Drive folder id 'driveFolderId' " + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Could not update file 'title' in Drive folder id 'driveFolderId' " + "because multiple files with that name already exist."); driveConnection.createOrUpdateFile("title", MediaType.WEBM_VIDEO, "driveFolderId", DATA); } diff --git a/javatests/google/registry/testing/ExceptionRule.java b/javatests/google/registry/testing/ExceptionRule.java index 9724d6665..3b48c5a23 100644 --- a/javatests/google/registry/testing/ExceptionRule.java +++ b/javatests/google/registry/testing/ExceptionRule.java @@ -16,7 +16,6 @@ package google.registry.testing; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.nullToEmpty; -import static com.google.common.base.Throwables.getRootCause; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import google.registry.flows.EppException; @@ -37,8 +36,6 @@ public class ExceptionRule implements TestRule { @Nullable String expectedMessage; - private boolean useRootCause; - @Override public Statement apply(final Statement base, Description description) { return new Statement() { @@ -53,10 +50,9 @@ public class ExceptionRule implements TestRule { expectedMessage == null ? "" : (" with message: " + expectedMessage))); } } catch (Throwable e) { - Throwable cause = useRootCause ? getRootCause(e) : e; if (expectedExceptionClass == null - || !(expectedExceptionClass.isAssignableFrom(cause.getClass()) - && nullToEmpty(cause.getMessage()).contains(nullToEmpty(expectedMessage)))) { + || !(expectedExceptionClass.isAssignableFrom(e.getClass()) + && nullToEmpty(e.getMessage()).contains(nullToEmpty(expectedMessage)))) { throw e; // We didn't expect this so pass it through. } if (e instanceof EppException) { @@ -72,19 +68,7 @@ public class ExceptionRule implements TestRule { this.expectedExceptionClass = expectedExceptionClass; } - public void expect(Class expectedExceptionClass, String expectedMessage) { - expect(expectedExceptionClass); + public void expectMessage(String expectedMessage) { this.expectedMessage = expectedMessage; } - - public void expectRootCause(Class expectedExceptionClass) { - expect(expectedExceptionClass); - this.useRootCause = true; - } - - public void expectRootCause( - Class expectedExceptionClass, String expectedMessage) { - expect(expectedExceptionClass, expectedMessage); - this.useRootCause = true; - } } diff --git a/javatests/google/registry/tldconfig/idn/IdnTableTest.java b/javatests/google/registry/tldconfig/idn/IdnTableTest.java index 79c21a731..a23b626c0 100644 --- a/javatests/google/registry/tldconfig/idn/IdnTableTest.java +++ b/javatests/google/registry/tldconfig/idn/IdnTableTest.java @@ -108,7 +108,8 @@ public class IdnTableTest { public void testMissingUrl_throwsNpe() { ImmutableList of = ImmutableList.of( "# Policy: https://love.example/policy.html"); - thrown.expect(NullPointerException.class, "sloth missing '# URL:"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("sloth missing '# URL:"); IdnTable.createFrom("sloth", of, Optional.empty()); } @@ -116,7 +117,8 @@ public class IdnTableTest { public void testMissingPolicy_throwsNpe() { ImmutableList of = ImmutableList.of( "# URL: https://love.example/sloth.txt"); - thrown.expect(NullPointerException.class, "sloth missing '# Policy:"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("sloth missing '# Policy:"); IdnTable.createFrom("sloth", of, Optional.empty()); } } diff --git a/javatests/google/registry/tmch/LordnTaskTest.java b/javatests/google/registry/tmch/LordnTaskTest.java index b22a1a03e..6715574e4 100644 --- a/javatests/google/registry/tmch/LordnTaskTest.java +++ b/javatests/google/registry/tmch/LordnTaskTest.java @@ -166,8 +166,8 @@ public class LordnTaskTest { .setRepoId("9000-EXAMPLE") .setCreationClientId("nonexistentRegistrar") .build(); - thrown.expect( - IllegalStateException.class, "No registrar found for client id: nonexistentRegistrar"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("No registrar found for client id: nonexistentRegistrar"); persistDomainAndEnqueueLordn(domain); } @@ -198,7 +198,8 @@ public class LordnTaskTest { public void test_loadAllTasks_retryLogic_allFailures() throws Exception { Queue queue = mock(Queue.class); when(queue.leaseTasks(any(LeaseOptions.class))).thenThrow(TransientFailureException.class); - thrown.expect(RuntimeException.class, "Error leasing tasks"); + thrown.expect(RuntimeException.class); + thrown.expectMessage("Error leasing tasks"); LordnTask.loadAllTasks(queue, "tld"); } diff --git a/javatests/google/registry/tmch/NordnUploadActionTest.java b/javatests/google/registry/tmch/NordnUploadActionTest.java index c6ed2b3ba..11d5a6d82 100644 --- a/javatests/google/registry/tmch/NordnUploadActionTest.java +++ b/javatests/google/registry/tmch/NordnUploadActionTest.java @@ -202,7 +202,8 @@ public class NordnUploadActionTest { public void testFailure_nullRegistryUser() throws Exception { persistClaimsModeDomain(); persistResource(Registry.get("tld").asBuilder().setLordnUsername(null).build()); - thrown.expect(VerifyException.class, "lordnUsername is not set for tld."); + thrown.expect(VerifyException.class); + thrown.expectMessage("lordnUsername is not set for tld."); action.run(); } diff --git a/javatests/google/registry/tmch/NordnVerifyActionTest.java b/javatests/google/registry/tmch/NordnVerifyActionTest.java index a80e251d5..e6406166f 100644 --- a/javatests/google/registry/tmch/NordnVerifyActionTest.java +++ b/javatests/google/registry/tmch/NordnVerifyActionTest.java @@ -175,7 +175,8 @@ public class NordnVerifyActionTest { @Test public void failureVerifyNotReady() throws Exception { when(httpResponse.getResponseCode()).thenReturn(SC_NO_CONTENT); - thrown.expect(ConflictException.class, "Not ready"); + thrown.expect(ConflictException.class); + thrown.expectMessage("Not ready"); action.run(); } } diff --git a/javatests/google/registry/tmch/SmdrlCsvParserTest.java b/javatests/google/registry/tmch/SmdrlCsvParserTest.java index 610887c2f..d66d78201 100644 --- a/javatests/google/registry/tmch/SmdrlCsvParserTest.java +++ b/javatests/google/registry/tmch/SmdrlCsvParserTest.java @@ -110,7 +110,8 @@ public class SmdrlCsvParserTest { @Test public void testFail_badVersion() throws Exception { - thrown.expect(IllegalArgumentException.class, "version"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("version"); SmdrlCsvParser.parse(ImmutableList.of( "666,2013-11-24T23:30:04.3Z", "smd-id,insertion-datetime", @@ -119,7 +120,8 @@ public class SmdrlCsvParserTest { @Test public void testFail_badHeader() throws Exception { - thrown.expect(IllegalArgumentException.class, "header"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("header"); SmdrlCsvParser.parse(ImmutableList.of( "1,2013-11-24T23:30:04.3Z", "lol,cat", @@ -128,7 +130,8 @@ public class SmdrlCsvParserTest { @Test public void testFail_tooManyColumns() throws Exception { - thrown.expect(IllegalArgumentException.class, "elements"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("elements"); SmdrlCsvParser.parse(ImmutableList.of( "1,2013-11-24T23:30:04.3Z", "smd-id,insertion-datetime", diff --git a/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java b/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java index e464d938d..fbad7121c 100644 --- a/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java +++ b/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java @@ -14,8 +14,10 @@ package google.registry.tmch; +import static com.google.common.truth.Truth.assertThat; import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PILOT; import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PRODUCTION; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.tmch.TmchTestData.loadFile; import static google.registry.util.ResourceUtils.readResourceUtf8; import static google.registry.util.X509Utils.loadCertificate; @@ -65,18 +67,18 @@ public class TmchCertificateAuthorityTest { public void testFailure_prodRootExpired() throws Exception { TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION); clock.setTo(DateTime.parse("2024-01-01T00:00:00Z")); - thrown.expectRootCause( - CertificateExpiredException.class, "NotAfter: Sun Jul 23 23:59:59 UTC 2023"); - tmchCertificateAuthority.getRoot(); + CertificateExpiredException e = + expectThrows(CertificateExpiredException.class, tmchCertificateAuthority::getRoot); + assertThat(e).hasMessageThat().containsMatch("NotAfter: Sun Jul 23 23:59:59 UTC 2023"); } @Test public void testFailure_prodRootNotYetValid() throws Exception { TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION); clock.setTo(DateTime.parse("2000-01-01T00:00:00Z")); - thrown.expectRootCause(CertificateNotYetValidException.class, - "NotBefore: Wed Jul 24 00:00:00 UTC 2013"); - tmchCertificateAuthority.getRoot(); + CertificateNotYetValidException e = + expectThrows(CertificateNotYetValidException.class, tmchCertificateAuthority::getRoot); + assertThat(e).hasMessageThat().containsMatch("NotBefore: Wed Jul 24 00:00:00 UTC 2013"); } @Test @@ -85,8 +87,11 @@ public class TmchCertificateAuthorityTest { TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT); TmchCrl.set( readResourceUtf8(TmchCertificateAuthority.class, "icann-tmch.crl"), "http://cert.crl"); - thrown.expectRootCause(SignatureException.class, "Signature does not match"); - tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE)); + SignatureException e = + expectThrows( + SignatureException.class, + () -> tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE))); + assertThat(e).hasMessageThat().contains("Signature does not match"); } @Test @@ -98,14 +103,18 @@ public class TmchCertificateAuthorityTest { @Test public void testFailure_verifySignatureDoesntMatch() throws Exception { TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION); - thrown.expectRootCause(SignatureException.class, "Signature does not match"); - tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE)); + SignatureException e = + expectThrows( + SignatureException.class, + () -> tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE))); + assertThat(e).hasMessageThat().contains("Signature does not match"); } @Test public void testFailure_verifyRevoked() throws Exception { TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT); - thrown.expect(CertificateRevokedException.class, "revoked, reason: KEY_COMPROMISE"); + thrown.expect(CertificateRevokedException.class); + thrown.expectMessage("revoked, reason: KEY_COMPROMISE"); tmchCertificateAuthority.verify(loadCertificate(REVOKED_TEST_CERTIFICATE)); } } diff --git a/javatests/google/registry/tmch/TmchCrlActionTest.java b/javatests/google/registry/tmch/TmchCrlActionTest.java index 770b5dee8..0428d6d59 100644 --- a/javatests/google/registry/tmch/TmchCrlActionTest.java +++ b/javatests/google/registry/tmch/TmchCrlActionTest.java @@ -15,6 +15,7 @@ package google.registry.tmch; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.ResourceUtils.readResourceBytes; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -60,17 +61,22 @@ public class TmchCrlActionTest extends TmchActionTestCase { // doesn't matter that the wrong CRT would be used to verify it because that check happens after // the age check. TmchCrlAction action = newTmchCrlAction(TmchCaMode.PRODUCTION); - thrown.expectRootCause(CRLException.class, "New CRL is more out of date than our current CRL."); - action.run(); + Exception e = expectThrows(Exception.class, action::run); + assertThat(e).hasCauseThat().isInstanceOf(CRLException.class); + assertThat(e) + .hasCauseThat() + .hasMessageThat() + .contains("New CRL is more out of date than our current CRL."); } @Test public void testFailure_crlNotSignedByRoot() throws Exception { clock.setTo(DateTime.parse("2013-07-24TZ")); - when(httpResponse.getContent()).thenReturn( - readResourceBytes(TmchCertificateAuthority.class, "icann-tmch.crl").read()); - thrown.expectRootCause(SignatureException.class, "Signature does not match."); - newTmchCrlAction(TmchCaMode.PILOT).run(); + when(httpResponse.getContent()) + .thenReturn(readResourceBytes(TmchCertificateAuthority.class, "icann-tmch.crl").read()); + Exception e = expectThrows(Exception.class, newTmchCrlAction(TmchCaMode.PILOT)::run); + assertThat(e).hasCauseThat().isInstanceOf(SignatureException.class); + assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("Signature does not match."); } @Test @@ -78,7 +84,7 @@ public class TmchCrlActionTest extends TmchActionTestCase { clock.setTo(DateTime.parse("1984-01-01TZ")); when(httpResponse.getContent()).thenReturn( readResourceBytes(TmchCertificateAuthority.class, "icann-tmch-pilot.crl").read()); - thrown.expectRootCause(CertificateNotYetValidException.class); - newTmchCrlAction(TmchCaMode.PILOT).run(); + Exception e = expectThrows(Exception.class, newTmchCrlAction(TmchCaMode.PILOT)::run); + assertThat(e).hasCauseThat().isInstanceOf(CertificateNotYetValidException.class); } } diff --git a/javatests/google/registry/tmch/TmchXmlSignatureTest.java b/javatests/google/registry/tmch/TmchXmlSignatureTest.java index 3f80bb17b..431109b49 100644 --- a/javatests/google/registry/tmch/TmchXmlSignatureTest.java +++ b/javatests/google/registry/tmch/TmchXmlSignatureTest.java @@ -14,6 +14,9 @@ package google.registry.tmch; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.tmch.TmchTestData.loadSmd; import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode; @@ -86,24 +89,23 @@ public class TmchXmlSignatureTest { public void testWrongCertificateAuthority() throws Exception { tmchXmlSignature = new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PRODUCTION)); smdData = loadSmd("active/Court-Agent-Arabic-Active.smd"); - thrown.expectRootCause(CertificateSignatureException.class, "Signature does not match"); - tmchXmlSignature.verify(smdData); + CertificateSignatureException e = + expectThrows(CertificateSignatureException.class, () -> tmchXmlSignature.verify(smdData)); + assertThat(e).hasMessageThat().contains("Signature does not match"); } @Test public void testTimeTravelBeforeCertificateWasCreated() throws Exception { smdData = loadSmd("active/Court-Agent-Arabic-Active.smd"); clock.setTo(DateTime.parse("2013-05-01T00:00:00Z")); - thrown.expectRootCause(CertificateNotYetValidException.class); - tmchXmlSignature.verify(smdData); + assertThrows(CertificateNotYetValidException.class, () -> tmchXmlSignature.verify(smdData)); } @Test public void testTimeTravelAfterCertificateHasExpired() throws Exception { smdData = loadSmd("active/Court-Agent-Arabic-Active.smd"); clock.setTo(DateTime.parse("2023-06-01T00:00:00Z")); - thrown.expectRootCause(CertificateExpiredException.class); - tmchXmlSignature.verify(smdData); + assertThrows(CertificateExpiredException.class, () -> tmchXmlSignature.verify(smdData)); } @Test @@ -324,35 +326,40 @@ public class TmchXmlSignatureTest { @Test public void testRevokedTmvTmvrevokedCourtAgentFrenchActive() throws Exception { smdData = loadSmd("revoked/tmv/TMVRevoked-Court-Agent-French-Active.smd"); - thrown.expectRootCause(CertificateRevokedException.class, "KEY_COMPROMISE"); - tmchXmlSignature.verify(smdData); + CertificateRevokedException e = + expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData)); + assertThat(e).hasMessageThat().contains("KEY_COMPROMISE"); } @Test public void testRevokedTmvTmvrevokedTrademarkAgentEnglishActive() throws Exception { smdData = loadSmd("revoked/tmv/TMVRevoked-Trademark-Agent-English-Active.smd"); - thrown.expectRootCause(CertificateRevokedException.class, "KEY_COMPROMISE"); - tmchXmlSignature.verify(smdData); + CertificateRevokedException e = + expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData)); + assertThat(e).hasMessageThat().contains("KEY_COMPROMISE"); } @Test public void testRevokedTmvTmvrevokedTrademarkAgentRussianActive() throws Exception { smdData = loadSmd("revoked/tmv/TMVRevoked-Trademark-Agent-Russian-Active.smd"); - thrown.expectRootCause(CertificateRevokedException.class, "KEY_COMPROMISE"); - tmchXmlSignature.verify(smdData); + CertificateRevokedException e = + expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData)); + assertThat(e).hasMessageThat().contains("KEY_COMPROMISE"); } @Test public void testRevokedTmvTmvrevokedTreatystatuteAgentChineseActive() throws Exception { smdData = loadSmd("revoked/tmv/TMVRevoked-TreatyStatute-Agent-Chinese-Active.smd"); - thrown.expectRootCause(CertificateRevokedException.class, "KEY_COMPROMISE"); - tmchXmlSignature.verify(smdData); + CertificateRevokedException e = + expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData)); + assertThat(e).hasMessageThat().contains("KEY_COMPROMISE"); } @Test public void testRevokedTmvTmvrevokedTreatystatuteAgentEnglishActive() throws Throwable { smdData = loadSmd("revoked/tmv/TMVRevoked-TreatyStatute-Agent-English-Active.smd"); - thrown.expectRootCause(CertificateRevokedException.class, "KEY_COMPROMISE"); - tmchXmlSignature.verify(smdData); + CertificateRevokedException e = + expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData)); + assertThat(e).hasMessageThat().contains("KEY_COMPROMISE"); } } diff --git a/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java b/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java index 069ecab36..92145e789 100644 --- a/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java +++ b/javatests/google/registry/tools/CreateCreditBalanceCommandTest.java @@ -80,7 +80,8 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase any(byte[].class))) .thenReturn( JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}"); - thrown.expect(VerifyException.class, "Server error:"); + thrown.expect(VerifyException.class); + thrown.expectMessage("Server error:"); runCommandForced("-i=" + premiumTermsPath, "-n=foo"); } @Test public void testRun_noInputFileSpecified_throwsException() throws Exception { - thrown.expect(ParameterException.class, "The following option is required"); + thrown.expect(ParameterException.class); + thrown.expectMessage("The following option is required"); runCommand(); } @@ -108,7 +110,8 @@ public class CreatePremiumListCommandTest "tmp_file2", readResourceUtf8( CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv")); - thrown.expect(IllegalArgumentException.class, "Could not parse line in premium list"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Could not parse line in premium list"); runCommandForced("-i=" + premiumTermsPath, "-n=foo"); } } diff --git a/javatests/google/registry/tools/CreateRegistrarCommandTest.java b/javatests/google/registry/tools/CreateRegistrarCommandTest.java index 6d699c3df..c0c39f3ea 100644 --- a/javatests/google/registry/tools/CreateRegistrarCommandTest.java +++ b/javatests/google/registry/tools/CreateRegistrarCommandTest.java @@ -441,7 +441,8 @@ public class CreateRegistrarCommandTest extends CommandTestCase { @Test public void testFailure_invalidAddGracePeriod() throws Exception { - thrown.expect(IllegalArgumentException.class, "Invalid format: \"5m\""); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid format: \"5m\""); runCommandForced( "--add_grace_period=5m", "--roid_suffix=Q9JYB4C", @@ -324,7 +327,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidRedemptionGracePeriod() throws Exception { - thrown.expect(IllegalArgumentException.class, "Invalid format: \"5m\""); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid format: \"5m\""); runCommandForced( "--redemption_grace_period=5m", "--roid_suffix=Q9JYB4C", @@ -334,7 +338,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidPendingDeleteLength() throws Exception { - thrown.expect(IllegalArgumentException.class, "Invalid format: \"5m\""); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid format: \"5m\""); runCommandForced( "--pending_delete_length=5m", "--roid_suffix=Q9JYB4C", @@ -344,7 +349,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidTldState() throws Exception { - thrown.expect(ParameterException.class, "Invalid value for --initial_tld_state parameter"); + thrown.expect(ParameterException.class); + thrown.expectMessage("Invalid value for --initial_tld_state parameter"); runCommandForced( "--initial_tld_state=INVALID_STATE", "--roid_suffix=Q9JYB4C", @@ -355,9 +361,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_bothTldStateFlags() throws Exception { DateTime now = DateTime.now(UTC); - thrown.expect( - IllegalArgumentException.class, - "Don't pass both --initial_tld_state and --tld_state_transitions"); + 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", @@ -369,7 +374,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_negativeInitialRenewBillingCost() throws Exception { - thrown.expect(IllegalArgumentException.class, "Renew billing cost cannot be negative"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Renew billing cost cannot be negative"); runCommandForced( "--initial_renew_billing_cost=USD -42", "--roid_suffix=Q9JYB4C", @@ -379,8 +385,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidEapCurrency() throws Exception { - thrown.expect( - IllegalArgumentException.class, "All EAP fees must be in the registry's currency"); + 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)), @@ -391,26 +397,30 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_noTldName() throws Exception { - thrown.expect(ParameterException.class, "Main parameters are required (\"Names of the TLDs\")"); + thrown.expect(ParameterException.class); + thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")"); runCommandForced(); } @Test public void testFailure_noDnsWriter() throws Exception { - thrown.expect(IllegalArgumentException.class, "At least one DNS writer must be specified"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("At least one DNS writer must be specified"); runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C"); } @Test public void testFailure_alreadyExists() throws Exception { createTld("xn--q9jyb4c"); - thrown.expect(IllegalStateException.class, "TLD 'xn--q9jyb4c' already exists"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("TLD 'xn--q9jyb4c' already exists"); runCommandForced("--roid_suffix=NOTDUPE", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c"); } @Test public void testFailure_tldStartsWithDigit() throws Exception { - thrown.expect(IllegalArgumentException.class, "TLDs cannot begin with a number"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("TLDs cannot begin with a number"); runCommandForced("1foo", "--roid_suffix=1FOO", "--dns_writers=VoidDnsWriter"); } @@ -546,7 +556,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_setPremiumListThatDoesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class, "The premium list 'phonies' doesn't exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("The premium list 'phonies' doesn't exist"); runCommandForced( "--premium_list=phonies", "--roid_suffix=Q9JYB4C", @@ -556,8 +567,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_addLrpPeriod_backwardsInterval() throws Exception { - thrown.expect( - ParameterException.class, + 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", @@ -568,7 +579,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_addLrpPeriod_badInterval() throws Exception { - thrown.expect(ParameterException.class, "--lrp_period=foobar not an ISO-8601 interval"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval"); runCommandForced( "--lrp_period=foobar", "--roid_suffix=Q9JYB4C", @@ -578,9 +590,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_specifiedDnsWriters_dontExist() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "Invalid DNS writer name(s) specified: [Deadbeef, Invalid]"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid DNS writer name(s) specified: [Deadbeef, Invalid]"); runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=Invalid,Deadbeef"); } @@ -606,7 +617,8 @@ public class CreateTldCommandTest extends CommandTestCase { private void runFailureReservedListsTest( String reservedLists, Class errorClass, String errorMsg) throws Exception { - thrown.expect(errorClass, errorMsg); + thrown.expect(errorClass); + thrown.expectMessage(errorMsg); runCommandForced( "--reserved_lists", reservedLists, diff --git a/javatests/google/registry/tools/DeleteCreditCommandTest.java b/javatests/google/registry/tools/DeleteCreditCommandTest.java index 73c95a420..dc4a15b0a 100644 --- a/javatests/google/registry/tools/DeleteCreditCommandTest.java +++ b/javatests/google/registry/tools/DeleteCreditCommandTest.java @@ -111,26 +111,30 @@ public class DeleteCreditCommandTest extends CommandTestCase { @Test public void testFailure_nonexistentClientId() throws Exception { - thrown.expect(IllegalArgumentException.class, "fakeclient"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("fakeclient"); runCommandForced("--client=fakeclient", "fake-xml"); } } diff --git a/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java b/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java index d2463e95d..69e2adcbc 100644 --- a/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java +++ b/javatests/google/registry/tools/GenerateEscrowDepositCommandTest.java @@ -51,51 +51,59 @@ public class GenerateEscrowDepositCommandTest @Test public void testCommand_missingTld() throws Exception { - thrown.expect(ParameterException.class, "The following option is required: -t, --tld"); + 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"); } @Test public void testCommand_emptyTld() throws Exception { - thrown.expect(IllegalArgumentException.class, "Null or empty TLD specified"); + 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"); } @Test public void testCommand_invalidTld() throws Exception { - thrown.expect(IllegalArgumentException.class, "TLDs do not exist: invalid"); + 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"); } @Test public void testCommand_missingWatermark() throws Exception { - thrown.expect(ParameterException.class, "The following option is required: -w, --watermark"); + thrown.expect(ParameterException.class); + thrown.expectMessage("The following option is required: -w, --watermark"); runCommand("--tld=tld", "--mode=full", "-r 42", "-o test"); } @Test public void testCommand_emptyWatermark() throws Exception { - thrown.expect(IllegalArgumentException.class, "Invalid format: \"\""); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid format: \"\""); runCommand("--tld=tld", "--watermark=", "--mode=full", "-r 42", "-o test"); } @Test public void testCommand_missingOutdir() throws Exception { - thrown.expect(ParameterException.class, "The following option is required: -o, --outdir"); + 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"); } @Test public void testCommand_emptyOutdir() throws Exception { - thrown.expect(ParameterException.class, "Output subdirectory must not be empty"); + 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"); } @Test public void testCommand_invalidWatermark() throws Exception { - thrown.expect(ParameterException.class, "Each watermark date must be the start of a day"); + 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", @@ -106,8 +114,8 @@ public class GenerateEscrowDepositCommandTest @Test public void testCommand_invalidMode() throws Exception { - thrown.expect( - ParameterException.class, "Invalid value for -m parameter. Allowed values:[FULL, THIN]"); + thrown.expect(ParameterException.class); + thrown.expectMessage("Invalid value for -m parameter. Allowed values:[FULL, THIN]"); runCommand( "--tld=tld", "--watermark=2017-01-01T00:00:00Z", @@ -118,8 +126,8 @@ public class GenerateEscrowDepositCommandTest @Test public void testCommand_invalidRevision() throws Exception { - thrown.expect( - ParameterException.class, "Revision must be greater than or equal to zero"); + thrown.expect(ParameterException.class); + thrown.expectMessage("Revision must be greater than or equal to zero"); runCommand( "--tld=tld", "--watermark=2017-01-01T00:00:00Z", diff --git a/javatests/google/registry/tools/GetApplicationIdsCommandTest.java b/javatests/google/registry/tools/GetApplicationIdsCommandTest.java index 86943d45d..4adb140bb 100644 --- a/javatests/google/registry/tools/GetApplicationIdsCommandTest.java +++ b/javatests/google/registry/tools/GetApplicationIdsCommandTest.java @@ -60,7 +60,8 @@ public class GetApplicationIdsCommandTest extends CommandTestCase @Test public void testFailure_noArgs() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "Exactly one of either token or assignee must be specified."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Exactly one of either token or assignee must be specified."); runCommand(); } } diff --git a/javatests/google/registry/tools/GetRegistrarCommandTest.java b/javatests/google/registry/tools/GetRegistrarCommandTest.java index 64270f916..67eeecdb3 100644 --- a/javatests/google/registry/tools/GetRegistrarCommandTest.java +++ b/javatests/google/registry/tools/GetRegistrarCommandTest.java @@ -34,7 +34,8 @@ public class GetRegistrarCommandTest extends CommandTestCase(DomainBase(\"4-TLD\"))"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Could not load resource for key: Key(DomainBase(\"4-TLD\"))"); runCommand( "agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw", "agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw"); } @@ -112,9 +111,8 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(ContactResource(\"3-ROID\"))"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Could not load resource for key: Key(ContactResource(\"3-ROID\"))"); runCommand( "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw", "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw"); @@ -157,9 +155,8 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(HostResource(\"3-ROID\"))"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Could not load resource for key: Key(HostResource(\"3-ROID\"))"); runCommand( "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw", "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw"); @@ -189,15 +186,15 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(DomainBase(\"2-TLD\"))"); + thrown.expect(NullPointerException.class); + thrown.expectMessage("Could not load resource for key: Key(DomainBase(\"2-TLD\"))"); runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw"); } @Test public void testFailure_nonsenseKey() throws Exception { - thrown.expect(IllegalArgumentException.class, "Could not parse Reference"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Could not parse Reference"); runCommand("agR0ZXN0chULEgpEb21haW5CYXN"); } diff --git a/javatests/google/registry/tools/ListCursorsCommandTest.java b/javatests/google/registry/tools/ListCursorsCommandTest.java index 25a8b32c7..29d1d09ac 100644 --- a/javatests/google/registry/tools/ListCursorsCommandTest.java +++ b/javatests/google/registry/tools/ListCursorsCommandTest.java @@ -49,7 +49,8 @@ public class ListCursorsCommandTest extends CommandTestCase @Test public void testListCursors_badCursor_throwsIae() throws Exception { - thrown.expect(ParameterException.class, "Invalid value for --type parameter."); + thrown.expect(ParameterException.class); + thrown.expectMessage("Invalid value for --type parameter."); runCommand("--type=love"); } diff --git a/javatests/google/registry/tools/ListDomainsCommandTest.java b/javatests/google/registry/tools/ListDomainsCommandTest.java index 929ae58b9..d06fb1dc1 100644 --- a/javatests/google/registry/tools/ListDomainsCommandTest.java +++ b/javatests/google/registry/tools/ListDomainsCommandTest.java @@ -43,8 +43,8 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase { @Test public void testFailure_missingIpWhitelist() throws Exception { - thrown.expect(ParameterException.class, "option is required: -w, --ip_whitelist"); + thrown.expect(ParameterException.class); + thrown.expectMessage("option is required: -w, --ip_whitelist"); runCommandForced( "--registrar=blobio", "--dns_writers=VoidDnsWriter", @@ -212,7 +213,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_missingRegistrar() throws Exception { - thrown.expect(ParameterException.class, "option is required: -r, --registrar"); + thrown.expect(ParameterException.class); + thrown.expectMessage("option is required: -r, --registrar"); runCommandForced( "--ip_whitelist=1.1.1.1", "--dns_writers=VoidDnsWriter", @@ -221,7 +223,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_missingCertificateFile() throws Exception { - thrown.expect(ParameterException.class, "option is required: -c, --certfile"); + thrown.expect(ParameterException.class); + thrown.expectMessage("option is required: -c, --certfile"); runCommandForced( "--ip_whitelist=1.1.1.1", "--dns_writers=VoidDnsWriter", @@ -230,7 +233,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_missingDnsWriter() throws Exception { - thrown.expect(ParameterException.class, "option is required: --dns_writers"); + thrown.expect(ParameterException.class); + thrown.expectMessage("option is required: --dns_writers"); runCommandForced( "--ip_whitelist=1.1.1.1", "--certfile=" + getCertFilename(), @@ -239,7 +243,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_invalidCert() throws Exception { - thrown.expect(CertificateParsingException.class, "No X509Certificate found"); + thrown.expect(CertificateParsingException.class); + thrown.expectMessage("No X509Certificate found"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobio", @@ -249,7 +254,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_invalidRegistrar() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar name is invalid"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar name is invalid"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=3blobio", @@ -259,8 +265,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_invalidDnsWriter() throws Exception { - thrown.expect( - IllegalArgumentException.class, "Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobio", @@ -270,7 +276,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_registrarTooShort() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar name is invalid"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar name is invalid"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=bl", @@ -280,7 +287,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_registrarTooLong() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar name is invalid"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar name is invalid"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobiotoooolong", @@ -290,7 +298,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_registrarInvalidCharacter() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar name is invalid"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar name is invalid"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blo#bio", @@ -300,7 +309,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_invalidPremiumList() throws Exception { - thrown.expect(IllegalArgumentException.class, "The premium list 'foo' doesn't exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("The premium list 'foo' doesn't exist"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobio", @@ -312,7 +322,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_tldExists() throws Exception { createTld("blobio-sunrise"); - thrown.expect(IllegalStateException.class, "TLD 'blobio-sunrise' already exists"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("TLD 'blobio-sunrise' already exists"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobio", @@ -327,7 +338,8 @@ public class SetupOteCommandTest extends CommandTestCase { .setRegistrarName("blobio-1") .build(); persistResource(registrar); - thrown.expect(IllegalStateException.class, "Registrar blobio-1 already exists"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Registrar blobio-1 already exists"); runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobio", diff --git a/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java b/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java index ffa4ab06e..c7e889575 100644 --- a/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java +++ b/javatests/google/registry/tools/UniformRapidSuspensionCommandTest.java @@ -150,21 +150,24 @@ public class UniformRapidSuspensionCommandTest @Test public void testFailure_locksToPreserveWithoutUndo() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class, "--undo"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("--undo"); runCommandForced("--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited"); } @Test public void testFailure_domainNameRequired() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(ParameterException.class, "--domain_name"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--domain_name"); runCommandForced("--hosts=urs1.example.com,urs2.example.com"); } @Test public void testFailure_extraFieldInDsData() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class, "Incorrect fields on --dsdata JSON"); + 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}"); @@ -173,7 +176,8 @@ public class UniformRapidSuspensionCommandTest @Test public void testFailure_missingFieldInDsData() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class, "Incorrect fields on --dsdata JSON"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Incorrect fields on --dsdata JSON"); runCommandForced( "--domain_name=evil.tld", "--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}"); @@ -182,7 +186,8 @@ public class UniformRapidSuspensionCommandTest @Test public void testFailure_malformedDsData() throws Exception { persistActiveDomain("evil.tld"); - thrown.expect(IllegalArgumentException.class, "Invalid --dsdata JSON"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid --dsdata JSON"); runCommandForced( "--domain_name=evil.tld", "--dsdata=[1,2,3]"); diff --git a/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java b/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java index 58f7a3d12..5df4674ac 100644 --- a/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java +++ b/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java @@ -276,7 +276,8 @@ public class UpdateApplicationStatusCommandTest @Test public void testFailure_historyClientIdDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class, "fakeclient"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("fakeclient"); runCommandForced( "--history_client_id=fakeclient", "--ids=2-Q9JYB4C", "--msg=Ignored", "--status=REJECTED"); } diff --git a/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java b/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java index 3b1033ef0..7516cc4ee 100644 --- a/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java +++ b/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java @@ -14,11 +14,13 @@ package google.registry.tools; +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.newDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; +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.time.DateTimeZone.UTC; @@ -139,13 +141,17 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase + runCommand( + "--id=4-Q9JYB4C", + "--tcn_id=370d0b7c9223372036854775807", + "--expiration_time=2010-08-16T09:00:00.0Z", + "--accepted_time=2009-08-16T09:00:00.0Z")); + assertThat(e).hasCauseThat().isInstanceOf(InvalidChecksumException.class); } @Test diff --git a/javatests/google/registry/tools/UpdateCursorsCommandTest.java b/javatests/google/registry/tools/UpdateCursorsCommandTest.java index 65e4e00e5..00bbf16da 100644 --- a/javatests/google/registry/tools/UpdateCursorsCommandTest.java +++ b/javatests/google/registry/tools/UpdateCursorsCommandTest.java @@ -116,7 +116,8 @@ public class UpdateCursorsCommandTest extends CommandTestCase { @Test public void testFailure_duplicateTldStateTransitions() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "The TLD states are chronologically out of order"); + 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"); @@ -518,8 +520,8 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_duplicateTldStateTransitionTimes() throws Exception { - thrown.expect( - ParameterException.class, "not formatted correctly or has transition times out of order"); + 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"); @@ -527,8 +529,8 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_outOfOrderTldStateTransitionTimes() throws Exception { - thrown.expect( - ParameterException.class, "not formatted correctly or has transition times out of order"); + 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", @@ -538,9 +540,8 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_bothTldStateFlags() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "Don't pass both --set_current_tld_state and --tld_state_transitions"); + 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", @@ -556,8 +557,8 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); - thrown.expect( - IllegalArgumentException.class, "The TLD states are chronologically out of order"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("The TLD states are chronologically out of order"); runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); } @@ -570,9 +571,8 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.plusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); - thrown.expect( - IllegalArgumentException.class, - " when there is a later transition already scheduled"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage(" when there is a later transition already scheduled"); runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); } @@ -585,9 +585,8 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); - thrown.expect( - IllegalArgumentException.class, - "--set_current_tld_state is not safe to use in production."); + 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", @@ -597,15 +596,16 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidRenewBillingCost() throws Exception { - thrown.expect( - ParameterException.class, "not formatted correctly or has transition times out of order"); + 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"); } @Test public void testFailure_negativeRenewBillingCost() throws Exception { - thrown.expect(IllegalArgumentException.class, "Renew billing cost cannot be negative"); + 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"); @@ -613,15 +613,15 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_invalidRenewCostTransitionTime() throws Exception { - thrown.expect( - ParameterException.class, "not formatted correctly or has transition times out of order"); + 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"); } @Test public void testFailure_duplicateRenewCostTransitionTimes() throws Exception { - thrown.expect( - ParameterException.class, "not formatted correctly or has transition times out of order"); + 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"); @@ -629,8 +629,8 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_outOfOrderRenewCostTransitionTimes() throws Exception { - thrown.expect( - ParameterException.class, "not formatted correctly or has transition times out of order"); + 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\"", @@ -640,40 +640,43 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_noTldName() throws Exception { - thrown.expect(ParameterException.class, "Main parameters are required (\"Names of the TLDs\")"); + thrown.expect(ParameterException.class); + thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")"); runCommandForced(); } @Test public void testFailure_oneTldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class, "TLD foo does not exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("TLD foo does not exist"); runCommandForced("foo", "xn--q9jyb4c"); } @Test public void testFailure_duplicateArguments() throws Exception { - thrown.expect(IllegalArgumentException.class, "Duplicate arguments found: 'xn--q9jyb4c'"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Duplicate arguments found: 'xn--q9jyb4c'"); runCommandForced("xn--q9jyb4c", "xn--q9jyb4c"); } @Test public void testFailure_tldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class, "TLD foobarbaz does not exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("TLD foobarbaz does not exist"); runCommandForced("foobarbaz"); } @Test public void testFailure_specifiedDnsWriter_doesntExist() throws Exception { - thrown.expect( - IllegalArgumentException.class, "Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter"); } @Test public void testFailure_setNonExistentReservedLists() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld"); + 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"); } @@ -682,7 +685,8 @@ 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, "xn--q9jyb4c_r1"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("xn--q9jyb4c_r1"); runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"); } @@ -691,13 +695,15 @@ 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, "xn--q9jyb4c_Z"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("xn--q9jyb4c_Z"); runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c"); } @Test public void testFailure_cantAddAndRemoveSameReservedListSimultaneously() throws Exception { - thrown.expect(IllegalArgumentException.class, "xn--q9jyb4c_r1"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("xn--q9jyb4c_r1"); runCommandForced( "--add_reserved_lists=xn--q9jyb4c_r1", "--remove_reserved_lists=xn--q9jyb4c_r1", @@ -710,7 +716,8 @@ public class UpdateTldCommandTest extends CommandTestCase { Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob")) .build()); - thrown.expect(IllegalArgumentException.class, "alice"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("alice"); runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c"); } @@ -720,13 +727,15 @@ public class UpdateTldCommandTest extends CommandTestCase { Registry.get("xn--q9jyb4c").asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("alice")) .build()); - thrown.expect(IllegalArgumentException.class, "bob"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("bob"); runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c"); } @Test public void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() throws Exception { - thrown.expect(IllegalArgumentException.class, "alice"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("alice"); runCommandForced( "--add_allowed_registrants=alice", "--remove_allowed_registrants=alice", @@ -740,7 +749,8 @@ public class UpdateTldCommandTest extends CommandTestCase { .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns1.example.com", "ns2.example.com")) .build()); - thrown.expect(IllegalArgumentException.class, "ns1.example.com"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("ns1.example.com"); runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c"); } @@ -751,13 +761,15 @@ public class UpdateTldCommandTest extends CommandTestCase { .setAllowedFullyQualifiedHostNames( ImmutableSet.of("ns1.example.com")) .build()); - thrown.expect(IllegalArgumentException.class, "ns2.example.com"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("ns2.example.com"); runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c"); } @Test public void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() throws Exception { - thrown.expect(IllegalArgumentException.class, "ns1.example.com"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("ns1.example.com"); runCommandForced( "--add_allowed_nameservers=ns1.example.com", "--remove_allowed_nameservers=ns1.example.com", @@ -882,7 +894,8 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_setPremiumListThatDoesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class, "The premium list 'phonies' doesn't exist"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("The premium list 'phonies' doesn't exist"); runCommandForced("--premium_list=phonies", "xn--q9jyb4c"); } @@ -896,15 +909,16 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_updateLrpPeriod_backwardsInterval() throws Exception { - thrown.expect( - ParameterException.class, + 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"); } @Test public void testFailure_updateLrpPeriod_badInterval() throws Exception { - thrown.expect(ParameterException.class, "--lrp_period=foobar not an ISO-8601 interval"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval"); runCommandForced("--lrp_period=foobar", "xn--q9jyb4c"); } @@ -923,7 +937,8 @@ public class UpdateTldCommandTest extends CommandTestCase { String reservedLists, Class errorClass, String errorMsg) throws Exception { - thrown.expect(errorClass, errorMsg); + thrown.expect(errorClass); + thrown.expectMessage(errorMsg); runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c"); } } diff --git a/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java b/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java index 2fa2c8a0d..eca7d182d 100644 --- a/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java +++ b/javatests/google/registry/tools/ValidateEscrowDepositCommandTest.java @@ -101,7 +101,8 @@ 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, "Syntax error at line 46, column 38: " + 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); } diff --git a/javatests/google/registry/tools/VerifyOteCommandTest.java b/javatests/google/registry/tools/VerifyOteCommandTest.java index b50b6e73a..aac13dd60 100644 --- a/javatests/google/registry/tools/VerifyOteCommandTest.java +++ b/javatests/google/registry/tools/VerifyOteCommandTest.java @@ -66,14 +66,15 @@ public class VerifyOteCommandTest extends CommandTestCase { @Test public void testFailure_registrarDoesntExist() throws Exception { - thrown.expect(IllegalArgumentException.class, "Registrar blobio does not exist."); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Registrar blobio does not exist."); runCommand("blobio"); } @Test public void testFailure_noRegistrarsNoCheckAll() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "Must provide at least one registrar name, or supply --check-all with no names."); runCommand(""); } diff --git a/javatests/google/registry/tools/params/DateTimeParameterTest.java b/javatests/google/registry/tools/params/DateTimeParameterTest.java index 4e599a03b..bf551862a 100644 --- a/javatests/google/registry/tools/params/DateTimeParameterTest.java +++ b/javatests/google/registry/tools/params/DateTimeParameterTest.java @@ -120,7 +120,8 @@ public class DateTimeParameterTest { @Test public void testValidate_sillyString_throwsParameterException() throws Exception { - thrown.expect(ParameterException.class, "--time=foo not an ISO"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--time=foo not an ISO"); instance.validate("--time", "foo"); } diff --git a/javatests/google/registry/tools/params/DurationParameterTest.java b/javatests/google/registry/tools/params/DurationParameterTest.java index 3e898547d..213b02ecd 100644 --- a/javatests/google/registry/tools/params/DurationParameterTest.java +++ b/javatests/google/registry/tools/params/DurationParameterTest.java @@ -93,7 +93,8 @@ public class DurationParameterTest { @Test public void testValidate_sillyString_throws() throws Exception { - thrown.expect(ParameterException.class, "--time=foo not an"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--time=foo not an"); instance.validate("--time", "foo"); } } diff --git a/javatests/google/registry/tools/params/EnumParameterTest.java b/javatests/google/registry/tools/params/EnumParameterTest.java index f035b6a82..2ec1e3858 100644 --- a/javatests/google/registry/tools/params/EnumParameterTest.java +++ b/javatests/google/registry/tools/params/EnumParameterTest.java @@ -41,8 +41,8 @@ public class EnumParameterTest { @Test public void testFailure_badValue() throws Exception { - thrown.expect( - IllegalArgumentException.class, + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( "No enum constant google.registry.model.registry.Registry.TldState.GENERAL_SUNRUSH"); instance.convert("GENERAL_SUNRUSH"); } diff --git a/javatests/google/registry/tools/params/IntervalParameterTest.java b/javatests/google/registry/tools/params/IntervalParameterTest.java index 009bfc966..9902d574f 100644 --- a/javatests/google/registry/tools/params/IntervalParameterTest.java +++ b/javatests/google/registry/tools/params/IntervalParameterTest.java @@ -74,7 +74,8 @@ public class IntervalParameterTest { @Test public void testValidate_sillyString_throws() throws Exception { - thrown.expect(ParameterException.class, "--time=foo not an"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--time=foo not an"); instance.validate("--time", "foo"); } } diff --git a/javatests/google/registry/tools/params/KeyValueMapParameterTest.java b/javatests/google/registry/tools/params/KeyValueMapParameterTest.java index caa8bc189..8a30357fc 100644 --- a/javatests/google/registry/tools/params/KeyValueMapParameterTest.java +++ b/javatests/google/registry/tools/params/KeyValueMapParameterTest.java @@ -98,7 +98,8 @@ public class KeyValueMapParameterTest { @Test public void testFailure_convertCurrencyUnitToString_badType() throws Exception { - thrown.expect(IllegalCurrencyException.class, "XYZ"); + thrown.expect(IllegalCurrencyException.class); + thrown.expectMessage("XYZ"); currencyUnitToStringMap.convert("USD=123abc,XYZ=xyz789"); } diff --git a/javatests/google/registry/tools/params/MoneyParameterTest.java b/javatests/google/registry/tools/params/MoneyParameterTest.java index ef24426b7..28b66d3e8 100644 --- a/javatests/google/registry/tools/params/MoneyParameterTest.java +++ b/javatests/google/registry/tools/params/MoneyParameterTest.java @@ -79,7 +79,8 @@ public class MoneyParameterTest { @Test public void testValidate_sillyString_throws() throws Exception { - thrown.expect(ParameterException.class, "--money=foo not valid"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--money=foo not valid"); instance.validate("--money", "foo"); } diff --git a/javatests/google/registry/tools/params/PathParameterTest.java b/javatests/google/registry/tools/params/PathParameterTest.java index 667f64445..2cd457322 100644 --- a/javatests/google/registry/tools/params/PathParameterTest.java +++ b/javatests/google/registry/tools/params/PathParameterTest.java @@ -101,13 +101,15 @@ public class PathParameterTest { @Test public void testInputFileValidate_missingFile_throws() throws Exception { - thrown.expect(ParameterException.class, "not found"); + thrown.expect(ParameterException.class); + thrown.expectMessage("not found"); inputFile.validate("input", new File(folder.getRoot(), "foo").toString()); } @Test public void testInputFileValidate_directory_throws() throws Exception { - thrown.expect(ParameterException.class, "is a directory"); + thrown.expect(ParameterException.class); + thrown.expectMessage("is a directory"); inputFile.validate("input", folder.getRoot().toString()); } @@ -115,7 +117,8 @@ public class PathParameterTest { public void testInputFileValidate_unreadableFile_throws() throws Exception { Path file = Paths.get(folder.newFile().toString()); Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------")); - thrown.expect(ParameterException.class, "not readable"); + thrown.expect(ParameterException.class); + thrown.expectMessage("not readable"); inputFile.validate("input", file.toString()); } @@ -141,7 +144,8 @@ public class PathParameterTest { @Test public void testOutputFileValidate_directory_throws() throws Exception { - thrown.expect(ParameterException.class, "is a directory"); + thrown.expect(ParameterException.class); + thrown.expectMessage("is a directory"); outputFile.validate("input", folder.getRoot().toString()); } @@ -149,21 +153,24 @@ public class PathParameterTest { public void testOutputFileValidate_notWritable_throws() throws Exception { Path file = Paths.get(folder.newFile().toString()); Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------")); - thrown.expect(ParameterException.class, "not writable"); + thrown.expect(ParameterException.class); + thrown.expectMessage("not writable"); outputFile.validate("input", file.toString()); } @Test public void testOutputFileValidate_parentDirMissing_throws() throws Exception { Path file = Paths.get(folder.getRoot().toString(), "MISSINGNO", "foo.txt"); - thrown.expect(ParameterException.class, "parent dir doesn't exist"); + thrown.expect(ParameterException.class); + thrown.expectMessage("parent dir doesn't exist"); outputFile.validate("input", file.toString()); } @Test public void testOutputFileValidate_parentDirIsFile_throws() throws Exception { Path file = Paths.get(folder.newFile().toString(), "foo.txt"); - thrown.expect(ParameterException.class, "parent is non-directory"); + thrown.expect(ParameterException.class); + thrown.expectMessage("parent is non-directory"); outputFile.validate("input", file.toString()); } } diff --git a/javatests/google/registry/tools/params/YearMonthParameterTest.java b/javatests/google/registry/tools/params/YearMonthParameterTest.java index 8a0787462..1e32a6d96 100644 --- a/javatests/google/registry/tools/params/YearMonthParameterTest.java +++ b/javatests/google/registry/tools/params/YearMonthParameterTest.java @@ -70,7 +70,8 @@ public class YearMonthParameterTest { @Test public void testValidate_sillyString_throwsParameterException() throws Exception { - thrown.expect(ParameterException.class, "--time=foo not a valid"); + thrown.expect(ParameterException.class); + thrown.expectMessage("--time=foo not a valid"); instance.validate("--time", "foo"); } diff --git a/javatests/google/registry/tools/server/CreateGroupsActionTest.java b/javatests/google/registry/tools/server/CreateGroupsActionTest.java index af8cb205a..ad8986c7d 100644 --- a/javatests/google/registry/tools/server/CreateGroupsActionTest.java +++ b/javatests/google/registry/tools/server/CreateGroupsActionTest.java @@ -67,14 +67,15 @@ public class CreateGroupsActionTest { @Test public void test_invalidRequest_missingClientId() throws Exception { - thrown.expect(BadRequestException.class, - "Error creating Google Groups, missing parameter: clientId"); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Error creating Google Groups, missing parameter: clientId"); runAction(null); } @Test public void test_invalidRequest_invalidClientId() throws Exception { - thrown.expect(BadRequestException.class, + thrown.expect(BadRequestException.class); + thrown.expectMessage( "Error creating Google Groups; could not find registrar with id completelyMadeUpClientId"); runAction("completelyMadeUpClientId"); } diff --git a/javatests/google/registry/tools/server/DeleteEntityActionTest.java b/javatests/google/registry/tools/server/DeleteEntityActionTest.java index 838474f4b..4dd6c6738 100644 --- a/javatests/google/registry/tools/server/DeleteEntityActionTest.java +++ b/javatests/google/registry/tools/server/DeleteEntityActionTest.java @@ -89,7 +89,8 @@ public class DeleteEntityActionTest { Entity entity = new Entity("not", "here"); String rawKey = KeyFactory.keyToString(entity.getKey()); action.rawKeys = rawKey; - thrown.expect(BadRequestException.class, "Could not find entity with key " + rawKey); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Could not find entity with key " + rawKey); action.run(); } @@ -101,7 +102,8 @@ public class DeleteEntityActionTest { Entity entity = new Entity("non", "existent"); String rawKey = KeyFactory.keyToString(entity.getKey()); action.rawKeys = String.format("%s,%s", ofyKey, rawKey); - thrown.expect(BadRequestException.class, "Could not find entity with key " + rawKey); + thrown.expect(BadRequestException.class); + thrown.expectMessage("Could not find entity with key " + rawKey); action.run(); } } diff --git a/javatests/google/registry/util/PosixTarHeaderTest.java b/javatests/google/registry/util/PosixTarHeaderTest.java index 4ca75964d..03fdd1859 100644 --- a/javatests/google/registry/util/PosixTarHeaderTest.java +++ b/javatests/google/registry/util/PosixTarHeaderTest.java @@ -206,7 +206,8 @@ public class PosixTarHeaderTest { byte[] bytes = header.getBytes(); bytes[150] = '0'; bytes[151] = '0'; - thrown.expect(IllegalArgumentException.class, "chksum invalid"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("chksum invalid"); PosixTarHeader.from(bytes); } diff --git a/javatests/google/registry/util/RetrierTest.java b/javatests/google/registry/util/RetrierTest.java index 47eb7dff1..d6ef8b9c0 100644 --- a/javatests/google/registry/util/RetrierTest.java +++ b/javatests/google/registry/util/RetrierTest.java @@ -86,13 +86,15 @@ public class RetrierTest { @Test public void testRetryableException() throws Exception { - thrown.expect(CountingException.class, "3"); + thrown.expect(CountingException.class); + thrown.expectMessage("3"); retrier.callWithRetry(new CountingThrower(3), CountingException.class); } @Test public void testUnretryableException() throws Exception { - thrown.expect(CountingException.class, "1"); + thrown.expect(CountingException.class); + thrown.expectMessage("1"); retrier.callWithRetry(new CountingThrower(5), IllegalArgumentException.class); } @@ -104,7 +106,8 @@ public class RetrierTest { @Test public void testRetryFailed_withReporter() throws Exception { - thrown.expect(CountingException.class, "3"); + thrown.expect(CountingException.class); + thrown.expectMessage("3"); TestReporter reporter = new TestReporter(); try { retrier.callWithRetry(new CountingThrower(3), reporter, CountingException.class); diff --git a/javatests/google/registry/util/SerializeUtilsTest.java b/javatests/google/registry/util/SerializeUtilsTest.java index d8b196d15..5aaf424c7 100644 --- a/javatests/google/registry/util/SerializeUtilsTest.java +++ b/javatests/google/registry/util/SerializeUtilsTest.java @@ -55,13 +55,15 @@ public class SerializeUtilsTest { @Test public void testSerialize_objectDoesntImplementSerialize_hasInformativeError() throws Exception { - thrown.expect(IllegalArgumentException.class, "Unable to serialize: LOL_VALUE"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Unable to serialize: LOL_VALUE"); serialize(new Lol()); } @Test public void testDeserialize_badValue_hasInformativeError() throws Exception { - thrown.expect(IllegalArgumentException.class, "Unable to deserialize: objectBytes=FF"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Unable to deserialize: objectBytes=FF"); deserialize(String.class, new byte[] { (byte) 0xff }); } } diff --git a/javatests/google/registry/util/SqlTemplateTest.java b/javatests/google/registry/util/SqlTemplateTest.java index f72eb81c4..9a5622d75 100644 --- a/javatests/google/registry/util/SqlTemplateTest.java +++ b/javatests/google/registry/util/SqlTemplateTest.java @@ -52,7 +52,8 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_substitutionButNoVariables() throws Exception { - thrown.expect(IllegalArgumentException.class, "Not found in template: ONE"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Not found in template: ONE"); SqlTemplate.create("") .put("ONE", "1") .build(); @@ -60,7 +61,8 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_substitutionButMissingVariables() throws Exception { - thrown.expect(IllegalArgumentException.class, "Not found in template: TWO"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Not found in template: TWO"); SqlTemplate.create("%ONE%") .put("ONE", "1") .put("TWO", "2") @@ -69,7 +71,8 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_sameKeyTwice_failsEarly() throws Exception { - thrown.expect(IllegalArgumentException.class, ""); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage(""); SqlTemplate.create("%ONE%") .put("ONE", "1") .put("ONE", "2"); @@ -77,7 +80,8 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_variablesButNotEnoughSubstitutions() throws Exception { - thrown.expect(IllegalArgumentException.class, "%TWO% found in template but no substitution"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("%TWO% found in template but no substitution"); SqlTemplate.create("%ONE% %TWO%") .put("ONE", "1") .build(); @@ -85,7 +89,8 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_mismatchedVariableAndSubstitution() throws Exception { - thrown.expect(IllegalArgumentException.class, "%TWO% found in template but no substitution"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("%TWO% found in template but no substitution"); SqlTemplate.create("%TWO%") .put("TOO", "2") .build(); @@ -93,14 +98,16 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_missingKeyVals_whatsThePoint() throws Exception { - thrown.expect(IllegalArgumentException.class, "%TWO% found in template but no substitution"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("%TWO% found in template but no substitution"); SqlTemplate.create("%TWO%") .build(); } @Test public void testFillSqlTemplate_lowercaseKey_notAllowed() throws Exception { - thrown.expect(IllegalArgumentException.class, "Bad substitution key: test"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Bad substitution key: test"); SqlTemplate.create("%test%") .put("test", "hello world") .build(); @@ -108,21 +115,24 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_substitution_disallowsSingleQuotes() throws Exception { - thrown.expect(IllegalArgumentException.class, "Illegal characters in foo'bar"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Illegal characters in foo'bar"); SqlTemplate.create("The words are '%LOS%' and baz") .put("LOS", "foo'bar"); } @Test public void testFillSqlTemplate_substitution_disallowsDoubleQuotes() throws Exception { - thrown.expect(IllegalArgumentException.class, "Illegal characters in foo\"bar"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Illegal characters in foo\"bar"); SqlTemplate.create("The words are '%LOS%' and baz") .put("LOS", "foo\"bar"); } @Test public void testFillSqlTemplate_quoteMismatch_throwsError() throws Exception { - thrown.expect(IllegalArgumentException.class, "Quote mismatch: \"%LOS%'"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Quote mismatch: \"%LOS%'"); SqlTemplate.create("The words are \"%LOS%' and baz") .put("LOS", "foobar") .build(); @@ -130,7 +140,8 @@ public class SqlTemplateTest { @Test public void testFillSqlTemplate_extendedQuote_throwsError() throws Exception { - thrown.expect(IllegalArgumentException.class, "Quote mismatch: '%LOS%"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Quote mismatch: '%LOS%"); SqlTemplate.create("The words are '%LOS%-lol' and baz") .put("LOS", "roid") .build(); diff --git a/javatests/google/registry/util/TaskEnqueuerTest.java b/javatests/google/registry/util/TaskEnqueuerTest.java index 77a72f6bc..461096ad1 100644 --- a/javatests/google/registry/util/TaskEnqueuerTest.java +++ b/javatests/google/registry/util/TaskEnqueuerTest.java @@ -95,7 +95,8 @@ public final class TaskEnqueuerTest { .thenThrow(new TransientFailureException("two")) .thenThrow(new TransientFailureException("three")) .thenThrow(new TransientFailureException("four")); - thrown.expect(TransientFailureException.class, "three"); + thrown.expect(TransientFailureException.class); + thrown.expectMessage("three"); taskEnqueuer.enqueue(queue, task); } diff --git a/javatests/google/registry/util/TeeOutputStreamTest.java b/javatests/google/registry/util/TeeOutputStreamTest.java index 74c7154ed..2bcf2f3b1 100644 --- a/javatests/google/registry/util/TeeOutputStreamTest.java +++ b/javatests/google/registry/util/TeeOutputStreamTest.java @@ -68,7 +68,8 @@ public class TeeOutputStreamTest { public void testWriteInteger_failsAfterClose() throws Exception { OutputStream tee = new TeeOutputStream(asList(outputA)); tee.close(); - thrown.expect(IllegalStateException.class, "outputstream closed"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("outputstream closed"); tee.write(1); } @@ -76,7 +77,8 @@ public class TeeOutputStreamTest { public void testWriteByteArray_failsAfterClose() throws Exception { OutputStream tee = new TeeOutputStream(asList(outputA)); tee.close(); - thrown.expect(IllegalStateException.class, "outputstream closed"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("outputstream closed"); tee.write("hello".getBytes(UTF_8)); } @@ -84,7 +86,8 @@ public class TeeOutputStreamTest { public void testWriteByteSubarray_failsAfterClose() throws Exception { OutputStream tee = new TeeOutputStream(asList(outputA)); tee.close(); - thrown.expect(IllegalStateException.class, "outputstream closed"); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("outputstream closed"); tee.write("hello".getBytes(UTF_8), 1, 3); } } diff --git a/javatests/google/registry/util/TypeUtilsTest.java b/javatests/google/registry/util/TypeUtilsTest.java index fc3abf445..f8d15a9e8 100644 --- a/javatests/google/registry/util/TypeUtilsTest.java +++ b/javatests/google/registry/util/TypeUtilsTest.java @@ -40,14 +40,15 @@ public class TypeUtilsTest { @Test public void test_getClassFromString_notAssignableFrom() { - thrown.expect(IllegalArgumentException.class, "ArrayList does not implement/extend Integer"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("ArrayList does not implement/extend Integer"); TypeUtils.getClassFromString("java.util.ArrayList", Integer.class); } @Test public void test_getClassFromString_unknownClass() { - thrown.expect( - IllegalArgumentException.class, "Failed to load class com.fake.company.nonexistent.Class"); + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Failed to load class com.fake.company.nonexistent.Class"); TypeUtils.getClassFromString("com.fake.company.nonexistent.Class", Object.class); } } diff --git a/javatests/google/registry/util/UrlFetchUtilsTest.java b/javatests/google/registry/util/UrlFetchUtilsTest.java index cc45567ff..881fb4b95 100644 --- a/javatests/google/registry/util/UrlFetchUtilsTest.java +++ b/javatests/google/registry/util/UrlFetchUtilsTest.java @@ -98,9 +98,8 @@ public class UrlFetchUtilsTest { public void testSetPayloadMultipart_boundaryInPayload() throws Exception { HTTPRequest request = mock(HTTPRequest.class); String payload = "I screamed------------------------------AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHH"; - thrown.expect( - IllegalStateException.class, - "Multipart data contains autogenerated boundary: " + thrown.expect(IllegalStateException.class); + thrown.expectMessage("Multipart data contains autogenerated boundary: " + "------------------------------AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); setPayloadMultipart(request, "lol", "cat", CSV_UTF_8, payload); } diff --git a/javatests/google/registry/xjc/XjcObjectTest.java b/javatests/google/registry/xjc/XjcObjectTest.java index f291c6e0e..cd917f199 100644 --- a/javatests/google/registry/xjc/XjcObjectTest.java +++ b/javatests/google/registry/xjc/XjcObjectTest.java @@ -69,7 +69,8 @@ public class XjcObjectTest { public void testMarshalValidation() throws Exception { XjcRdeDeposit deposit = unmarshalFullDeposit(); deposit.setId(""); - thrown.expect(Throwable.class, "pattern '\\w{1,13}' for type 'depositIdType'"); + thrown.expect(Throwable.class); + thrown.expectMessage("pattern '\\w{1,13}' for type 'depositIdType'"); deposit.marshal(new ByteArrayOutputStream(), UTF_8); } @@ -92,7 +93,8 @@ public class XjcObjectTest { @Test public void testUnmarshalValidation() throws Exception { - thrown.expect(Throwable.class, "pattern '\\w{1,13}' for type 'depositIdType'"); + thrown.expect(Throwable.class); + thrown.expectMessage("pattern '\\w{1,13}' for type 'depositIdType'"); unmarshal(XjcRdeDeposit.class, new ByteArrayInputStream( RDE_DEPOSIT_FULL.replaceFirst("id=\"[^\"]+\"", "id=\"\"").getBytes(UTF_8))); } diff --git a/javatests/google/registry/xjc/XmlTestdataTest.java b/javatests/google/registry/xjc/XmlTestdataTest.java index 96f8d0817..7c521872f 100644 --- a/javatests/google/registry/xjc/XmlTestdataTest.java +++ b/javatests/google/registry/xjc/XmlTestdataTest.java @@ -151,7 +151,8 @@ public class XmlTestdataTest { @Theory public void testInvalid(Evil v) throws Exception { - thrown.expect(Throwable.class, v.error); + thrown.expect(Throwable.class); + thrown.expectMessage(v.error); unmarshal(XjcObject.class, v.xmlStream); } }