Automatically refactor more exception testing to use new JUnit rules

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179072309
This commit is contained in:
mcilwain 2017-12-14 11:40:04 -08:00 committed by Ben McIlwain
parent d5d29959b4
commit 9157930983
100 changed files with 3900 additions and 3192 deletions

View file

@ -31,6 +31,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableSet;
@ -174,8 +176,10 @@ public class DomainTransferRejectFlowTest
public void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml");
assertThrows(
NotAuthorizedForTldException.class,
() ->
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml"));
}
@Test
@ -193,8 +197,9 @@ public class DomainTransferRejectFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_contact_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_contact_authinfo.xml"));
}
@Test
@ -204,81 +209,84 @@ public class DomainTransferRejectFlowTest
domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_domain_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_domain_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_reject.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_reject.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
// NB: No need to test pending delete status since pending transfers will get cancelled upon