mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +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
|
@ -15,6 +15,7 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
@ -53,9 +54,13 @@ public class DeleteReservedListCommandTest extends CommandTestCase<DeleteReserve
|
|||
public void testFailure_whenReservedListIsInUse() throws Exception {
|
||||
createTld("xn--q9jyb4c");
|
||||
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(reservedList).build());
|
||||
thrown.expect(IllegalArgumentException.class,
|
||||
"Cannot delete reserved list because it is used on these tld(s): xn--q9jyb4c");
|
||||
runCommandForced("--name=" + reservedList.getName());
|
||||
assertThat(ReservedList.get(reservedList.getName())).isPresent();
|
||||
try {
|
||||
runCommandForced("--name=" + reservedList.getName());
|
||||
assertWithMessage("Expected IllegalArgumentException to be thrown").fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(ReservedList.get(reservedList.getName())).isPresent();
|
||||
assertThat(e).hasMessage(
|
||||
"Cannot delete reserved list because it is used on these tld(s): xn--q9jyb4c");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue