Get rid of custom ExceptionRule methods

The only remaining methods on ExceptionRule after this are methods that
also exist on ExpectedException, which will allow us to, in the next CL,
swap out the one for the other and then run the automated refactoring to
turn it all into assertThrows/expectThrows.

Note that there were some assertions about root causes that couldn't
easily be turned into ExpectedException invocations, so I simply
converted them directly to usages of assertThrows/expectThrows.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178623431
This commit is contained in:
mcilwain 2017-12-11 08:47:27 -08:00 committed by jianglai
parent 68a26f5b6e
commit b825a2b5a8
144 changed files with 1176 additions and 894 deletions

View file

@ -208,7 +208,8 @@ public class BigqueryPollJobActionTest {
when(bigqueryJobsGet.execute()).thenReturn(
new Job().setStatus(new JobStatus().setState("DONE")));
action.payload = "payload".getBytes(UTF_8);
thrown.expect(BadRequestException.class, "Cannot deserialize task from payload");
thrown.expect(BadRequestException.class);
thrown.expectMessage("Cannot deserialize task from payload");
action.run();
}
}

View file

@ -124,7 +124,8 @@ public class CheckSnapshotActionTest {
public void testPost_forPendingBackup_returnsNotModified() throws Exception {
setPendingBackup();
thrown.expect(NotModifiedException.class, "Datastore backup some_backup still pending");
thrown.expect(NotModifiedException.class);
thrown.expectMessage("Datastore backup some_backup still pending");
action.run();
}
@ -140,9 +141,8 @@ public class CheckSnapshotActionTest {
.plus(Duration.standardMinutes(3))
.plus(Duration.millis(1234)));
thrown.expect(
NoContentException.class,
"Datastore backup some_backup abandoned - "
thrown.expect(NoContentException.class);
thrown.expectMessage("Datastore backup some_backup abandoned - "
+ "not complete after 20 hours, 3 minutes and 1 second");
action.run();
@ -188,7 +188,8 @@ public class CheckSnapshotActionTest {
when(backupService.findByName("some_backup"))
.thenThrow(new IllegalArgumentException("No backup found"));
thrown.expect(BadRequestException.class, "Bad backup name some_backup: No backup found");
thrown.expect(BadRequestException.class);
thrown.expectMessage("Bad backup name some_backup: No backup found");
action.run();
}
@ -219,7 +220,8 @@ public class CheckSnapshotActionTest {
when(backupService.findByName("some_backup"))
.thenThrow(new IllegalArgumentException("No backup found"));
thrown.expect(BadRequestException.class, "Bad backup name some_backup: No backup found");
thrown.expect(BadRequestException.class);
thrown.expectMessage("Bad backup name some_backup: No backup found");
action.run();
}

View file

@ -186,18 +186,16 @@ public class LoadSnapshotActionTest {
@Test
public void testFailure_doPost_badGcsFilename() throws Exception {
action.snapshotFile = "gs://bucket/snapshot";
thrown.expect(
BadRequestException.class,
"Error calling load snapshot: backup info file extension missing");
thrown.expect(BadRequestException.class);
thrown.expectMessage("Error calling load snapshot: backup info file extension missing");
action.run();
}
@Test
public void testFailure_doPost_bigqueryThrowsException() throws Exception {
when(bigqueryJobsInsert.execute()).thenThrow(new IOException("The Internet has gone missing"));
thrown.expect(
InternalServerErrorException.class,
"Error loading snapshot: The Internet has gone missing");
thrown.expect(InternalServerErrorException.class);
thrown.expectMessage("Error loading snapshot: The Internet has gone missing");
action.run();
}
}

View file

@ -108,7 +108,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_noRegistrarParameter() throws Exception {
thrown.expect(BadRequestException.class, REGISTRAR_ID_PARAM);
thrown.expect(BadRequestException.class);
thrown.expectMessage(REGISTRAR_ID_PARAM);
action.handleJsonRequest(ImmutableMap.of(
GCS_BUCKET_PARAM, "mah-buckit",
GCS_FOLDER_PREFIX_PARAM, "some/folder/",
@ -117,7 +118,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_noGcsBucketParameter() throws Exception {
thrown.expect(BadRequestException.class, GCS_BUCKET_PARAM);
thrown.expect(BadRequestException.class);
thrown.expectMessage(GCS_BUCKET_PARAM);
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_FOLDER_PREFIX_PARAM, "some/folder/",
@ -126,7 +128,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_noGcsFolderPrefixParameter() throws Exception {
thrown.expect(BadRequestException.class, GCS_FOLDER_PREFIX_PARAM);
thrown.expect(BadRequestException.class);
thrown.expectMessage(GCS_FOLDER_PREFIX_PARAM);
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_BUCKET_PARAM, "mah-buckit",
@ -135,7 +138,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_noReportNameParameter() throws Exception {
thrown.expect(BadRequestException.class, DETAIL_REPORT_NAME_PARAM);
thrown.expect(BadRequestException.class);
thrown.expectMessage(DETAIL_REPORT_NAME_PARAM);
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_BUCKET_PARAM, "mah-buckit",
@ -144,7 +148,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_registrarNotFound() throws Exception {
thrown.expect(BadRequestException.class, "FakeRegistrar");
thrown.expect(BadRequestException.class);
thrown.expectMessage("FakeRegistrar");
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "FakeRegistrar",
GCS_BUCKET_PARAM, "mah-buckit",
@ -156,7 +161,8 @@ public class PublishDetailReportActionTest {
public void testFailure_registrarHasNoDriveFolder() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setDriveFolderId(null).build());
thrown.expect(BadRequestException.class, "drive folder");
thrown.expect(BadRequestException.class);
thrown.expectMessage("drive folder");
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_BUCKET_PARAM, "mah-buckit",
@ -166,7 +172,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_gcsBucketNotFound() throws Exception {
thrown.expect(BadRequestException.class, "fake-buckit");
thrown.expect(BadRequestException.class);
thrown.expectMessage("fake-buckit");
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_BUCKET_PARAM, "fake-buckit",
@ -176,7 +183,8 @@ public class PublishDetailReportActionTest {
@Test
public void testFailure_gcsFileNotFound() throws Exception {
thrown.expect(BadRequestException.class, "some/folder/fake_file.csv");
thrown.expect(BadRequestException.class);
thrown.expectMessage("some/folder/fake_file.csv");
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_BUCKET_PARAM, "mah-buckit",
@ -189,7 +197,8 @@ public class PublishDetailReportActionTest {
when(driveConnection.createFile(
anyString(), any(MediaType.class), anyString(), any(byte[].class)))
.thenThrow(new IOException("Drive is down"));
thrown.expect(InternalServerErrorException.class, "Drive is down");
thrown.expect(InternalServerErrorException.class);
thrown.expectMessage("Drive is down");
action.handleJsonRequest(ImmutableMap.of(
REGISTRAR_ID_PARAM, "TheRegistrar",
GCS_BUCKET_PARAM, "mah-buckit",

View file

@ -127,7 +127,8 @@ public class UpdateSnapshotViewActionTest {
public void testFailure_bigqueryConnectionThrowsError() throws Exception {
when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
.thenThrow(new IOException("I'm sorry Dave, I can't let you do that"));
thrown.expect(InternalServerErrorException.class, "Error in update snapshot view action");
thrown.expect(InternalServerErrorException.class);
thrown.expectMessage("Error in update snapshot view action");
action.run();
}
}