mirror of
https://github.com/google/nomulus.git
synced 2025-07-03 09:43:30 +02: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:
parent
cb8320ff40
commit
f3a0b78145
62 changed files with 519 additions and 450 deletions
|
@ -91,60 +91,60 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
|
|||
|
||||
@Test
|
||||
public void testFailure_invalidSmd() throws Exception {
|
||||
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
|
||||
String smdFile = writeToTmpFile(INVALID_SMD);
|
||||
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_revokedSmd() throws Exception {
|
||||
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
|
||||
DateTime now = new DateTime(UTC);
|
||||
SignedMarkRevocationList.create(now, ImmutableMap.of(ACTIVE_SMD_ID, now)).save();
|
||||
String smdFile = writeToTmpFile(ACTIVE_SMD);
|
||||
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_revokedTmv() throws Exception {
|
||||
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
|
||||
String smdFile = writeToTmpFile(REVOKED_TMV_SMD);
|
||||
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_unparseableXml() throws Exception {
|
||||
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
|
||||
String smdFile = writeToTmpFile(base64().encode("This is not XML!".getBytes(UTF_8)));
|
||||
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badlyEncodedData() throws Exception {
|
||||
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
|
||||
String smdFile = writeToTmpFile("Bad base64 data ~!@#$#@%%$#^$%^&^**&^)(*)(_".getBytes(UTF_8));
|
||||
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_wrongLabel() throws Exception {
|
||||
thrown.expectRootCause(RequiredParameterMissingException.class);
|
||||
String smdFile = writeToTmpFile(DIFFERENT_LABEL_SMD);
|
||||
thrown.expectRootCause(RequiredParameterMissingException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nonExistentApplication() throws Exception {
|
||||
thrown.expectRootCause(IllegalArgumentException.class);
|
||||
String smdFile = writeToTmpFile(ACTIVE_SMD);
|
||||
thrown.expectRootCause(IllegalArgumentException.class);
|
||||
runCommand("--id=3-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_deletedApplication() throws Exception {
|
||||
thrown.expectRootCause(IllegalArgumentException.class);
|
||||
persistResource(domainApplication.asBuilder().setDeletionTime(new DateTime(UTC)).build());
|
||||
String smdFile = writeToTmpFile(ACTIVE_SMD);
|
||||
thrown.expectRootCause(IllegalArgumentException.class);
|
||||
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue