mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 01:35:17 +02:00
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:
parent
36ad38e5df
commit
7dc224627f
125 changed files with 1970 additions and 1982 deletions
|
@ -56,7 +56,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;
|
||||
|
@ -85,8 +84,6 @@ public class CloudDnsWriterTest {
|
|||
private CloudDnsWriter writer;
|
||||
private ImmutableSet<ResourceRecordSet> stubZone;
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
/*
|
||||
|
|
|
@ -17,6 +17,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.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -34,9 +35,7 @@ import java.util.Arrays;
|
|||
import javax.net.SocketFactory;
|
||||
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.junit.runners.JUnit4;
|
||||
import org.xbill.DNS.ARecord;
|
||||
|
@ -62,10 +61,6 @@ public class DnsMessageTransportTest {
|
|||
private Message simpleQuery;
|
||||
private Message expectedResponse;
|
||||
private DnsMessageTransport resolver;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
simpleQuery =
|
||||
|
@ -114,9 +109,7 @@ public class DnsMessageTransportTest {
|
|||
new ByteArrayInputStream(Arrays.copyOf(messageBytes, messageBytes.length - 1));
|
||||
when(mockSocket.getInputStream()).thenReturn(inputStream);
|
||||
when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
|
||||
thrown.expect(EOFException.class);
|
||||
|
||||
resolver.send(new Message());
|
||||
assertThrows(EOFException.class, () -> resolver.send(new Message()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,10 +138,9 @@ public class DnsMessageTransportTest {
|
|||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
when(mockSocket.getOutputStream()).thenReturn(outputStream);
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("message larger than maximum");
|
||||
|
||||
resolver.send(oversize);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> resolver.send(oversize));
|
||||
assertThat(thrown).hasMessageThat().contains("message larger than maximum");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -157,13 +149,14 @@ public class DnsMessageTransportTest {
|
|||
when(mockSocket.getInputStream())
|
||||
.thenReturn(new ByteArrayInputStream(messageToBytesWithLength(expectedResponse)));
|
||||
when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
|
||||
thrown.expect(VerifyException.class);
|
||||
thrown.expectMessage("response ID "
|
||||
+ expectedResponse.getHeader().getID()
|
||||
+ " does not match query ID "
|
||||
+ simpleQuery.getHeader().getID());
|
||||
|
||||
resolver.send(simpleQuery);
|
||||
VerifyException thrown = expectThrows(VerifyException.class, () -> resolver.send(simpleQuery));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"response ID "
|
||||
+ expectedResponse.getHeader().getID()
|
||||
+ " does not match query ID "
|
||||
+ simpleQuery.getHeader().getID());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -173,10 +166,10 @@ public class DnsMessageTransportTest {
|
|||
when(mockSocket.getInputStream())
|
||||
.thenReturn(new ByteArrayInputStream(messageToBytesWithLength(expectedResponse)));
|
||||
when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
|
||||
thrown.expect(VerifyException.class);
|
||||
thrown.expectMessage("response opcode 'STATUS' does not match query opcode 'QUERY'");
|
||||
|
||||
resolver.send(simpleQuery);
|
||||
VerifyException thrown = expectThrows(VerifyException.class, () -> resolver.send(simpleQuery));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("response opcode 'STATUS' does not match query opcode 'QUERY'");
|
||||
}
|
||||
|
||||
private Message responseMessageWithCode(Message query, int responseCode) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue