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

@ -21,7 +21,6 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDomainAndEnqueueLordn;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
@ -165,7 +164,7 @@ public class LordnTaskTest {
.setCreationClientId("nonexistentRegistrar")
.build();
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> persistDomainAndEnqueueLordn(domain));
assertThrows(IllegalStateException.class, () -> persistDomainAndEnqueueLordn(domain));
assertThat(thrown)
.hasMessageThat()
.contains("No registrar found for client id: nonexistentRegistrar");
@ -204,7 +203,7 @@ public class LordnTaskTest {
Queue queue = mock(Queue.class);
when(queue.leaseTasks(any(LeaseOptions.class))).thenThrow(TransientFailureException.class);
RuntimeException thrown =
expectThrows(RuntimeException.class, () -> LordnTask.loadAllTasks(queue, "tld"));
assertThrows(RuntimeException.class, () -> LordnTask.loadAllTasks(queue, "tld"));
assertThat(thrown).hasMessageThat().contains("Error leasing tasks");
}

View file

@ -26,7 +26,6 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistDomainAndEnqueueLordn;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static google.registry.util.UrlFetchUtils.getHeaderFirst;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -199,7 +198,7 @@ public class NordnUploadActionTest {
public void testFailure_nullRegistryUser() throws Exception {
persistClaimsModeDomain();
persistResource(Registry.get("tld").asBuilder().setLordnUsername(null).build());
VerifyException thrown = expectThrows(VerifyException.class, action::run);
VerifyException thrown = assertThrows(VerifyException.class, action::run);
assertThat(thrown).hasMessageThat().contains("lordnUsername is not set for tld.");
}

View file

@ -20,7 +20,6 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.UrlFetchUtils.getHeaderFirst;
import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
@ -171,7 +170,7 @@ public class NordnVerifyActionTest {
@Test
public void failureVerifyNotReady() throws Exception {
when(httpResponse.getResponseCode()).thenReturn(SC_NO_CONTENT);
ConflictException thrown = expectThrows(ConflictException.class, action::run);
ConflictException thrown = assertThrows(ConflictException.class, action::run);
assertThat(thrown).hasMessageThat().contains("Not ready");
}
}

View file

@ -15,7 +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.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.joda.time.Duration.millis;
import static org.joda.time.Duration.standardDays;
@ -107,7 +107,7 @@ public class SmdrlCsvParserTest {
@Test
public void testFail_badVersion() throws Exception {
IllegalArgumentException thrown =
expectThrows(
assertThrows(
IllegalArgumentException.class,
() ->
SmdrlCsvParser.parse(
@ -121,7 +121,7 @@ public class SmdrlCsvParserTest {
@Test
public void testFail_badHeader() throws Exception {
IllegalArgumentException thrown =
expectThrows(
assertThrows(
IllegalArgumentException.class,
() ->
SmdrlCsvParser.parse(
@ -135,7 +135,7 @@ public class SmdrlCsvParserTest {
@Test
public void testFail_tooManyColumns() throws Exception {
IllegalArgumentException thrown =
expectThrows(
assertThrows(
IllegalArgumentException.class,
() ->
SmdrlCsvParser.parse(

View file

@ -17,7 +17,7 @@ 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.testing.JUnitBackports.assertThrows;
import static google.registry.tmch.TmchTestData.loadFile;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static google.registry.util.X509Utils.loadCertificate;
@ -63,7 +63,7 @@ public class TmchCertificateAuthorityTest {
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION);
clock.setTo(DateTime.parse("2024-01-01T00:00:00Z"));
CertificateExpiredException e =
expectThrows(CertificateExpiredException.class, tmchCertificateAuthority::getRoot);
assertThrows(CertificateExpiredException.class, tmchCertificateAuthority::getRoot);
assertThat(e).hasMessageThat().containsMatch("NotAfter: Sun Jul 23 23:59:59 UTC 2023");
}
@ -72,7 +72,7 @@ public class TmchCertificateAuthorityTest {
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION);
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
CertificateNotYetValidException e =
expectThrows(CertificateNotYetValidException.class, tmchCertificateAuthority::getRoot);
assertThrows(CertificateNotYetValidException.class, tmchCertificateAuthority::getRoot);
assertThat(e).hasMessageThat().containsMatch("NotBefore: Wed Jul 24 00:00:00 UTC 2013");
}
@ -83,7 +83,7 @@ public class TmchCertificateAuthorityTest {
TmchCrl.set(
readResourceUtf8(TmchCertificateAuthority.class, "icann-tmch.crl"), "http://cert.crl");
SignatureException e =
expectThrows(
assertThrows(
SignatureException.class,
() -> tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE)));
assertThat(e).hasMessageThat().contains("Signature does not match");
@ -99,7 +99,7 @@ public class TmchCertificateAuthorityTest {
public void testFailure_verifySignatureDoesntMatch() throws Exception {
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PRODUCTION);
SignatureException e =
expectThrows(
assertThrows(
SignatureException.class,
() -> tmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE)));
assertThat(e).hasMessageThat().contains("Signature does not match");
@ -109,7 +109,7 @@ public class TmchCertificateAuthorityTest {
public void testFailure_verifyRevoked() throws Exception {
TmchCertificateAuthority tmchCertificateAuthority = new TmchCertificateAuthority(PILOT);
CertificateRevokedException thrown =
expectThrows(
assertThrows(
CertificateRevokedException.class,
() -> tmchCertificateAuthority.verify(loadCertificate(REVOKED_TEST_CERTIFICATE)));
assertThat(thrown).hasMessageThat().contains("revoked, reason: KEY_COMPROMISE");

View file

@ -15,7 +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.testing.JUnitBackports.assertThrows;
import static google.registry.util.ResourceUtils.readResourceBytes;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -61,7 +61,7 @@ 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);
Exception e = expectThrows(Exception.class, action::run);
Exception e = assertThrows(Exception.class, action::run);
assertThat(e).hasCauseThat().isInstanceOf(CRLException.class);
assertThat(e)
.hasCauseThat()
@ -74,7 +74,7 @@ public class TmchCrlActionTest extends TmchActionTestCase {
clock.setTo(DateTime.parse("2013-07-24TZ"));
when(httpResponse.getContent())
.thenReturn(readResourceBytes(TmchCertificateAuthority.class, "icann-tmch.crl").read());
Exception e = expectThrows(Exception.class, newTmchCrlAction(TmchCaMode.PILOT)::run);
Exception e = assertThrows(Exception.class, newTmchCrlAction(TmchCaMode.PILOT)::run);
assertThat(e).hasCauseThat().isInstanceOf(SignatureException.class);
assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("Signature does not match.");
}
@ -84,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());
Exception e = expectThrows(Exception.class, newTmchCrlAction(TmchCaMode.PILOT)::run);
Exception e = assertThrows(Exception.class, newTmchCrlAction(TmchCaMode.PILOT)::run);
assertThat(e).hasCauseThat().isInstanceOf(CertificateNotYetValidException.class);
}
}

View file

@ -16,7 +16,6 @@ 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,7 +85,7 @@ public class TmchXmlSignatureTest {
tmchXmlSignature = new TmchXmlSignature(new TmchCertificateAuthority(TmchCaMode.PRODUCTION));
smdData = loadSmd("active/Court-Agent-Arabic-Active.smd");
CertificateSignatureException e =
expectThrows(CertificateSignatureException.class, () -> tmchXmlSignature.verify(smdData));
assertThrows(CertificateSignatureException.class, () -> tmchXmlSignature.verify(smdData));
assertThat(e).hasMessageThat().contains("Signature does not match");
}
@ -318,7 +317,7 @@ public class TmchXmlSignatureTest {
public void testRevokedTmvTmvrevokedCourtAgentFrenchActive() throws Exception {
smdData = loadSmd("revoked/tmv/TMVRevoked-Court-Agent-French-Active.smd");
CertificateRevokedException e =
expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThat(e).hasMessageThat().contains("KEY_COMPROMISE");
}
@ -326,7 +325,7 @@ public class TmchXmlSignatureTest {
public void testRevokedTmvTmvrevokedTrademarkAgentEnglishActive() throws Exception {
smdData = loadSmd("revoked/tmv/TMVRevoked-Trademark-Agent-English-Active.smd");
CertificateRevokedException e =
expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThat(e).hasMessageThat().contains("KEY_COMPROMISE");
}
@ -334,7 +333,7 @@ public class TmchXmlSignatureTest {
public void testRevokedTmvTmvrevokedTrademarkAgentRussianActive() throws Exception {
smdData = loadSmd("revoked/tmv/TMVRevoked-Trademark-Agent-Russian-Active.smd");
CertificateRevokedException e =
expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThat(e).hasMessageThat().contains("KEY_COMPROMISE");
}
@ -342,7 +341,7 @@ public class TmchXmlSignatureTest {
public void testRevokedTmvTmvrevokedTreatystatuteAgentChineseActive() throws Exception {
smdData = loadSmd("revoked/tmv/TMVRevoked-TreatyStatute-Agent-Chinese-Active.smd");
CertificateRevokedException e =
expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThat(e).hasMessageThat().contains("KEY_COMPROMISE");
}
@ -350,7 +349,7 @@ public class TmchXmlSignatureTest {
public void testRevokedTmvTmvrevokedTreatystatuteAgentEnglishActive() throws Throwable {
smdData = loadSmd("revoked/tmv/TMVRevoked-TreatyStatute-Agent-English-Active.smd");
CertificateRevokedException e =
expectThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThrows(CertificateRevokedException.class, () -> tmchXmlSignature.verify(smdData));
assertThat(e).hasMessageThat().contains("KEY_COMPROMISE");
}
}