mirror of
https://github.com/google/nomulus
synced 2026-02-13 08:11:36 +00:00
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:
@@ -170,55 +170,55 @@ public class DomainTransferQueryFlowTest
|
||||
|
||||
@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_query_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_query_domain_authinfo.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_neverBeenTransferred() throws Exception {
|
||||
thrown.expect(NoTransferHistoryToQueryException.class);
|
||||
changeTransferStatus(null);
|
||||
thrown.expect(NoTransferHistoryToQueryException.class);
|
||||
doFailingTest("domain_transfer_query.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_unrelatedClient() throws Exception {
|
||||
thrown.expect(NotAuthorizedToViewTransferException.class);
|
||||
setClientIdForFlow("ClientZ");
|
||||
thrown.expect(NotAuthorizedToViewTransferException.class);
|
||||
doFailingTest("domain_transfer_query.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_query.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nonexistentDomain() throws Exception {
|
||||
deleteResource(domain);
|
||||
thrown.expect(
|
||||
ResourceDoesNotExistException.class,
|
||||
String.format("(%s)", getUniqueIdFromCommand()));
|
||||
deleteResource(domain);
|
||||
doFailingTest("domain_transfer_query.xml");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user