From aabf02ac76ac050154422eee79569a81b7d00038 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 3 Jan 2020 11:35:34 -0500 Subject: [PATCH] chore: remove deprecated method (#70) * remove deprecated method * remove deprecated method * remove unused rule * remove deprecated rule * remove unused fields * remove deprecated rule * remove deprecated rule * chore: reformat code Co-authored-by: Stephanie Wang --- .../cloud/bigquery/BigQueryImplTest.java | 87 +++++++++++-------- .../cloud/bigquery/BigQueryOptionsTest.java | 14 +-- .../com/google/cloud/bigquery/JobTest.java | 52 ++++------- .../bigquery/TableDataWriteChannelTest.java | 18 ++-- .../testing/RemoteBigQueryHelperTest.java | 4 - 5 files changed, 82 insertions(+), 93 deletions(-) diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java index b83c4ca08..b1e1a5d36 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java @@ -58,10 +58,9 @@ import org.easymock.Capture; import org.easymock.EasyMock; import org.junit.After; +import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class BigQueryImplTest { @@ -133,19 +132,14 @@ public class BigQueryImplTest { .setCreationTime(TABLE_CREATION_TIME) .build(); - private static final ModelId MODEL_ID = ModelId.of(DATASET, MODEL); private static final ModelId OTHER_MODEL_ID = ModelId.of(DATASET, OTHER_MODEL); private static final ModelId MODEL_ID_WITH_PROJECT = ModelId.of(PROJECT, DATASET, MODEL); - private static final ModelInfo MODEL_INFO = ModelInfo.of(MODEL_ID); private static final ModelInfo OTHER_MODEL_INFO = ModelInfo.of(OTHER_MODEL_ID); private static final ModelInfo MODEL_INFO_WITH_PROJECT = ModelInfo.of(MODEL_ID_WITH_PROJECT); - private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION = - LoadJobConfiguration.of(TABLE_ID, "URI"); private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION_WITH_PROJECT = LoadJobConfiguration.of(TABLE_ID_WITH_PROJECT, "URI"); - private static final JobInfo LOAD_JOB = JobInfo.of(LOAD_JOB_CONFIGURATION); private static final JobInfo COMPLETE_LOAD_JOB = JobInfo.of(JobId.of(PROJECT, JOB), LOAD_JOB_CONFIGURATION_WITH_PROJECT); private static final CopyJobConfiguration COPY_JOB_CONFIGURATION = @@ -166,16 +160,8 @@ public class BigQueryImplTest { .setDefaultDataset(DatasetId.of(PROJECT, DATASET)) .setDestinationTable(TABLE_ID_WITH_PROJECT) .build(); - private static final JobInfo QUERY_JOB = JobInfo.of(QUERY_JOB_CONFIGURATION); private static final JobInfo COMPLETE_QUERY_JOB = JobInfo.of(JobId.of(PROJECT, JOB), QUERY_JOB_CONFIGURATION_WITH_PROJECT); - private static final ExtractJobConfiguration EXTRACT_JOB_CONFIGURATION = - ExtractJobConfiguration.of(TABLE_ID, "URI"); - private static final ExtractJobConfiguration EXTRACT_JOB_CONFIGURATION_WITH_PROJECT = - ExtractJobConfiguration.of(TABLE_ID_WITH_PROJECT, "URI"); - private static final JobInfo EXTRACT_JOB = JobInfo.of(EXTRACT_JOB_CONFIGURATION); - private static final JobInfo COMPLETE_EXTRACT_JOB = - JobInfo.of(JobId.of(PROJECT, JOB), EXTRACT_JOB_CONFIGURATION_WITH_PROJECT); private static final TableCell BOOLEAN_FIELD = new TableCell().setV("false"); private static final TableCell INTEGER_FIELD = new TableCell().setV("1"); private static final TableRow TABLE_ROW = @@ -429,8 +415,6 @@ public class BigQueryImplTest { private BigQueryRpc bigqueryRpcMock; private BigQuery bigquery; - @Rule public ExpectedException thrown = ExpectedException.none(); - private BigQueryOptions createBigQueryOptionsForProject( String project, BigQueryRpcFactory rpcFactory) { return BigQueryOptions.newBuilder() @@ -533,8 +517,12 @@ public void testGetDatasetNotFoundWhenThrowIsEnabled() { EasyMock.replay(bigqueryRpcMock); options.setThrowNotFound(true); bigquery = options.getService(); - thrown.expect(BigQueryException.class); - bigquery.getDataset("dataset-not-found"); + try { + bigquery.getDataset("dataset-not-found"); + Assert.fail(); + } catch (BigQueryException ex) { + Assert.assertNotNull(ex.getMessage()); + } } @Test @@ -817,8 +805,12 @@ public void testGetTableNotFoundWhenThrowIsEnabled() { EasyMock.replay(bigqueryRpcMock); options.setThrowNotFound(true); bigquery = options.getService(); - thrown.expect(BigQueryException.class); - bigquery.getTable(DATASET, "table-not-found"); + try { + bigquery.getTable(DATASET, "table-not-found"); + Assert.fail(); + } catch (BigQueryException ex) { + Assert.assertNotNull(ex.getMessage()); + } } @Test @@ -1161,8 +1153,12 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); - thrown.expect(BigQueryException.class); - bigquery.insertAll(request); + try { + bigquery.insertAll(request); + Assert.fail(); + } catch (BigQueryException ex) { + Assert.assertNotNull(ex.getMessage()); + } } @Test @@ -1477,8 +1473,12 @@ public void testGetJobNotFoundWhenThrowIsEnabled() { EasyMock.replay(bigqueryRpcMock); options.setThrowNotFound(true); bigquery = options.getService(); - thrown.expect(BigQueryException.class); - bigquery.getJob("job-not-found"); + try { + bigquery.getJob("job-not-found"); + Assert.fail(); + } catch (BigQueryException ex) { + Assert.assertNotNull(ex.getMessage()); + } } @Test @@ -1901,9 +1901,13 @@ public void testNonRetryableException() { .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); - thrown.expect(BigQueryException.class); - thrown.expectMessage(exceptionMessage); - bigquery.getDataset(DatasetId.of(DATASET)); + + try { + bigquery.getDataset(DatasetId.of(DATASET)); + Assert.fail(); + } catch (BigQueryException ex) { + Assert.assertEquals(exceptionMessage, ex.getMessage()); + } } @Test @@ -1918,21 +1922,28 @@ public void testRuntimeException() { .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); - thrown.expect(BigQueryException.class); - thrown.expectMessage(exceptionMessage); - bigquery.getDataset(DATASET); + try { + bigquery.getDataset(DATASET); + Assert.fail(); + } catch (BigQueryException ex) { + Assert.assertTrue(ex.getMessage().endsWith(exceptionMessage)); + } } @Test public void testQueryDryRun() throws Exception { // https://github.com/googleapis/google-cloud-java/issues/2479 EasyMock.replay(bigqueryRpcMock); - thrown.expect(UnsupportedOperationException.class); - options - .toBuilder() - .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) - .build() - .getService() - .query(QueryJobConfiguration.newBuilder("foo").setDryRun(true).build()); + try { + options + .toBuilder() + .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) + .build() + .getService() + .query(QueryJobConfiguration.newBuilder("foo").setDryRun(true).build()); + Assert.fail(); + } catch (UnsupportedOperationException ex) { + Assert.assertNotNull(ex.getMessage()); + } } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryOptionsTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryOptionsTest.java index 04962dffb..dc57c1f9a 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryOptionsTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryOptionsTest.java @@ -18,17 +18,19 @@ import com.google.cloud.TransportOptions; import org.easymock.EasyMock; -import org.junit.Rule; +import org.junit.Assert; import org.junit.Test; -import org.junit.rules.ExpectedException; public class BigQueryOptionsTest { - @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testInvalidTransport() { - thrown.expect(IllegalArgumentException.class); - BigQueryOptions.newBuilder() - .setTransportOptions(EasyMock.createMock(TransportOptions.class)); + try { + BigQueryOptions.newBuilder() + .setTransportOptions(EasyMock.createMock(TransportOptions.class)); + Assert.fail(); + } catch (IllegalArgumentException expected) { + Assert.assertNotNull(expected.getMessage()); + } } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java index c36fda6b4..978405d09 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java @@ -40,9 +40,8 @@ import com.google.common.collect.ImmutableList; import java.util.Collections; import org.junit.After; -import org.junit.Rule; +import org.junit.Assert; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.threeten.bp.Duration; public class JobTest { @@ -85,8 +84,6 @@ public class JobTest { private Job expectedJob; private Job job; - @Rule public final ExpectedException thrown = ExpectedException.none(); - private void initializeExpectedJob(int optionsCalls, JobInfo jobInfo) { expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); @@ -253,34 +250,6 @@ public void testWaitForAndGetQueryResultsEmpty() throws InterruptedException { expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); - // TODO(pongad): remove when we bump gax to 1.15. - Page emptyPage = - new Page() { - @Override - public boolean hasNextPage() { - return false; - } - - @Override - public String getNextPageToken() { - return ""; - } - - @Override - public Page getNextPage() { - return null; - } - - @Override - public Iterable iterateAll() { - return Collections.emptyList(); - } - - @Override - public Iterable getValues() { - return Collections.emptyList(); - } - }; QueryResponse completedQuery = QueryResponse.newBuilder() .setCompleted(true) @@ -435,8 +404,13 @@ public void testWaitForAndGetQueryResults_Unsupported() throws InterruptedExcept expect(bigquery.getOptions()).andReturn(mockOptions); replay(bigquery, mockOptions); initializeJob(); - thrown.expect(UnsupportedOperationException.class); - job.getQueryResults(); + + try { + job.getQueryResults(); + Assert.fail(); + } catch (UnsupportedOperationException expected) { + Assert.assertNotNull(expected.getMessage()); + } } @Test @@ -510,9 +484,13 @@ public void testWaitForWithTimeout() throws InterruptedException { expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); replay(status, bigquery, clock, mockOptions); initializeJob(); - thrown.expect(BigQueryException.class); - job.waitFor(concat(TEST_RETRY_OPTIONS, RetryOption.totalTimeout(Duration.ofMillis(3)))); - verify(status, clock, mockOptions); + + try { + job.waitFor(concat(TEST_RETRY_OPTIONS, RetryOption.totalTimeout(Duration.ofMillis(3)))); + Assert.fail(); + } catch (BigQueryException expected) { + Assert.assertNotNull(expected.getMessage()); + } } @Test diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableDataWriteChannelTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableDataWriteChannelTest.java index 43012a8ef..0b4707db1 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableDataWriteChannelTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableDataWriteChannelTest.java @@ -42,10 +42,9 @@ import org.easymock.Capture; import org.easymock.CaptureType; import org.junit.After; +import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class TableDataWriteChannelTest { @@ -67,8 +66,6 @@ public class TableDataWriteChannelTest { LoadJobConfiguration.of(TABLE_ID, "URI"); private static final JobInfo JOB_INFO = JobInfo.of(JobId.of(), JOB_CONFIGURATION); - @Rule public ExpectedException thrown = ExpectedException.none(); - private BigQueryOptions options; private BigQueryRpcFactory rpcFactoryMock; private BigQueryRpc bigqueryRpcMock; @@ -141,16 +138,21 @@ public void testCreateRetryableError() { } @Test - public void testCreateNonRetryableError() { + public void testCreateNonRetryableError() throws IOException { + RuntimeException ex = new RuntimeException("expected"); expect( bigqueryRpcMock.open( new com.google.api.services.bigquery.model.Job() .setJobReference(JOB_INFO.getJobId().toPb()) .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andThrow(new RuntimeException()); + .andThrow(ex); replay(bigqueryRpcMock); - thrown.expect(RuntimeException.class); - new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); + try (TableDataWriteChannel channel = + new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION)) { + Assert.fail(); + } catch (RuntimeException expected) { + Assert.assertEquals("java.lang.RuntimeException: expected", expected.getMessage()); + } } @Test diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/testing/RemoteBigQueryHelperTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/testing/RemoteBigQueryHelperTest.java index 65cd0571f..e994df433 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/testing/RemoteBigQueryHelperTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/testing/RemoteBigQueryHelperTest.java @@ -27,9 +27,7 @@ import java.io.InputStream; import java.util.concurrent.ExecutionException; import org.easymock.EasyMock; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.threeten.bp.Duration; public class RemoteBigQueryHelperTest { @@ -65,8 +63,6 @@ public class RemoteBigQueryHelperTest { + "}"; private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes()); - @Rule public ExpectedException thrown = ExpectedException.none(); - @Test public void testForceDelete() throws InterruptedException, ExecutionException { BigQuery bigqueryMock = EasyMock.createMock(BigQuery.class);