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

@ -191,9 +191,9 @@ public class GhostrydeTest {
byte[] ciphertext = bsOut.toByteArray();
korruption(ciphertext, ciphertext.length / 2);
thrown.expect(IllegalStateException.class, "tampering");
ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext);
thrown.expect(IllegalStateException.class, "tampering");
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
}
@ -219,9 +219,9 @@ public class GhostrydeTest {
byte[] ciphertext = bsOut.toByteArray();
korruption(ciphertext, ciphertext.length / 2);
thrown.expect(PGPException.class);
ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext);
thrown.expect(PGPException.class);
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
}
@ -245,10 +245,10 @@ public class GhostrydeTest {
output.write(data);
}
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
thrown.expect(
PGPException.class,
"Message was encrypted for keyid a59c132f3589a1d5 but ours is c9598c84ec70b9fd");
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
}