Get rid of custom ExceptionRule methods

The only remaining methods on ExceptionRule after this are methods that
also exist on ExpectedException, which will allow us to, in the next CL,
swap out the one for the other and then run the automated refactoring to
turn it all into assertThrows/expectThrows.

Note that there were some assertions about root causes that couldn't
easily be turned into ExpectedException invocations, so I simply
converted them directly to usages of assertThrows/expectThrows.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178623431
This commit is contained in:
mcilwain 2017-12-11 08:47:27 -08:00 committed by jianglai
parent 68a26f5b6e
commit b825a2b5a8
144 changed files with 1176 additions and 894 deletions

View file

@ -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();
}
}

View file

@ -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 {

View file

@ -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");

View file

@ -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 {

View file

@ -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);
}

View file

@ -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();