mirror of
https://github.com/google/nomulus
synced 2026-08-21 22:56:19 +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:
@@ -152,30 +152,30 @@ public class RdeImportUtilsTest extends ShardableTestCase {
|
||||
/** Verifies thrown error when tld in escrow file is not in the registry */
|
||||
@Test
|
||||
public void testValidateEscrowFile_tldNotFound() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry");
|
||||
xmlInput = DEPOSIT_BADTLD_XML.openBufferedStream();
|
||||
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
|
||||
thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry");
|
||||
rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badtld.xml");
|
||||
}
|
||||
|
||||
/** Verifies thrown errer when tld in escrow file is not in PREDELEGATION state */
|
||||
@Test
|
||||
public void testValidateEscrowFile_tldWrongState() throws Exception {
|
||||
xmlInput = DEPOSIT_GETLD_XML.openBufferedStream();
|
||||
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
|
||||
thrown.expect(
|
||||
IllegalArgumentException.class,
|
||||
"Tld 'getld' is in state GENERAL_AVAILABILITY and cannot be imported");
|
||||
xmlInput = DEPOSIT_GETLD_XML.openBufferedStream();
|
||||
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
|
||||
rdeImportUtils.validateEscrowFileForImport("invalid-deposit-getld.xml");
|
||||
}
|
||||
|
||||
/** Verifies thrown error when registrar in escrow file is not in the registry */
|
||||
@Test
|
||||
public void testValidateEscrowFile_badRegistrar() throws Exception {
|
||||
thrown.expect(
|
||||
IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry");
|
||||
xmlInput = DEPOSIT_BADREGISTRAR_XML.openBufferedStream();
|
||||
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
|
||||
thrown.expect(
|
||||
IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry");
|
||||
rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badregistrar.xml");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user