mirror of
https://github.com/google/nomulus.git
synced 2025-07-24 11:38:35 +02:00
Merge JUnitBackport's expectThrows into assertThrows
More information: https://github.com/junit-team/junit5/issues/531 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187034408
This commit is contained in:
parent
f96a0b7da9
commit
606b470cd0
180 changed files with 1325 additions and 1381 deletions
|
@ -19,7 +19,6 @@ import static com.google.common.collect.Iterables.getOnlyElement;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.logging.Level.INFO;
|
||||
|
@ -203,7 +202,7 @@ public class BigqueryPollJobActionTest {
|
|||
when(bigqueryJobsGet.execute()).thenReturn(
|
||||
new Job().setStatus(new JobStatus().setState("DONE")));
|
||||
action.payload = "payload".getBytes(UTF_8);
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, action::run);
|
||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||
assertThat(thrown).hasMessageThat().contains("Cannot deserialize task from payload");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.export;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.export.CheckSnapshotAction.CHECK_SNAPSHOT_KINDS_TO_LOAD_PARAM;
|
||||
import static google.registry.export.CheckSnapshotAction.CHECK_SNAPSHOT_NAME_PARAM;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -122,7 +122,7 @@ public class CheckSnapshotActionTest {
|
|||
public void testPost_forPendingBackup_returnsNotModified() throws Exception {
|
||||
setPendingBackup();
|
||||
|
||||
NotModifiedException thrown = expectThrows(NotModifiedException.class, action::run);
|
||||
NotModifiedException thrown = assertThrows(NotModifiedException.class, action::run);
|
||||
assertThat(thrown).hasMessageThat().contains("Datastore backup some_backup still pending");
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class CheckSnapshotActionTest {
|
|||
.plus(Duration.standardMinutes(3))
|
||||
.plus(Duration.millis(1234)));
|
||||
|
||||
NoContentException thrown = expectThrows(NoContentException.class, action::run);
|
||||
NoContentException thrown = assertThrows(NoContentException.class, action::run);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
|
@ -186,7 +186,7 @@ public class CheckSnapshotActionTest {
|
|||
when(backupService.findByName("some_backup"))
|
||||
.thenThrow(new IllegalArgumentException("No backup found"));
|
||||
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, action::run);
|
||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||
assertThat(thrown).hasMessageThat().contains("Bad backup name some_backup: No backup found");
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ public class CheckSnapshotActionTest {
|
|||
when(backupService.findByName("some_backup"))
|
||||
.thenThrow(new IllegalArgumentException("No backup found"));
|
||||
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, action::run);
|
||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||
assertThat(thrown).hasMessageThat().contains("Bad backup name some_backup: No backup found");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import static google.registry.export.ExportReservedTermsAction.RESERVED_TERMS_FI
|
|||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
@ -123,14 +123,14 @@ public class ExportReservedTermsActionTest {
|
|||
any(MediaType.class),
|
||||
anyString(),
|
||||
any(byte[].class))).thenThrow(new IOException("errorMessage"));
|
||||
RuntimeException thrown = expectThrows(RuntimeException.class, () -> runAction("tld"));
|
||||
RuntimeException thrown = assertThrows(RuntimeException.class, () -> runAction("tld"));
|
||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
assertThat(thrown).hasCauseThat().hasMessageThat().isEqualTo("errorMessage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_uploadFileToDrive_failsWhenTldDoesntExist() throws Exception {
|
||||
RuntimeException thrown = expectThrows(RuntimeException.class, () -> runAction("fakeTld"));
|
||||
RuntimeException thrown = assertThrows(RuntimeException.class, () -> runAction("fakeTld"));
|
||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
assertThat(thrown)
|
||||
.hasCauseThat()
|
||||
|
|
|
@ -22,7 +22,7 @@ import static google.registry.export.LoadSnapshotAction.LOAD_SNAPSHOT_KINDS_PARA
|
|||
import static google.registry.export.LoadSnapshotAction.PATH;
|
||||
import static google.registry.export.LoadSnapshotAction.QUEUE;
|
||||
import static google.registry.export.LoadSnapshotAction.enqueueLoadSnapshotTask;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -182,7 +182,7 @@ public class LoadSnapshotActionTest {
|
|||
@Test
|
||||
public void testFailure_doPost_badGcsFilename() throws Exception {
|
||||
action.snapshotFile = "gs://bucket/snapshot";
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, action::run);
|
||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Error calling load snapshot: backup info file extension missing");
|
||||
|
@ -192,7 +192,7 @@ public class LoadSnapshotActionTest {
|
|||
public void testFailure_doPost_bigqueryThrowsException() throws Exception {
|
||||
when(bigqueryJobsInsert.execute()).thenThrow(new IOException("The Internet has gone missing"));
|
||||
InternalServerErrorException thrown =
|
||||
expectThrows(InternalServerErrorException.class, action::run);
|
||||
assertThrows(InternalServerErrorException.class, action::run);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Error loading snapshot: The Internet has gone missing");
|
||||
|
|
|
@ -21,7 +21,7 @@ import static google.registry.export.PublishDetailReportAction.GCS_FOLDER_PREFIX
|
|||
import static google.registry.export.PublishDetailReportAction.REGISTRAR_ID_PARAM;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
|
@ -105,7 +105,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_noRegistrarParameter() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -119,7 +119,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_noGcsBucketParameter() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -133,7 +133,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_noGcsFolderPrefixParameter() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -147,7 +147,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_noReportNameParameter() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -161,7 +161,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_registrarNotFound() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -178,7 +178,7 @@ public class PublishDetailReportActionTest {
|
|||
persistResource(
|
||||
loadRegistrar("TheRegistrar").asBuilder().setDriveFolderId(null).build());
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -193,7 +193,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_gcsBucketNotFound() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -208,7 +208,7 @@ public class PublishDetailReportActionTest {
|
|||
@Test
|
||||
public void testFailure_gcsFileNotFound() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
@ -226,7 +226,7 @@ public class PublishDetailReportActionTest {
|
|||
anyString(), any(MediaType.class), anyString(), any(byte[].class)))
|
||||
.thenThrow(new IOException("Drive is down"));
|
||||
InternalServerErrorException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
InternalServerErrorException.class,
|
||||
() ->
|
||||
action.handleJsonRequest(
|
||||
|
|
|
@ -21,7 +21,7 @@ import static google.registry.export.UpdateSnapshotViewAction.UPDATE_SNAPSHOT_DA
|
|||
import static google.registry.export.UpdateSnapshotViewAction.UPDATE_SNAPSHOT_KIND_PARAM;
|
||||
import static google.registry.export.UpdateSnapshotViewAction.UPDATE_SNAPSHOT_TABLE_ID_PARAM;
|
||||
import static google.registry.export.UpdateSnapshotViewAction.createViewUpdateTask;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
|
@ -124,7 +124,7 @@ public class UpdateSnapshotViewActionTest {
|
|||
when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
|
||||
.thenThrow(new IOException("I'm sorry Dave, I can't let you do that"));
|
||||
InternalServerErrorException thrown =
|
||||
expectThrows(InternalServerErrorException.class, action::run);
|
||||
assertThrows(InternalServerErrorException.class, action::run);
|
||||
assertThat(thrown).hasMessageThat().contains("Error in update snapshot view action");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue