Automatically refactor more exception testing to use new JUnit rules

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178911894
This commit is contained in:
mcilwain 2017-08-14 09:20:03 -04:00 committed by Ben McIlwain
parent 36ad38e5df
commit 7dc224627f
125 changed files with 1970 additions and 1982 deletions

View file

@ -26,6 +26,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveSubordinateHo
import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@ -52,7 +53,6 @@ import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@ -76,9 +76,6 @@ public class DnsUpdateWriterTest {
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final InjectRule inject = new InjectRule();
@ -390,11 +387,14 @@ public class DnsUpdateWriterTest {
.build();
persistResource(domain);
when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL));
thrown.expect(VerifyException.class);
thrown.expectMessage("SERVFAIL");
writer.publishDomain("example.tld");
writer.commit();
VerifyException thrown =
expectThrows(
VerifyException.class,
() -> {
writer.publishDomain("example.tld");
writer.commit();
});
assertThat(thrown).hasMessageThat().contains("SERVFAIL");
}
@Test
@ -406,11 +406,14 @@ public class DnsUpdateWriterTest {
.build();
persistResource(host);
when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL));
thrown.expect(VerifyException.class);
thrown.expectMessage("SERVFAIL");
writer.publishHost("ns1.example.tld");
writer.commit();
VerifyException thrown =
expectThrows(
VerifyException.class,
() -> {
writer.publishHost("ns1.example.tld");
writer.commit();
});
assertThat(thrown).hasMessageThat().contains("SERVFAIL");
}
private void assertThatUpdatedZoneIs(Update update, String zoneName) {