mirror of
https://github.com/google/nomulus
synced 2026-09-04 23:27:11 +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:
@@ -136,19 +136,19 @@ public class DirectoryGroupsConnectionTest {
|
||||
|
||||
@Test
|
||||
public void test_addMemberToGroup_handlesExceptionThrownByDirectoryService() throws Exception {
|
||||
thrown.expect(GoogleJsonResponseException.class);
|
||||
when(membersInsert.execute()).thenThrow(
|
||||
makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server."));
|
||||
thrown.expect(GoogleJsonResponseException.class);
|
||||
runAddMemberTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_addMemberToGroup_handlesMemberKeyNotFoundException() throws Exception {
|
||||
thrown.expect(RuntimeException.class,
|
||||
"Adding member jim@example.com to group spam@example.com "
|
||||
+ "failed because the member wasn't found.");
|
||||
when(membersInsert.execute()).thenThrow(
|
||||
makeResponseException(SC_NOT_FOUND, "Resource Not Found: memberKey"));
|
||||
thrown.expect(RuntimeException.class,
|
||||
"Adding member jim@example.com to group spam@example.com "
|
||||
+ "failed because the member wasn't found.");
|
||||
connection.addMemberToGroup("spam@example.com", "jim@example.com", Role.MEMBER);
|
||||
}
|
||||
|
||||
@@ -196,9 +196,9 @@ public class DirectoryGroupsConnectionTest {
|
||||
|
||||
@Test
|
||||
public void test_createGroup_handlesExceptionThrownByDirectoryService() throws Exception {
|
||||
thrown.expect(GoogleJsonResponseException.class);
|
||||
when(groupsInsert.execute()).thenThrow(
|
||||
makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server."));
|
||||
thrown.expect(GoogleJsonResponseException.class);
|
||||
runCreateGroupTest();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user