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

@ -15,13 +15,13 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.Assert.fail;
import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
@ -285,7 +285,7 @@ public class MutatingCommandTest {
+ "blockPremiumNames -> [false, true]\n");
try {
command.execute();
fail("Expected transaction to fail with IllegalStateException.");
assertWithMessage("Expected transaction to fail with IllegalStateException").fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage()).contains("Entity changed since init() was called.");
assertThat(ofy().load().entity(host1).now()).isNull();