Merge JUnitBackport's expectThrows into assertThrows

More information: https://github.com/junit-team/junit5/issues/531

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187034408
This commit is contained in:
cushon 2018-02-26 09:38:17 -08:00 committed by jianglai
parent f96a0b7da9
commit 606b470cd0
180 changed files with 1325 additions and 1381 deletions

View file

@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardSeconds;
import static org.mockito.Mockito.mock;
@ -97,7 +97,7 @@ public class EscrowTaskRunnerTest {
persistResource(
Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-07TZ"), registry));
NoContentException thrown =
expectThrows(
assertThrows(
NoContentException.class,
() ->
runner.lockRunAndRollForward(
@ -112,7 +112,7 @@ public class EscrowTaskRunnerTest {
persistResource(
Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry));
ServiceUnavailableException thrown =
expectThrows(
assertThrows(
ServiceUnavailableException.class,
() -> {
runner.lockHandler = new FakeLockHandler(false);

View file

@ -18,7 +18,6 @@ import static com.google.common.base.Strings.repeat;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.keyring.api.PgpHelper.KeyRequirement.ENCRYPT;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
@ -193,7 +192,7 @@ public class GhostrydeTest {
ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext);
IllegalStateException thrown =
expectThrows(
assertThrows(
IllegalStateException.class,
() -> {
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
@ -254,7 +253,7 @@ public class GhostrydeTest {
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
PGPException thrown =
expectThrows(
assertThrows(
PGPException.class,
() -> {
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {

View file

@ -22,7 +22,6 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.GcsTestingUtils.writeGcsFile;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.joda.time.DateTimeZone.UTC;
@ -173,7 +172,7 @@ public class RdeReportActionTest {
when(httpResponse.getContent()).thenReturn(IIRDEA_BAD_XML.read());
when(urlFetchService.fetch(request.capture())).thenReturn(httpResponse);
InternalServerErrorException thrown =
expectThrows(
assertThrows(
InternalServerErrorException.class,
() -> createAction().runWithLock(loadRdeReportCursor()));
assertThat(thrown).hasMessageThat().contains("The structure of the report is invalid.");

View file

@ -24,7 +24,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
import static google.registry.testing.GcsTestingUtils.readGcsFile;
import static google.registry.testing.GcsTestingUtils.writeGcsFile;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.SystemInfo.hasCommand;
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -309,7 +309,7 @@ public class RdeUploadActionTest {
RdeUploadAction action = createAction(uploadUrl);
action.lazyJsch = Lazies.of(createThrowingJSchSpy(action.lazyJsch.get(), 3));
RuntimeException thrown =
expectThrows(RuntimeException.class, () -> action.runWithLock(uploadCursor));
assertThrows(RuntimeException.class, () -> action.runWithLock(uploadCursor));
assertThat(thrown).hasMessageThat().contains("The crow flies in square circles.");
}
@ -384,7 +384,7 @@ public class RdeUploadActionTest {
persistResource(
Cursor.create(CursorType.RDE_STAGING, stagingCursor, Registry.get("tld")));
ServiceUnavailableException thrown =
expectThrows(
assertThrows(
ServiceUnavailableException.class, () -> createAction(null).runWithLock(uploadCursor));
assertThat(thrown).hasMessageThat().contains("Waiting for RdeStagingAction to complete");
}

View file

@ -16,7 +16,7 @@ package google.registry.rde.imports;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.rde.imports.RdeImportsTestData.loadBytes;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.appengine.tools.cloudstorage.GcsService;
@ -61,7 +61,7 @@ public class RdeHostInputTest {
@Test
public void testNegativeShards_throwsIllegalArgumentException() throws Exception {
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> getInput(Optional.of(-1)));
assertThrows(IllegalArgumentException.class, () -> getInput(Optional.of(-1)));
assertThat(thrown).hasMessageThat().contains("Number of shards must be greater than zero");
}
@ -69,7 +69,7 @@ public class RdeHostInputTest {
@Test
public void testZeroShards_throwsIllegalArgumentException() throws Exception {
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> getInput(Optional.of(0)));
assertThrows(IllegalArgumentException.class, () -> getInput(Optional.of(0)));
assertThat(thrown).hasMessageThat().contains("Number of shards must be greater than zero");
}

View file

@ -22,7 +22,6 @@ import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
@ -273,7 +272,7 @@ public class RdeImportUtilsTest extends ShardableTestCase {
xmlInput = DEPOSIT_BADTLD_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
Exception e =
expectThrows(
assertThrows(
IllegalArgumentException.class,
() -> rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badtld.xml"));
assertThat(e).hasMessageThat().isEqualTo("TLD 'badtld' not found in the registry");
@ -285,7 +284,7 @@ public class RdeImportUtilsTest extends ShardableTestCase {
xmlInput = DEPOSIT_GETLD_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
Exception e =
expectThrows(
assertThrows(
IllegalArgumentException.class,
() -> rdeImportUtils.validateEscrowFileForImport("invalid-deposit-getld.xml"));
assertThat(e)
@ -299,7 +298,7 @@ public class RdeImportUtilsTest extends ShardableTestCase {
xmlInput = DEPOSIT_BADREGISTRAR_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
Exception e =
expectThrows(
assertThrows(
IllegalArgumentException.class,
() -> rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badregistrar.xml"));
assertThat(e).hasMessageThat().isEqualTo("Registrar 'RegistrarY' not found in the registry");

View file

@ -16,7 +16,7 @@ package google.registry.rde.imports;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.rde.imports.RdeImportsTestData.loadBytes;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.google.common.io.ByteSource;
import google.registry.rde.imports.RdeParser.RdeHeader;
@ -74,7 +74,7 @@ public class RdeParserTest {
@Test
public void testGetContactNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getContact);
IllegalStateException thrown = assertThrows(IllegalStateException.class, parser::getContact);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeContact-1.0:contact");
@ -158,7 +158,7 @@ public class RdeParserTest {
@Test
public void testGetDomainNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getDomain);
IllegalStateException thrown = assertThrows(IllegalStateException.class, parser::getDomain);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeDomain-1.0:domain");
@ -270,7 +270,7 @@ public class RdeParserTest {
@Test
public void testGetHostNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getHost);
IllegalStateException thrown = assertThrows(IllegalStateException.class, parser::getHost);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeHost-1.0:host");
@ -384,7 +384,7 @@ public class RdeParserTest {
public void testGetRegistrarNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown =
expectThrows(IllegalStateException.class, parser::getRegistrar);
assertThrows(IllegalStateException.class, parser::getRegistrar);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeRegistrar-1.0:registrar");
@ -423,7 +423,7 @@ public class RdeParserTest {
@Test
public void testGetNndnNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getNndn);
IllegalStateException thrown = assertThrows(IllegalStateException.class, parser::getNndn);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeNNDN-1.0:NNDN");
@ -461,7 +461,7 @@ public class RdeParserTest {
@Test
public void testGetIdnNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getIdn);
IllegalStateException thrown = assertThrows(IllegalStateException.class, parser::getIdn);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeIDN-1.0:idnTableRef");
@ -502,7 +502,7 @@ public class RdeParserTest {
public void testGetEppParamsNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown =
expectThrows(IllegalStateException.class, parser::getEppParams);
assertThrows(IllegalStateException.class, parser::getEppParams);
assertThat(thrown)
.hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeEppParams-1.0:eppParams");

View file

@ -26,7 +26,7 @@ import static google.registry.testing.DatastoreHelper.getHistoryEntries;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static java.util.Arrays.asList;
@ -214,7 +214,7 @@ public class XjcToDomainResourceConverterTest {
persistActiveContact("sh8013");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_pendingRestorePeriod.xml");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> convertDomainInTransaction(xjcDomain));
assertThrows(IllegalArgumentException.class, () -> convertDomainInTransaction(xjcDomain));
assertThat(thrown)
.hasMessageThat()
.contains("Unsupported grace period status: PENDING_RESTORE");
@ -270,7 +270,7 @@ public class XjcToDomainResourceConverterTest {
persistActiveHost("ns2.example.net");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_host_attrs.xml");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> convertDomainInTransaction(xjcDomain));
assertThrows(IllegalArgumentException.class, () -> convertDomainInTransaction(xjcDomain));
assertThat(thrown).hasMessageThat().contains("Host attributes are not yet supported");
}
@ -281,7 +281,7 @@ public class XjcToDomainResourceConverterTest {
persistActiveHost("ns1.example.net");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_host_objs.xml");
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> convertDomainInTransaction(xjcDomain));
assertThrows(IllegalStateException.class, () -> convertDomainInTransaction(xjcDomain));
assertThat(thrown)
.hasMessageThat()
.contains("HostResource not found with name 'ns2.example.net'");
@ -292,7 +292,7 @@ public class XjcToDomainResourceConverterTest {
persistActiveContact("sh8013");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment.xml");
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> convertDomainInTransaction(xjcDomain));
assertThrows(IllegalStateException.class, () -> convertDomainInTransaction(xjcDomain));
assertThat(thrown).hasMessageThat().contains("Registrant not found: 'jd1234'");
}
@ -302,7 +302,7 @@ public class XjcToDomainResourceConverterTest {
persistActiveContact("sh8013");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment_registrant_missing.xml");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> convertDomainInTransaction(xjcDomain));
assertThrows(IllegalArgumentException.class, () -> convertDomainInTransaction(xjcDomain));
assertThat(thrown)
.hasMessageThat()
.contains("Registrant is missing for domain 'example1.example'");
@ -313,7 +313,7 @@ public class XjcToDomainResourceConverterTest {
persistActiveContact("jd1234");
final XjcRdeDomain xjcDomain = loadDomainFromRdeXml("domain_fragment.xml");
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> convertDomainInTransaction(xjcDomain));
assertThrows(IllegalStateException.class, () -> convertDomainInTransaction(xjcDomain));
assertThat(thrown).hasMessageThat().contains("Contact not found: 'sh8013'");
}