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

@ -17,7 +17,7 @@ package google.registry.proxy;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.proxy.ProxyConfig.Environment.TEST;
import static google.registry.proxy.ProxyConfig.getProxyConfig;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.junit.Assert.fail;
import com.beust.jcommander.ParameterException;
@ -94,7 +94,7 @@ public class ProxyModuleTest {
@Test
public void testFailure_parseArgs_wrongEnvironment() {
ParameterException e =
expectThrows(
assertThrows(
ParameterException.class,
() -> {
String[] args = {"--env", "beta"};

View file

@ -22,7 +22,7 @@ import static google.registry.proxy.TestUtils.makeHttpPostRequest;
import static google.registry.proxy.TestUtils.makeHttpResponse;
import static google.registry.proxy.handler.EppServiceHandler.CLIENT_CERTIFICATE_HASH_KEY;
import static google.registry.proxy.handler.RelayHandler.RELAY_CHANNEL_KEY;
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.verifyNoMoreInteractions;
@ -96,7 +96,7 @@ public class BackendMetricsHandlerTest {
public void testFailure_outbound_wrongType() {
Object request = new Object();
IllegalArgumentException e =
expectThrows(IllegalArgumentException.class, () -> channel.writeOutbound(request));
assertThrows(IllegalArgumentException.class, () -> channel.writeOutbound(request));
assertThat(e).hasMessageThat().isEqualTo("Outgoing request must be FullHttpRequest.");
}
@ -104,7 +104,7 @@ public class BackendMetricsHandlerTest {
public void testFailure_inbound_wrongType() {
Object response = new Object();
IllegalArgumentException e =
expectThrows(IllegalArgumentException.class, () -> channel.writeInbound(response));
assertThrows(IllegalArgumentException.class, () -> channel.writeInbound(response));
assertThat(e).hasMessageThat().isEqualTo("Incoming response must be FullHttpResponse.");
}
@ -159,7 +159,7 @@ public class BackendMetricsHandlerTest {
public void testFailure_responseBeforeRequest() {
FullHttpResponse response = makeHttpResponse("phantom response", HttpResponseStatus.OK);
IllegalStateException e =
expectThrows(IllegalStateException.class, () -> channel.writeInbound(response));
assertThrows(IllegalStateException.class, () -> channel.writeInbound(response));
assertThat(e).hasMessageThat().isEqualTo("Response received before request is sent.");
}

View file

@ -17,7 +17,7 @@ package google.registry.proxy.handler;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.proxy.Protocol.PROTOCOL_KEY;
import static google.registry.proxy.handler.EppServiceHandler.CLIENT_CERTIFICATE_HASH_KEY;
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.verifyNoMoreInteractions;
@ -108,7 +108,7 @@ public class EppQuotaHandlerTest {
when(quotaManager.acquireQuota(QuotaRequest.create(clientCertHash)))
.thenReturn(QuotaResponse.create(false, clientCertHash, now));
OverQuotaException e =
expectThrows(OverQuotaException.class, () -> channel.writeInbound(message));
assertThrows(OverQuotaException.class, () -> channel.writeInbound(message));
assertThat(e).hasMessageThat().contains(clientCertHash);
verify(metrics).registerQuotaRejection("epp", clientCertHash);
verifyNoMoreInteractions(metrics);
@ -136,7 +136,7 @@ public class EppQuotaHandlerTest {
// Blocks the second user.
OverQuotaException e =
expectThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThat(e).hasMessageThat().contains(otherClientCertHash);
verify(metrics).registerQuotaRejection("epp", otherClientCertHash);
verifyNoMoreInteractions(metrics);
@ -162,7 +162,7 @@ public class EppQuotaHandlerTest {
// Blocks the second channel.
OverQuotaException e =
expectThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThat(e).hasMessageThat().contains(clientCertHash);
verify(metrics).registerQuotaRejection("epp", clientCertHash);
verifyNoMoreInteractions(metrics);

View file

@ -17,7 +17,7 @@ package google.registry.proxy.handler;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.proxy.Protocol.PROTOCOL_KEY;
import static google.registry.proxy.handler.ProxyProtocolHandler.REMOTE_ADDRESS_KEY;
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.verifyNoMoreInteractions;
@ -103,7 +103,7 @@ public class WhoisQuotaHandlerTest {
when(quotaManager.acquireQuota(QuotaRequest.create(remoteAddress)))
.thenReturn(QuotaResponse.create(false, remoteAddress, now));
OverQuotaException e =
expectThrows(OverQuotaException.class, () -> channel.writeInbound(message));
assertThrows(OverQuotaException.class, () -> channel.writeInbound(message));
assertThat(e).hasMessageThat().contains("none");
verify(metrics).registerQuotaRejection("whois", "none");
verifyNoMoreInteractions(metrics);
@ -131,7 +131,7 @@ public class WhoisQuotaHandlerTest {
// Blocks the second user.
OverQuotaException e =
expectThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThat(e).hasMessageThat().contains("none");
verify(metrics).registerQuotaRejection("whois", "none");
verifyNoMoreInteractions(metrics);
@ -166,7 +166,7 @@ public class WhoisQuotaHandlerTest {
// Blocks the second channel.
OverQuotaException e =
expectThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThrows(OverQuotaException.class, () -> otherChannel.writeInbound(message));
assertThat(e).hasMessageThat().contains("none");
verify(metrics).registerQuotaRejection("whois", "none");

View file

@ -15,7 +15,7 @@
package google.registry.proxy.quota;
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.readResourceUtf8;
import google.registry.proxy.ProxyConfig.Quota;
@ -76,7 +76,7 @@ public class QuotaConfigTest {
quotaConfig = loadQuotaConfig("quota_config_unlimited_tokens.yaml");
assertThat(quotaConfig.hasUnlimitedTokens("some_user")).isTrue();
IllegalStateException e =
expectThrows(IllegalStateException.class, () -> quotaConfig.getTokenAmount("some_user"));
assertThrows(IllegalStateException.class, () -> quotaConfig.getTokenAmount("some_user"));
assertThat(e)
.hasMessageThat()
.contains("User ID some_user is provisioned with unlimited tokens");
@ -85,7 +85,7 @@ public class QuotaConfigTest {
@Test
public void testFailure_duplicateUserId() {
IllegalArgumentException e =
expectThrows(
assertThrows(
IllegalArgumentException.class, () -> loadQuotaConfig("quota_config_duplicate.yaml"));
assertThat(e).hasMessageThat().contains("Multiple entries with same key");
}