Skip to content

Commit

Permalink
chore: remove deprecated method (#70)
Browse files Browse the repository at this point in the history
* 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 <stephaniewang526@users.noreply.github.com>
  • Loading branch information
elharo and stephaniewang526 committed Jan 3, 2020
1 parent e8016c1 commit aabf02a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 93 deletions.
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}
}
Expand Up @@ -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.<TransportOptions>createMock(TransportOptions.class));
try {
BigQueryOptions.newBuilder()
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
Assert.fail();
} catch (IllegalArgumentException expected) {
Assert.assertNotNull(expected.getMessage());
}
}
}
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<FieldValueList> emptyPage =
new Page<FieldValueList>() {
@Override
public boolean hasNextPage() {
return false;
}

@Override
public String getNextPageToken() {
return "";
}

@Override
public Page<FieldValueList> getNextPage() {
return null;
}

@Override
public Iterable<FieldValueList> iterateAll() {
return Collections.emptyList();
}

@Override
public Iterable<FieldValueList> getValues() {
return Collections.emptyList();
}
};
QueryResponse completedQuery =
QueryResponse.newBuilder()
.setCompleted(true)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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 {

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit aabf02a

Please sign in to comment.