Move thrown.expect() right before the throwing statement

aka regexing for fun and profit.

This also makes sure that there are no statements after the
throwing statement, since these would be dead code. There
were a surprising number of places with assertions after
the throw, and none of these are actually triggered in tests
ever. When I found these, I replaced them with try/catch/rethrow
which makes the assertions actually happen:

before:

// This is the ExceptionRule that checks EppException marshaling
thrown.expect(FooException.class);
doThrowingThing();
assertSomething();  // Dead code!

after:

try {
  doThrowingThing();
  assertWithMessage("...").fail();
} catch (FooException e) {
  assertSomething();
  // For EppExceptions:
  assertAboutEppExceptins().that(e).marshalsToXml();
}

To make this work, I added EppExceptionSubject.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135793407
This commit is contained in:
cgoldfeder 2016-10-11 07:19:48 -07:00 committed by Ben McIlwain
parent cb8320ff40
commit f3a0b78145
62 changed files with 519 additions and 450 deletions

View file

@ -153,109 +153,109 @@ public class DomainTransferRejectFlowTest
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml");
}
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_contact_authinfo.xml");
}
@Test
public void testFailure_badDomainPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the domain's password so it does not match the password in the file.
domain = persistResource(
domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_domain_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_gainingClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("ClientZ");
thrown.expect(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,
String.format("(%s)", getUniqueIdFromCommand()));
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(domain);
doFailingTest("domain_transfer_reject.xml");
}