From ca9741591142dda6a9782e678ae7416fba4cbab8 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 14 May 2020 20:42:52 +0200 Subject: [PATCH 01/10] chore(deps): update dependency com.google.cloud:google-cloud-bigquery to v1.115.0 (#353) --- samples/install-without-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 79bf483706..97964abe57 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -45,7 +45,7 @@ com.google.cloud google-cloud-bigquery - 1.114.0 + 1.115.0 From 91213204d784e1a60d0552511933c71083cdb61a Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 14 May 2020 15:45:15 -0400 Subject: [PATCH 02/10] chore: release 1.115.1-SNAPSHOT (#354) * updated versions.txt [ci skip] * updated samples/pom.xml [ci skip] * updated samples/snippets/pom.xml [ci skip] * updated samples/install-without-bom/pom.xml [ci skip] * updated google-cloud-bigquery/pom.xml [ci skip] * updated pom.xml [ci skip] * updated samples/snapshot/pom.xml [ci skip] Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- google-cloud-bigquery/pom.xml | 4 ++-- pom.xml | 4 ++-- samples/snapshot/pom.xml | 2 +- versions.txt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index e143dc048d..ee4ac1ad46 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-bigquery - 1.115.0 + 1.115.1-SNAPSHOT jar BigQuery https://github.com/googleapis/java-bigquery @@ -11,7 +11,7 @@ com.google.cloud google-cloud-bigquery-parent - 1.115.0 + 1.115.1-SNAPSHOT google-cloud-bigquery diff --git a/pom.xml b/pom.xml index 2a966bfa80..845f020655 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bigquery-parent pom - 1.115.0 + 1.115.1-SNAPSHOT BigQuery Parent https://github.com/googleapis/java-bigquery @@ -91,7 +91,7 @@ com.google.cloud google-cloud-bigquery - 1.115.0 + 1.115.1-SNAPSHOT diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 748b9199f4..4c90b1576c 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -44,7 +44,7 @@ com.google.cloud google-cloud-bigquery - 1.115.0 + 1.115.1-SNAPSHOT diff --git a/versions.txt b/versions.txt index 396fa318ae..2c900ad0e0 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-bigquery:1.115.0:1.115.0 \ No newline at end of file +google-cloud-bigquery:1.115.0:1.115.1-SNAPSHOT \ No newline at end of file From ef6166e6235746c10151ac4e6ab54a04a8b4b92f Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 15 May 2020 09:21:33 -0700 Subject: [PATCH 03/10] changes without context (#355) autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. --- README.md | 2 +- synth.metadata | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3367b3ee10..4d9e26597e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ If you are using Maven without BOM, add this to your dependencies: com.google.cloud google-cloud-bigquery - 1.114.0 + 1.115.0 ``` diff --git a/synth.metadata b/synth.metadata index fc58861bef..d2c71635f5 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-bigquery.git", - "sha": "ec2382dd5747f2582b0aec9ab4824bc7c6ada951" + "sha": "91213204d784e1a60d0552511933c71083cdb61a" } }, { From f327bbd6efde90ea87b283ac0169ed87590f8433 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 18 May 2020 21:35:41 +0200 Subject: [PATCH 04/10] chore(deps): update dependency com.google.cloud:libraries-bom to v5.4.0 (#359) --- samples/snippets/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index a022259b12..8c070dfb0f 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -44,7 +44,7 @@ com.google.cloud libraries-bom - 5.3.0 + 5.4.0 pom import From 96d2c87bf087f980106f57ffaac0933274c84b96 Mon Sep 17 00:00:00 2001 From: Emily Darrow <47046797+ejdarrow@users.noreply.github.com> Date: Mon, 18 May 2020 16:15:08 -0400 Subject: [PATCH 05/10] docs(samples): Added UpdateTableDescription example. (#360) --- .../bigquery/UpdateTableDescription.java | 50 ++++++++++++ .../bigquery/UpdateTableDescriptionIT.java | 77 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 samples/snippets/src/main/java/com/example/bigquery/UpdateTableDescription.java create mode 100644 samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java diff --git a/samples/snippets/src/main/java/com/example/bigquery/UpdateTableDescription.java b/samples/snippets/src/main/java/com/example/bigquery/UpdateTableDescription.java new file mode 100644 index 0000000000..c52df00c61 --- /dev/null +++ b/samples/snippets/src/main/java/com/example/bigquery/UpdateTableDescription.java @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.bigquery; + +// [START bigquery_update_table_description] +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQueryException; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.Table; + +public class UpdateTableDescription { + + public static void runUpdateTableDescription() { + // TODO(developer): Replace these variables before running the sample. + String datasetName = "MY_DATASET_NAME"; + String tableName = "MY_TABLE_NAME"; + String newDescription = "this is the new table description"; + updateTableDescription(datasetName, tableName, newDescription); + } + + public static void updateTableDescription(String datasetName, String tableName, + String newDescription) { + try { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. + BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); + + Table table = bigquery.getTable(datasetName, tableName); + bigquery.update(table.toBuilder().setDescription(newDescription).build()); + System.out.println("Table description updated successfully to " + newDescription); + } catch (BigQueryException e) { + System.out.println("Table description was not updated \n" + e.toString()); + } + } +} +// [END bigquery_update_table_description] diff --git a/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java new file mode 100644 index 0000000000..ad71373a38 --- /dev/null +++ b/samples/snippets/src/test/java/com/example/bigquery/UpdateTableDescriptionIT.java @@ -0,0 +1,77 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.bigquery; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class UpdateTableDescriptionIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME"); + + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("BIGQUERY_DATASET_NAME"); + } + + @Before + public void setUp() throws Exception { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void updateTableDescription() { + // Create a table in order to modify its description + String tableName = "MY_TABLE_NAME_" + UUID.randomUUID().toString().replace("-", "_"); + CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, null); + String newDescription = "new description!"; + + // Modify table's description + UpdateTableDescription.updateTableDescription(BIGQUERY_DATASET_NAME, tableName, newDescription); + + assertThat(bout.toString()) + .contains("Table description updated successfully to " + newDescription); + + // Clean up + DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName); + + } +} From 7a256f734aab3a26a8290a66b11cbcb91fe05d7a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 19 May 2020 01:22:54 +0200 Subject: [PATCH 06/10] deps: update dependency com.google.cloud:google-cloud-shared-dependencies to v0.4.0 (#362) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 845f020655..cddbd6ab22 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ com.google.cloud google-cloud-shared-dependencies - 0.3.1 + 0.4.0 pom import From 773edeabee7c6515c60b9a11f9e08bc927a9abc5 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 18 May 2020 16:23:11 -0700 Subject: [PATCH 07/10] changes without context (#363) autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. --- README.md | 3 ++- synth.metadata | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d9e26597e..3a9e42de40 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google com.google.cloud libraries-bom - 5.3.0 + 5.4.0 pom import @@ -237,6 +237,7 @@ has instructions for running the samples. | Update Dataset Access | [source code](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetAccess.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetAccess.java) | | Update Dataset Description | [source code](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetDescription.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetDescription.java) | | Update Dataset Expiration | [source code](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetExpiration.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateDatasetExpiration.java) | +| Update Table Description | [source code](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/UpdateTableDescription.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateTableDescription.java) | | Update Table Expiration | [source code](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/UpdateTableExpiration.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-bigquery&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/bigquery/UpdateTableExpiration.java) | diff --git a/synth.metadata b/synth.metadata index d2c71635f5..ec52a41625 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-bigquery.git", - "sha": "91213204d784e1a60d0552511933c71083cdb61a" + "sha": "96d2c87bf087f980106f57ffaac0933274c84b96" } }, { From 84cd360e8beb317625504516139b10d8fb47cea5 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Tue, 19 May 2020 22:08:48 +0530 Subject: [PATCH 08/10] chore: remove hamcrest dependency and modify test case (#364) --- google-cloud-bigquery/pom.xml | 8 +------- .../cloud/bigquery/StandardTableDefinition.java | 2 +- .../bigquery/StandardTableDefinitionTest.java | 15 ++++----------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index ee4ac1ad46..c3b3678de5 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -83,12 +83,6 @@ - - org.hamcrest - hamcrest - 2.2 - test - junit junit @@ -161,4 +155,4 @@ - \ No newline at end of file + diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java index 4e26f831f1..9a76b71009 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java @@ -277,7 +277,7 @@ static StandardTableDefinition fromPb(Table tablePb) { } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Illegal Argument - Got unexpected time partitioning " - + tablePb.getTimePartitioning().toString() + + tablePb.getTimePartitioning().getType() + " in project " + tablePb.getTableReference().getProjectId() + " in dataset " diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java index 397e69d1ef..6742763cb2 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java @@ -16,9 +16,6 @@ package com.google.cloud.bigquery; -import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -29,6 +26,7 @@ import com.google.api.services.bigquery.model.TableReference; import com.google.cloud.bigquery.StandardTableDefinition.StreamingBuffer; import com.google.common.collect.ImmutableList; +import com.google.common.truth.Truth; import org.junit.Test; public class StandardTableDefinitionTest { @@ -139,14 +137,9 @@ public void testFromPbWithUnexpectedTimePartitioningTypeRaisesInvalidArgumentExc try { StandardTableDefinition.fromPb(invalidTable); } catch (IllegalArgumentException ie) { - assertThat( - ie.getMessage(), - allOf( - containsString("Illegal Argument - Got unexpected time partitioning"), - containsString("GHURRY"), - containsString("ILLEGAL_ARG_TEST_PROJECT"), - containsString("ILLEGAL_ARG_TEST_DATASET"), - containsString("ILLEGAL_ARG_TEST_TABLE"))); + Truth.assertThat(ie.getMessage()) + .contains( + "Illegal Argument - Got unexpected time partitioning GHURRY in project ILLEGAL_ARG_TEST_PROJECT in dataset ILLEGAL_ARG_TEST_DATASET in table ILLEGAL_ARG_TEST_TABLE"); return; } fail("testFromPb illegal argument exception did not throw!"); From 4a716acc035421ce4ec316a81ad5152c747e48da Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Tue, 19 May 2020 22:13:14 +0530 Subject: [PATCH 09/10] chore: add mockitto dependency and convert test cases (#348) * chore: add mockitto dependency and convert test cases * chore: add remaining test cases * chore: remove easymock dependency and add remanining test cases * chore: change version of dependency and modify test cases * chore: change version of mockito dependency --- google-cloud-bigquery/pom.xml | 9 +- .../cloud/bigquery/BigQueryExceptionTest.java | 28 +- .../cloud/bigquery/BigQueryImplTest.java | 624 +++++++++--------- .../cloud/bigquery/BigQueryOptionsTest.java | 8 +- .../google/cloud/bigquery/DatasetTest.java | 238 +++---- .../com/google/cloud/bigquery/JobTest.java | 350 ++++------ .../com/google/cloud/bigquery/ModelTest.java | 119 ++-- .../google/cloud/bigquery/RoutineTest.java | 122 ++-- .../bigquery/TableDataWriteChannelTest.java | 394 ++++++----- .../com/google/cloud/bigquery/TableTest.java | 257 +++----- .../testing/RemoteBigQueryHelperTest.java | 14 +- pom.xml | 13 +- 12 files changed, 948 insertions(+), 1228 deletions(-) diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index c3b3678de5..198d38a5b4 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -93,12 +93,9 @@ truth - org.easymock - easymock - - - org.objenesis - objenesis + org.mockito + mockito-core + test diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryExceptionTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryExceptionTest.java index 7fb68ef4dd..41915e2834 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryExceptionTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryExceptionTest.java @@ -16,15 +16,15 @@ package com.google.cloud.bigquery; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpResponseException; @@ -33,7 +33,10 @@ import java.io.IOException; import java.net.SocketTimeoutException; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class BigQueryExceptionTest { @Test @@ -128,9 +131,8 @@ public void testBigQueryException() { @Test public void testTranslateAndThrow() throws Exception { Exception cause = new BigQueryException(503, "message"); - RetryHelperException exceptionMock = createMock(RetryHelperException.class); - expect(exceptionMock.getCause()).andReturn(cause).times(2); - replay(exceptionMock); + RetryHelperException exceptionMock = mock(RetryHelperException.class); + when(exceptionMock.getCause()).thenReturn(cause); try { BigQueryException.translateAndThrow(exceptionMock); } catch (BaseServiceException ex) { @@ -138,13 +140,12 @@ public void testTranslateAndThrow() throws Exception { assertEquals("message", ex.getMessage()); assertTrue(ex.isRetryable()); } finally { - verify(exceptionMock); + verify(exceptionMock, times(2)).getCause(); } cause = new IllegalArgumentException("message"); - exceptionMock = createMock(RetryHelperException.class); - expect(exceptionMock.getMessage()).andReturn("message").times(1); - expect(exceptionMock.getCause()).andReturn(cause).times(2); - replay(exceptionMock); + exceptionMock = mock(RetryHelperException.class); + when(exceptionMock.getMessage()).thenReturn("message"); + when(exceptionMock.getCause()).thenReturn(cause); try { BigQueryException.translateAndThrow(exceptionMock); } catch (BaseServiceException ex) { @@ -153,7 +154,8 @@ public void testTranslateAndThrow() throws Exception { assertFalse(ex.isRetryable()); assertSame(cause, ex.getCause()); } finally { - verify(exceptionMock); + verify(exceptionMock).getMessage(); + verify(exceptionMock, times(2)).getCause(); } } } 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 999ea9a03b..ac11f40d06 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 @@ -17,10 +17,6 @@ package com.google.cloud.bigquery; import static com.google.common.truth.Truth.assertThat; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.anyString; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.eq; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -28,6 +24,12 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.api.gax.paging.Page; import com.google.api.services.bigquery.model.ErrorProto; @@ -55,13 +57,15 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.easymock.Capture; -import org.easymock.EasyMock; -import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class BigQueryImplTest { private static final String PROJECT = "project"; @@ -440,6 +444,9 @@ public class BigQueryImplTest { private BigQueryRpc bigqueryRpcMock; private BigQuery bigquery; + @Captor private ArgumentCaptor> capturedOptions; + @Captor private ArgumentCaptor jobCapture; + private BigQueryOptions createBigQueryOptionsForProject( String project, BigQueryRpcFactory rpcFactory) { return BigQueryOptions.newBuilder() @@ -461,22 +468,14 @@ private BigQueryOptions createBigQueryOptionsForProjectWithLocation( @Before public void setUp() { - rpcFactoryMock = EasyMock.createMock(BigQueryRpcFactory.class); - bigqueryRpcMock = EasyMock.createMock(BigQueryRpc.class); - EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(BigQueryOptions.class))) - .andReturn(bigqueryRpcMock); - EasyMock.replay(rpcFactoryMock); + rpcFactoryMock = mock(BigQueryRpcFactory.class); + bigqueryRpcMock = mock(BigQueryRpc.class); + when(rpcFactoryMock.create(any(BigQueryOptions.class))).thenReturn(bigqueryRpcMock); options = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock); } - @After - public void tearDown() { - EasyMock.verify(rpcFactoryMock, bigqueryRpcMock); - } - @Test public void testGetOptions() { - EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); assertSame(options, bigquery.getOptions()); } @@ -484,23 +483,20 @@ public void testGetOptions() { @Test public void testCreateDataset() { DatasetInfo datasetInfo = DATASET_INFO.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.create(datasetInfo.toPb(), EMPTY_RPC_OPTIONS)) - .andReturn(datasetInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(datasetInfo.toPb(), EMPTY_RPC_OPTIONS)) + .thenReturn(datasetInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Dataset dataset = bigquery.create(datasetInfo); assertEquals(new Dataset(bigquery, new DatasetInfo.BuilderImpl(datasetInfo)), dataset); + verify(bigqueryRpcMock).create(datasetInfo.toPb(), EMPTY_RPC_OPTIONS); } @Test public void testCreateDatasetWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect( - bigqueryRpcMock.create(eq(DATASET_INFO_WITH_PROJECT.toPb()), capture(capturedOptions))) - .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(eq(DATASET_INFO_WITH_PROJECT.toPb()), capturedOptions.capture())) + .thenReturn(DATASET_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.create(DATASET_INFO, DATASET_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(DATASET_OPTION_FIELDS.getRpcOption()); @@ -510,36 +506,36 @@ public void testCreateDatasetWithSelectedFields() { assertEquals(28, selector.length()); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); + verify(bigqueryRpcMock).create(eq(DATASET_INFO_WITH_PROJECT.toPb()), capturedOptions.capture()); } @Test public void testGetDataset() { - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenReturn(DATASET_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.getDataset(DATASET); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); + verify(bigqueryRpcMock).getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testGetDatasetNotFoundWhenThrowIsDisabled() { - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenReturn(DATASET_INFO_WITH_PROJECT.toPb()); options.setThrowNotFound(false); bigquery = options.getService(); Dataset dataset = bigquery.getDataset(DATASET); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); + verify(bigqueryRpcMock).getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testGetDatasetNotFoundWhenThrowIsEnabled() { - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, "dataset-not-found", EMPTY_RPC_OPTIONS)) - .andThrow(new BigQueryException(404, "Dataset not found")); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, "dataset-not-found", EMPTY_RPC_OPTIONS)) + .thenThrow(new BigQueryException(404, "Dataset not found")); options.setThrowNotFound(true); bigquery = options.getService(); try { @@ -548,37 +544,36 @@ public void testGetDatasetNotFoundWhenThrowIsEnabled() { } catch (BigQueryException ex) { Assert.assertNotNull(ex.getMessage()); } + verify(bigqueryRpcMock).getDataset(PROJECT, "dataset-not-found", EMPTY_RPC_OPTIONS); } @Test public void testGetDatasetFromDatasetId() { - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenReturn(DATASET_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.getDataset(DatasetId.of(DATASET)); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); + verify(bigqueryRpcMock).getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testGetDatasetFromDatasetIdWithProject() { DatasetInfo datasetInfo = DATASET_INFO.setProjectId(OTHER_PROJECT); DatasetId datasetId = DatasetId.of(OTHER_PROJECT, DATASET); - EasyMock.expect(bigqueryRpcMock.getDataset(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(datasetInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenReturn(datasetInfo.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.getDataset(datasetId); assertEquals(new Dataset(bigquery, new DatasetInfo.BuilderImpl(datasetInfo)), dataset); + verify(bigqueryRpcMock).getDataset(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testGetDatasetWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(bigqueryRpcMock.getDataset(eq(PROJECT), eq(DATASET), capture(capturedOptions))) - .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(eq(PROJECT), eq(DATASET), capturedOptions.capture())) + .thenReturn(DATASET_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.getDataset(DATASET, DATASET_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(DATASET_OPTION_FIELDS.getRpcOption()); @@ -588,6 +583,7 @@ public void testGetDatasetWithSelectedFields() { assertEquals(28, selector.length()); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); + verify(bigqueryRpcMock).getDataset(eq(PROJECT), eq(DATASET), capturedOptions.capture()); } @Test @@ -599,12 +595,12 @@ public void testListDatasets() { new Dataset(bigquery, new DatasetInfo.BuilderImpl(OTHER_DATASET_INFO))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(datasetList, DatasetInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listDatasets(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listDatasets(PROJECT, EMPTY_RPC_OPTIONS)).thenReturn(result); Page page = bigquery.listDatasets(); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals( datasetList.toArray(), Iterables.toArray(page.getValues(), DatasetInfo.class)); + verify(bigqueryRpcMock).listDatasets(PROJECT, EMPTY_RPC_OPTIONS); } @Test @@ -616,13 +612,12 @@ public void testListDatasetsWithProjects() { bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO.setProjectId(OTHER_PROJECT)))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(datasetList, DatasetInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listDatasets(OTHER_PROJECT, EMPTY_RPC_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listDatasets(OTHER_PROJECT, EMPTY_RPC_OPTIONS)).thenReturn(result); Page page = bigquery.listDatasets(OTHER_PROJECT); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals( datasetList.toArray(), Iterables.toArray(page.getValues(), DatasetInfo.class)); + verify(bigqueryRpcMock).listDatasets(OTHER_PROJECT, EMPTY_RPC_OPTIONS); } @Test @@ -630,13 +625,13 @@ public void testListEmptyDatasets() { ImmutableList datasets = ImmutableList.of(); Tuple> result = Tuple.>of(null, datasets); - EasyMock.expect(bigqueryRpcMock.listDatasets(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listDatasets(PROJECT, EMPTY_RPC_OPTIONS)).thenReturn(result); bigquery = options.getService(); Page page = bigquery.listDatasets(); assertNull(page.getNextPageToken()); assertArrayEquals( ImmutableList.of().toArray(), Iterables.toArray(page.getValues(), Dataset.class)); + verify(bigqueryRpcMock).listDatasets(PROJECT, EMPTY_RPC_OPTIONS); } @Test @@ -648,50 +643,46 @@ public void testListDatasetsWithOptions() { new Dataset(bigquery, new DatasetInfo.BuilderImpl(OTHER_DATASET_INFO))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(datasetList, DatasetInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listDatasets(PROJECT, DATASET_LIST_OPTIONS)).andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listDatasets(PROJECT, DATASET_LIST_OPTIONS)).thenReturn(result); Page page = bigquery.listDatasets(DATASET_LIST_ALL, DATASET_LIST_PAGE_TOKEN, DATASET_LIST_PAGE_SIZE); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals( datasetList.toArray(), Iterables.toArray(page.getValues(), DatasetInfo.class)); + verify(bigqueryRpcMock).listDatasets(PROJECT, DATASET_LIST_OPTIONS); } @Test public void testDeleteDataset() { - EasyMock.expect(bigqueryRpcMock.deleteDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(DATASET)); + verify(bigqueryRpcMock).deleteDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testDeleteDatasetFromDatasetId() { - EasyMock.expect(bigqueryRpcMock.deleteDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(DatasetId.of(DATASET))); + verify(bigqueryRpcMock).deleteDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testDeleteDatasetFromDatasetIdWithProject() { DatasetId datasetId = DatasetId.of(OTHER_PROJECT, DATASET); - EasyMock.expect(bigqueryRpcMock.deleteDataset(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteDataset(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(datasetId)); + verify(bigqueryRpcMock).deleteDataset(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testDeleteDatasetWithOptions() { - EasyMock.expect(bigqueryRpcMock.deleteDataset(PROJECT, DATASET, DATASET_DELETE_OPTIONS)) - .andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteDataset(PROJECT, DATASET, DATASET_DELETE_OPTIONS)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(DATASET, DATASET_DELETE_CONTENTS)); + verify(bigqueryRpcMock).deleteDataset(PROJECT, DATASET, DATASET_DELETE_OPTIONS); } @Test @@ -702,26 +693,22 @@ public void testUpdateDataset() { .toBuilder() .setDescription("newDescription") .build(); - EasyMock.expect(bigqueryRpcMock.patch(updatedDatasetInfo.toPb(), EMPTY_RPC_OPTIONS)) - .andReturn(updatedDatasetInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.patch(updatedDatasetInfo.toPb(), EMPTY_RPC_OPTIONS)) + .thenReturn(updatedDatasetInfo.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.update(updatedDatasetInfo); assertEquals(new Dataset(bigquery, new DatasetInfo.BuilderImpl(updatedDatasetInfo)), dataset); + verify(bigqueryRpcMock).patch(updatedDatasetInfo.toPb(), EMPTY_RPC_OPTIONS); } @Test public void testUpdateDatasetWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); DatasetInfo updatedDatasetInfo = DATASET_INFO.toBuilder().setDescription("newDescription").build(); DatasetInfo updatedDatasetInfoWithProject = DATASET_INFO_WITH_PROJECT.toBuilder().setDescription("newDescription").build(); - EasyMock.expect( - bigqueryRpcMock.patch( - eq(updatedDatasetInfoWithProject.toPb()), capture(capturedOptions))) - .andReturn(updatedDatasetInfoWithProject.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.patch(eq(updatedDatasetInfoWithProject.toPb()), capturedOptions.capture())) + .thenReturn(updatedDatasetInfoWithProject.toPb()); bigquery = options.getService(); Dataset dataset = bigquery.update(updatedDatasetInfo, DATASET_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(DATASET_OPTION_FIELDS.getRpcOption()); @@ -731,19 +718,20 @@ public void testUpdateDatasetWithSelectedFields() { assertEquals(28, selector.length()); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(updatedDatasetInfoWithProject)), dataset); + verify(bigqueryRpcMock) + .patch(eq(updatedDatasetInfoWithProject.toPb()), capturedOptions.capture()); } @Test public void testCreateTable() { TableInfo tableInfo = TABLE_INFO.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.create(tableInfo.toPb(), EMPTY_RPC_OPTIONS)) - .andReturn(tableInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(tableInfo.toPb(), EMPTY_RPC_OPTIONS)).thenReturn(tableInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.create(tableInfo); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table); + verify(bigqueryRpcMock).create(tableInfo.toPb(), EMPTY_RPC_OPTIONS); } @Test @@ -751,22 +739,18 @@ public void testCreateTableWithoutProject() { TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT); TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable()); tableInfo.toBuilder().setTableId(tableId); - EasyMock.expect(bigqueryRpcMock.create(tableInfo.toPb(), EMPTY_RPC_OPTIONS)) - .andReturn(tableInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(tableInfo.toPb(), EMPTY_RPC_OPTIONS)).thenReturn(tableInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.create(tableInfo); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table); + verify(bigqueryRpcMock).create(tableInfo.toPb(), EMPTY_RPC_OPTIONS); } @Test public void testCreateTableWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect( - bigqueryRpcMock.create(eq(TABLE_INFO_WITH_PROJECT.toPb()), capture(capturedOptions))) - .andReturn(TABLE_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(eq(TABLE_INFO_WITH_PROJECT.toPb()), capturedOptions.capture())) + .thenReturn(TABLE_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Table table = bigquery.create(TABLE_INFO, TABLE_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(TABLE_OPTION_FIELDS.getRpcOption()); @@ -775,59 +759,59 @@ public void testCreateTableWithSelectedFields() { assertTrue(selector.contains("etag")); assertEquals(31, selector.length()); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), table); + verify(bigqueryRpcMock).create(eq(TABLE_INFO_WITH_PROJECT.toPb()), capturedOptions.capture()); } @Test public void testGetTable() { - EasyMock.expect(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Table table = bigquery.getTable(DATASET, TABLE); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), table); + verify(bigqueryRpcMock).getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testGetModel() { - EasyMock.expect(bigqueryRpcMock.getModel(PROJECT, DATASET, MODEL, EMPTY_RPC_OPTIONS)) - .andReturn(MODEL_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getModel(PROJECT, DATASET, MODEL, EMPTY_RPC_OPTIONS)) + .thenReturn(MODEL_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Model model = bigquery.getModel(DATASET, MODEL); assertEquals(new Model(bigquery, new ModelInfo.BuilderImpl(MODEL_INFO_WITH_PROJECT)), model); + verify(bigqueryRpcMock).getModel(PROJECT, DATASET, MODEL, EMPTY_RPC_OPTIONS); } @Test public void testListPartition() { - EasyMock.expect( - bigqueryRpcMock.getTable( - PROJECT, DATASET, "table$__PARTITIONS_SUMMARY__", EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_INFO_PARTITIONS.toPb()); - EasyMock.expect(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_DATA_WITH_PARTITIONS); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable( + PROJECT, DATASET, "table$__PARTITIONS_SUMMARY__", EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_INFO_PARTITIONS.toPb()); + when(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_DATA_WITH_PARTITIONS); bigquery = options.getService(); List partition = bigquery.listPartitions(TABLE_ID_WITH_PROJECT); assertEquals(3, partition.size()); + verify(bigqueryRpcMock) + .getTable(PROJECT, DATASET, "table$__PARTITIONS_SUMMARY__", EMPTY_RPC_OPTIONS); + verify(bigqueryRpcMock).listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testGetTableNotFoundWhenThrowIsDisabled() { - EasyMock.expect(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_INFO_WITH_PROJECT.toPb()); options.setThrowNotFound(false); bigquery = options.getService(); Table table = bigquery.getTable(DATASET, TABLE); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), table); + verify(bigqueryRpcMock).getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testGetTableNotFoundWhenThrowIsEnabled() { - EasyMock.expect( - bigqueryRpcMock.getTable(PROJECT, DATASET, "table-not-found", EMPTY_RPC_OPTIONS)) - .andThrow(new BigQueryException(404, "Table not found")); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(PROJECT, DATASET, "table-not-found", EMPTY_RPC_OPTIONS)) + .thenThrow(new BigQueryException(404, "Table not found")); options.setThrowNotFound(true); bigquery = options.getService(); try { @@ -836,52 +820,50 @@ public void testGetTableNotFoundWhenThrowIsEnabled() { } catch (BigQueryException ex) { Assert.assertNotNull(ex.getMessage()); } + verify(bigqueryRpcMock).getTable(PROJECT, DATASET, "table-not-found", EMPTY_RPC_OPTIONS); } @Test public void testGetTableFromTableId() { - EasyMock.expect(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Table table = bigquery.getTable(TABLE_ID); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), table); + verify(bigqueryRpcMock).getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testGetTableFromTableIdWithProject() { TableInfo tableInfo = TABLE_INFO.setProjectId(OTHER_PROJECT); TableId tableId = TABLE_ID.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.getTable(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(tableInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(tableInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.getTable(tableId); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table); + verify(bigqueryRpcMock).getTable(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testGetTableFromTableIdWithoutProject() { TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT); TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable()); - EasyMock.expect(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(tableInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(tableInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.getTable(tableId); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table); + verify(bigqueryRpcMock).getTable(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testGetTableWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect( - bigqueryRpcMock.getTable(eq(PROJECT), eq(DATASET), eq(TABLE), capture(capturedOptions))) - .andReturn(TABLE_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getTable(eq(PROJECT), eq(DATASET), eq(TABLE), capturedOptions.capture())) + .thenReturn(TABLE_INFO_WITH_PROJECT.toPb()); bigquery = options.getService(); Table table = bigquery.getTable(TABLE_ID, TABLE_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(TABLE_OPTION_FIELDS.getRpcOption()); @@ -890,6 +872,8 @@ public void testGetTableWithSelectedFields() { assertTrue(selector.contains("etag")); assertEquals(31, selector.length()); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), table); + verify(bigqueryRpcMock) + .getTable(eq(PROJECT), eq(DATASET), eq(TABLE), capturedOptions.capture()); } @Test @@ -902,12 +886,11 @@ public void testListTables() { new Table(bigquery, new TableInfo.BuilderImpl(MODEL_TABLE_INFO_WITH_PROJECT))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(result); Page page = bigquery.listTables(DATASET); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test @@ -918,12 +901,11 @@ public void testListTablesReturnedParameters() { new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)).thenReturn(result); Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS); } @Test @@ -934,12 +916,11 @@ public void testListTablesReturnedParametersNullType() { new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS_NULL_TYPE))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)).thenReturn(result); Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS); } @Test @@ -950,12 +931,11 @@ public void testListTablesWithRangePartitioning() { new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_RANGE_PARTITIONING))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)).thenReturn(result); Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS); } @Test @@ -967,12 +947,11 @@ public void testListTablesFromDatasetId() { new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(result); Page
page = bigquery.listTables(DatasetId.of(DATASET)); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test @@ -983,12 +962,11 @@ public void testListTablesFromDatasetIdWithProject() { new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO.setProjectId(OTHER_PROJECT)))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(result); Page
page = bigquery.listTables(DatasetId.of(OTHER_PROJECT, DATASET)); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test @@ -1000,12 +978,11 @@ public void testListTablesWithOptions() { new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS)).thenReturn(result); Page
page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class)); + verify(bigqueryRpcMock).listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS); } @Test @@ -1017,71 +994,70 @@ public void testListModels() { new Model(bigquery, new ModelInfo.BuilderImpl(OTHER_MODEL_INFO))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(modelList, ModelInfo.TO_PB_FUNCTION)); - EasyMock.expect(bigqueryRpcMock.listModels(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listModels(PROJECT, DATASET, EMPTY_RPC_OPTIONS)).thenReturn(result); Page page = bigquery.listModels(DATASET); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(modelList.toArray(), Iterables.toArray(page.getValues(), Model.class)); + verify(bigqueryRpcMock).listModels(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testDeleteTable() { - EasyMock.expect(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(TABLE_ID)); + verify(bigqueryRpcMock).deleteTable(PROJECT, DATASET, TABLE); } @Test public void testDeleteTableFromTableId() { - EasyMock.expect(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(TABLE_ID)); + verify(bigqueryRpcMock).deleteTable(PROJECT, DATASET, TABLE); } @Test public void testDeleteTableFromTableIdWithProject() { TableId tableId = TABLE_ID.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.deleteTable(OTHER_PROJECT, DATASET, TABLE)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteTable(OTHER_PROJECT, DATASET, TABLE)).thenReturn(true); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); assertTrue(bigquery.delete(tableId)); + verify(bigqueryRpcMock).deleteTable(OTHER_PROJECT, DATASET, TABLE); } @Test public void testDeleteTableFromTableIdWithoutProject() { TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable()); - EasyMock.expect(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteTable(PROJECT, DATASET, TABLE)).thenReturn(true); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); assertTrue(bigquery.delete(tableId)); + verify(bigqueryRpcMock).deleteTable(PROJECT, DATASET, TABLE); } @Test public void testDeleteModel() { - EasyMock.expect(bigqueryRpcMock.deleteModel(PROJECT, DATASET, MODEL)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.deleteModel(PROJECT, DATASET, MODEL)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.delete(ModelId.of(DATASET, MODEL))); + verify(bigqueryRpcMock).deleteModel(PROJECT, DATASET, MODEL); } @Test public void testUpdateTable() { TableInfo updatedTableInfo = TABLE_INFO.setProjectId(OTHER_PROJECT).toBuilder().setDescription("newDescription").build(); - EasyMock.expect(bigqueryRpcMock.patch(updatedTableInfo.toPb(), EMPTY_RPC_OPTIONS)) - .andReturn(updatedTableInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.patch(updatedTableInfo.toPb(), EMPTY_RPC_OPTIONS)) + .thenReturn(updatedTableInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.update(updatedTableInfo); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(updatedTableInfo)), table); + verify(bigqueryRpcMock).patch(updatedTableInfo.toPb(), EMPTY_RPC_OPTIONS); } @Test @@ -1089,25 +1065,21 @@ public void testUpdateTableWithoutProject() { TableInfo tableInfo = TABLE_INFO.setProjectId(PROJECT); TableId tableId = TableId.of("", TABLE_ID.getDataset(), TABLE_ID.getTable()); tableInfo.toBuilder().setTableId(tableId); - EasyMock.expect(bigqueryRpcMock.patch(tableInfo.toPb(), EMPTY_RPC_OPTIONS)) - .andReturn(tableInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.patch(tableInfo.toPb(), EMPTY_RPC_OPTIONS)).thenReturn(tableInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Table table = bigquery.update(tableInfo); assertEquals(new Table(bigquery, new TableInfo.BuilderImpl(tableInfo)), table); + verify(bigqueryRpcMock).patch(tableInfo.toPb(), EMPTY_RPC_OPTIONS); } @Test public void testUpdateTableWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); TableInfo updatedTableInfo = TABLE_INFO.toBuilder().setDescription("newDescription").build(); TableInfo updatedTableInfoWithProject = TABLE_INFO_WITH_PROJECT.toBuilder().setDescription("newDescription").build(); - EasyMock.expect( - bigqueryRpcMock.patch(eq(updatedTableInfoWithProject.toPb()), capture(capturedOptions))) - .andReturn(updatedTableInfoWithProject.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.patch(eq(updatedTableInfoWithProject.toPb()), capturedOptions.capture())) + .thenReturn(updatedTableInfoWithProject.toPb()); bigquery = options.getService(); Table table = bigquery.update(updatedTableInfo, TABLE_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(TABLE_OPTION_FIELDS.getRpcOption()); @@ -1117,6 +1089,8 @@ public void testUpdateTableWithSelectedFields() { assertEquals(31, selector.length()); assertEquals( new Table(bigquery, new TableInfo.BuilderImpl(updatedTableInfoWithProject)), table); + verify(bigqueryRpcMock) + .patch(eq(updatedTableInfoWithProject.toPb()), capturedOptions.capture()); } @Test @@ -1155,11 +1129,9 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { new TableDataInsertAllResponse.InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage"))))); - EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) - .andThrow(new BigQueryException(500, "InternalError")); - EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) - .andReturn(responsePb); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) + .thenThrow(new BigQueryException(500, "InternalError")) + .thenReturn(responsePb); bigquery = options .toBuilder() @@ -1171,6 +1143,7 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { assertNull(response.getErrorsFor(1L)); assertEquals(1, response.getErrorsFor(0L).size()); assertEquals("ErrorMessage", response.getErrorsFor(0L).get(0).getMessage()); + verify(bigqueryRpcMock, times(2)).insertAll(PROJECT, DATASET, TABLE, requestPb); } @Test @@ -1201,9 +1174,8 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { .setSkipInvalidRows(false) .setIgnoreUnknownValues(true) .setTemplateSuffix("suffix"); - EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) - .andThrow(new BigQueryException(500, "InternalError")); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) + .thenThrow(new BigQueryException(500, "InternalError")); bigquery = options .toBuilder() @@ -1216,6 +1188,7 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { } catch (BigQueryException ex) { Assert.assertNotNull(ex.getMessage()); } + verify(bigqueryRpcMock).insertAll(PROJECT, DATASET, TABLE, requestPb); } @Test @@ -1255,9 +1228,8 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { new TableDataInsertAllResponse.InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage"))))); - EasyMock.expect(bigqueryRpcMock.insertAll(OTHER_PROJECT, DATASET, TABLE, requestPb)) - .andReturn(responsePb); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.insertAll(OTHER_PROJECT, DATASET, TABLE, requestPb)) + .thenReturn(responsePb); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); @@ -1266,6 +1238,7 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { assertNull(response.getErrorsFor(1L)); assertEquals(1, response.getErrorsFor(0L).size()); assertEquals("ErrorMessage", response.getErrorsFor(0L).get(0).getMessage()); + verify(bigqueryRpcMock).insertAll(OTHER_PROJECT, DATASET, TABLE, requestPb); } @Test @@ -1305,10 +1278,8 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { new TableDataInsertAllResponse.InsertErrors() .setIndex(0L) .setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage"))))); - EasyMock.expect( - bigqueryRpcMock.insertAll("project-different-from-option", DATASET, TABLE, requestPb)) - .andReturn(responsePb); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.insertAll("project-different-from-option", DATASET, TABLE, requestPb)) + .thenReturn(responsePb); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); @@ -1317,48 +1288,48 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) { assertNull(response.getErrorsFor(1L)); assertEquals(1, response.getErrorsFor(0L).size()); assertEquals("ErrorMessage", response.getErrorsFor(0L).get(0).getMessage()); + verify(bigqueryRpcMock).insertAll("project-different-from-option", DATASET, TABLE, requestPb); } @Test public void testListTableData() { - EasyMock.expect(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_DATA_PB); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_DATA_PB); bigquery = options.getService(); Page page = bigquery.listTableData(DATASET, TABLE); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class)); + verify(bigqueryRpcMock).listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testListTableDataFromTableId() { - EasyMock.expect(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_DATA_PB); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_DATA_PB); bigquery = options.getService(); Page page = bigquery.listTableData(TableId.of(DATASET, TABLE)); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class)); + verify(bigqueryRpcMock).listTableData(PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testListTableDataFromTableIdWithProject() { TableId tableId = TABLE_ID.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.listTableData(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) - .andReturn(TABLE_DATA_PB); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTableData(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS)) + .thenReturn(TABLE_DATA_PB); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Page page = bigquery.listTableData(tableId); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class)); + verify(bigqueryRpcMock).listTableData(OTHER_PROJECT, DATASET, TABLE, EMPTY_RPC_OPTIONS); } @Test public void testListTableDataWithOptions() { - EasyMock.expect(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, TABLE_DATA_LIST_OPTIONS)) - .andReturn(TABLE_DATA_PB); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, TABLE_DATA_LIST_OPTIONS)) + .thenReturn(TABLE_DATA_PB); bigquery = options.getService(); Page page = bigquery.listTableData( @@ -1369,6 +1340,7 @@ public void testListTableDataWithOptions() { TABLE_DATA_LIST_START_INDEX); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class)); + verify(bigqueryRpcMock).listTableData(PROJECT, DATASET, TABLE, TABLE_DATA_LIST_OPTIONS); } // The "minimally initialized" Job that lets Job.fromPb run without throwing. @@ -1385,26 +1357,20 @@ public void testCreateJobSuccess() { JobId jobId = JobId.of(id); String query = "SELECT * in FOO"; - Capture jobCapture = EasyMock.newCapture(); - EasyMock.expect( - bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS))) - .andReturn(newJobPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS))) + .thenReturn(newJobPb()); bigquery = options.getService(); assertThat(bigquery.create(JobInfo.of(jobId, QueryJobConfiguration.of(query)))).isNotNull(); assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id); + verify(bigqueryRpcMock).create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS)); } @Test public void testCreateJobWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect( - bigqueryRpcMock.create( - EasyMock.anyObject(com.google.api.services.bigquery.model.Job.class), - EasyMock.capture(capturedOptions))) - .andReturn(newJobPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create( + any(com.google.api.services.bigquery.model.Job.class), capturedOptions.capture())) + .thenReturn(newJobPb()); BigQuery.JobOption jobOptions = BigQuery.JobOption.fields(BigQuery.JobField.USER_EMAIL); @@ -1416,6 +1382,8 @@ public void testCreateJobWithSelectedFields() { assertThat(selector.split(",")) .asList() .containsExactly("jobReference", "configuration", "user_email"); + verify(bigqueryRpcMock) + .create(any(com.google.api.services.bigquery.model.Job.class), capturedOptions.capture()); } @Test @@ -1424,11 +1392,8 @@ public void testCreateJobNoGet() { JobId jobId = JobId.of(id); String query = "SELECT * in FOO"; - Capture jobCapture = EasyMock.newCapture(); - EasyMock.expect( - bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS))) - .andThrow(new BigQueryException(409, "already exists, for some reason")); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS))) + .thenThrow(new BigQueryException(409, "already exists, for some reason")); bigquery = options.getService(); try { @@ -1437,6 +1402,7 @@ public void testCreateJobNoGet() { } catch (BigQueryException e) { assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id); } + verify(bigqueryRpcMock).create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS)); } @Test @@ -1451,22 +1417,18 @@ public JobId get() { } }; - Capture jobCapture = EasyMock.newCapture(); - EasyMock.expect( - bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS))) - .andThrow(new BigQueryException(409, "already exists, for some reason")); - EasyMock.expect( - bigqueryRpcMock.getJob( - anyString(), - EasyMock.eq(id), - EasyMock.eq((String) null), - EasyMock.eq(EMPTY_RPC_OPTIONS))) - .andReturn(newJobPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS))) + .thenThrow(new BigQueryException(409, "already exists, for some reason")); + when(bigqueryRpcMock.getJob( + any(String.class), eq(id), eq((String) null), eq(EMPTY_RPC_OPTIONS))) + .thenReturn(newJobPb()); bigquery = options.getService(); ((BigQueryImpl) bigquery).create(JobInfo.of(QueryJobConfiguration.of(query)), idProvider); assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id); + verify(bigqueryRpcMock).create(jobCapture.capture(), eq(EMPTY_RPC_OPTIONS)); + verify(bigqueryRpcMock) + .getJob(any(String.class), eq(id), eq((String) null), eq(EMPTY_RPC_OPTIONS)); } @Test @@ -1475,10 +1437,8 @@ public void testCreateJobWithProjectId() { JobInfo.newBuilder(QUERY_JOB_CONFIGURATION.setProjectId(OTHER_PROJECT)) .setJobId(JobId.of(OTHER_PROJECT, JOB)) .build(); - Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(bigqueryRpcMock.create(eq(jobInfo.toPb()), capture(capturedOptions))) - .andReturn(jobInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.create(eq(jobInfo.toPb()), capturedOptions.capture())) + .thenReturn(jobInfo.toPb()); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); @@ -1489,45 +1449,45 @@ public void testCreateJobWithProjectId() { assertTrue(selector.contains("configuration")); assertTrue(selector.contains("user_email")); assertEquals(37, selector.length()); + verify(bigqueryRpcMock).create(eq(jobInfo.toPb()), capturedOptions.capture()); } @Test public void testGetJob() { - EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) - .andReturn(COMPLETE_COPY_JOB.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) + .thenReturn(COMPLETE_COPY_JOB.toPb()); bigquery = options.getService(); Job job = bigquery.getJob(JOB); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_COPY_JOB)), job); + verify(bigqueryRpcMock).getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS); } @Test public void testGetJobWithLocation() { - EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS)) - .andReturn(COMPLETE_COPY_JOB.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS)) + .thenReturn(COMPLETE_COPY_JOB.toPb()); BigQueryOptions options = createBigQueryOptionsForProjectWithLocation(PROJECT, rpcFactoryMock); bigquery = options.getService(); Job job = bigquery.getJob(JOB); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_COPY_JOB)), job); + verify(bigqueryRpcMock).getJob(PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS); } @Test public void testGetJobNotFoundWhenThrowIsDisabled() { - EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) - .andReturn(COMPLETE_COPY_JOB.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) + .thenReturn(COMPLETE_COPY_JOB.toPb()); options.setThrowNotFound(false); bigquery = options.getService(); Job job = bigquery.getJob(JOB); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_COPY_JOB)), job); + verify(bigqueryRpcMock).getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS); } @Test public void testGetJobNotFoundWhenThrowIsEnabled() { - EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, "job-not-found", null, EMPTY_RPC_OPTIONS)) - .andThrow(new BigQueryException(404, "Job not found")); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(PROJECT, "job-not-found", null, EMPTY_RPC_OPTIONS)) + .thenThrow(new BigQueryException(404, "Job not found")); options.setThrowNotFound(true); bigquery = options.getService(); try { @@ -1536,52 +1496,53 @@ public void testGetJobNotFoundWhenThrowIsEnabled() { } catch (BigQueryException ex) { Assert.assertNotNull(ex.getMessage()); } + verify(bigqueryRpcMock).getJob(PROJECT, "job-not-found", null, EMPTY_RPC_OPTIONS); } @Test public void testGetJobFromJobId() { - EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) - .andReturn(COMPLETE_COPY_JOB.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) + .thenReturn(COMPLETE_COPY_JOB.toPb()); bigquery = options.getService(); Job job = bigquery.getJob(JobId.of(JOB)); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_COPY_JOB)), job); + verify(bigqueryRpcMock).getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS); } @Test public void testGetJobFromJobIdWithLocation() { - EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS)) - .andReturn(COMPLETE_COPY_JOB.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS)) + .thenReturn(COMPLETE_COPY_JOB.toPb()); BigQueryOptions options = createBigQueryOptionsForProjectWithLocation(PROJECT, rpcFactoryMock); bigquery = options.getService(); Job job = bigquery.getJob(JobId.of(JOB)); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_COPY_JOB)), job); + verify(bigqueryRpcMock).getJob(PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS); } @Test public void testGetJobFromJobIdWithProject() { JobId jobId = JobId.of(OTHER_PROJECT, JOB); JobInfo jobInfo = COPY_JOB.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.getJob(OTHER_PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) - .andReturn(jobInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(OTHER_PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) + .thenReturn(jobInfo.toPb()); bigquery = options.getService(); Job job = bigquery.getJob(jobId); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(jobInfo)), job); + verify(bigqueryRpcMock).getJob(OTHER_PROJECT, JOB, null, EMPTY_RPC_OPTIONS); } @Test public void testGetJobFromJobIdWithProjectWithLocation() { JobId jobId = JobId.of(OTHER_PROJECT, JOB); JobInfo jobInfo = COPY_JOB.setProjectId(OTHER_PROJECT); - EasyMock.expect(bigqueryRpcMock.getJob(OTHER_PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS)) - .andReturn(jobInfo.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getJob(OTHER_PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS)) + .thenReturn(jobInfo.toPb()); BigQueryOptions options = createBigQueryOptionsForProjectWithLocation(PROJECT, rpcFactoryMock); bigquery = options.getService(); Job job = bigquery.getJob(jobId); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(jobInfo)), job); + verify(bigqueryRpcMock).getJob(OTHER_PROJECT, JOB, LOCATION, EMPTY_RPC_OPTIONS); } @Test @@ -1602,11 +1563,11 @@ public com.google.api.services.bigquery.model.Job apply(Job job) { return job.toPb(); } })); - EasyMock.expect(bigqueryRpcMock.listJobs(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listJobs(PROJECT, EMPTY_RPC_OPTIONS)).thenReturn(result); Page page = bigquery.listJobs(); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class)); + verify(bigqueryRpcMock).listJobs(PROJECT, EMPTY_RPC_OPTIONS); } @Test @@ -1627,18 +1588,17 @@ public com.google.api.services.bigquery.model.Job apply(Job job) { return job.toPb(); } })); - EasyMock.expect(bigqueryRpcMock.listJobs(PROJECT, JOB_LIST_OPTIONS)).andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listJobs(PROJECT, JOB_LIST_OPTIONS)).thenReturn(result); Page page = bigquery.listJobs( JOB_LIST_ALL_USERS, JOB_LIST_STATE_FILTER, JOB_LIST_PAGE_TOKEN, JOB_LIST_PAGE_SIZE); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class)); + verify(bigqueryRpcMock).listJobs(PROJECT, JOB_LIST_OPTIONS); } @Test public void testListJobsWithSelectedFields() { - Capture> capturedOptions = Capture.newInstance(); bigquery = options.getService(); ImmutableList jobList = ImmutableList.of( @@ -1655,9 +1615,7 @@ public com.google.api.services.bigquery.model.Job apply(Job job) { return job.toPb(); } })); - EasyMock.expect(bigqueryRpcMock.listJobs(eq(PROJECT), capture(capturedOptions))) - .andReturn(result); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.listJobs(eq(PROJECT), capturedOptions.capture())).thenReturn(result); Page page = bigquery.listJobs(JOB_LIST_OPTION_FIELD); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class)); @@ -1670,31 +1628,32 @@ public com.google.api.services.bigquery.model.Job apply(Job job) { assertTrue(selector.contains("errorResult")); assertTrue(selector.contains(")")); assertEquals(75, selector.length()); + verify(bigqueryRpcMock).listJobs(eq(PROJECT), capturedOptions.capture()); } @Test public void testCancelJob() { - EasyMock.expect(bigqueryRpcMock.cancel(PROJECT, JOB, null)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.cancel(PROJECT, JOB, null)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.cancel(JOB)); + verify(bigqueryRpcMock).cancel(PROJECT, JOB, null); } @Test public void testCancelJobFromJobId() { - EasyMock.expect(bigqueryRpcMock.cancel(PROJECT, JOB, null)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.cancel(PROJECT, JOB, null)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.cancel(JobId.of(PROJECT, JOB))); + verify(bigqueryRpcMock).cancel(PROJECT, JOB, null); } @Test public void testCancelJobFromJobIdWithProject() { JobId jobId = JobId.of(OTHER_PROJECT, JOB); - EasyMock.expect(bigqueryRpcMock.cancel(OTHER_PROJECT, JOB, null)).andReturn(true); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.cancel(OTHER_PROJECT, JOB, null)).thenReturn(true); bigquery = options.getService(); assertTrue(bigquery.cancel(jobId)); + verify(bigqueryRpcMock).cancel(OTHER_PROJECT, JOB, null); } @Test @@ -1718,24 +1677,20 @@ public void testQueryRequestCompleted() throws InterruptedException { .setTotalRows(BigInteger.valueOf(1L)) .setSchema(TABLE_SCHEMA.toPb()); - EasyMock.expect( - bigqueryRpcMock.create( - JOB_INFO.toPb(), Collections.emptyMap())) - .andReturn(jobResponsePb); - EasyMock.expect( - bigqueryRpcMock.getQueryResults( - PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) - .andReturn(responsePb); - EasyMock.expect( - bigqueryRpcMock.listTableData( - PROJECT, DATASET, TABLE, Collections.emptyMap())) - .andReturn( + when(bigqueryRpcMock.create( + JOB_INFO.toPb(), Collections.emptyMap())) + .thenReturn(jobResponsePb); + when(bigqueryRpcMock.getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) + .thenReturn(responsePb); + when(bigqueryRpcMock.listTableData( + PROJECT, DATASET, TABLE, Collections.emptyMap())) + .thenReturn( new TableDataList() .setPageToken("") .setRows(ImmutableList.of(TABLE_ROW)) .setTotalRows(1L)); - EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); TableResult result = bigquery.query(QUERY_JOB_CONFIGURATION_FOR_QUERY, queryJob); assertThat(result.getSchema()).isEqualTo(TABLE_SCHEMA); @@ -1744,6 +1699,14 @@ public void testQueryRequestCompleted() throws InterruptedException { assertThat(row.get(0).getBooleanValue()).isFalse(); assertThat(row.get(1).getLongValue()).isEqualTo(1); } + verify(bigqueryRpcMock) + .create(JOB_INFO.toPb(), Collections.emptyMap()); + verify(bigqueryRpcMock) + .getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS)); + + verify(bigqueryRpcMock) + .listTableData(PROJECT, DATASET, TABLE, Collections.emptyMap()); } @Test @@ -1767,27 +1730,24 @@ public void testQueryRequestCompletedOptions() throws InterruptedException { .setTotalRows(BigInteger.valueOf(1L)) .setSchema(TABLE_SCHEMA.toPb()); - EasyMock.expect( - bigqueryRpcMock.create( - JOB_INFO.toPb(), Collections.emptyMap())) - .andReturn(jobResponsePb); + when(bigqueryRpcMock.create( + JOB_INFO.toPb(), Collections.emptyMap())) + .thenReturn(jobResponsePb); Map optionMap = Maps.newEnumMap(BigQueryRpc.Option.class); QueryResultsOption pageSizeOption = QueryResultsOption.pageSize(42L); optionMap.put(pageSizeOption.getRpcOption(), pageSizeOption.getValue()); - EasyMock.expect( - bigqueryRpcMock.getQueryResults( - PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) - .andReturn(responsePb); - EasyMock.expect(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, optionMap)) - .andReturn( + when(bigqueryRpcMock.getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) + .thenReturn(responsePb); + when(bigqueryRpcMock.listTableData(PROJECT, DATASET, TABLE, optionMap)) + .thenReturn( new TableDataList() .setPageToken("") .setRows(ImmutableList.of(TABLE_ROW)) .setTotalRows(1L)); - EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); Job job = bigquery.create(JobInfo.of(queryJob, QUERY_JOB_CONFIGURATION_FOR_QUERY)); TableResult result = job.getQueryResults(pageSizeOption); @@ -1797,6 +1757,12 @@ public void testQueryRequestCompletedOptions() throws InterruptedException { assertThat(row.get(0).getBooleanValue()).isFalse(); assertThat(row.get(1).getLongValue()).isEqualTo(1); } + verify(bigqueryRpcMock) + .create(JOB_INFO.toPb(), Collections.emptyMap()); + verify(bigqueryRpcMock) + .getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS)); + verify(bigqueryRpcMock).listTableData(PROJECT, DATASET, TABLE, optionMap); } @Test @@ -1807,6 +1773,8 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti .setConfiguration(QUERY_JOB_CONFIGURATION_FOR_QUERY.toPb()) .setJobReference(queryJob.toPb()) .setId(JOB); + jobResponsePb1.setStatus( + new com.google.api.services.bigquery.model.JobStatus().setState("DONE")); jobResponsePb1.getConfiguration().getQuery().setDestinationTable(TABLE_ID.toPb()); GetQueryResultsResponse responsePb1 = @@ -1823,31 +1791,23 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti .setTotalRows(BigInteger.valueOf(1L)) .setSchema(TABLE_SCHEMA.toPb()); - EasyMock.expect( - bigqueryRpcMock.create( - JOB_INFO.toPb(), Collections.emptyMap())) - .andReturn(jobResponsePb1); - EasyMock.expect(bigqueryRpcMock.getJob(eq(PROJECT), eq(JOB), anyString(), anyObject(Map.class))) - .andReturn(jobResponsePb1); - - EasyMock.expect( - bigqueryRpcMock.getQueryResults( - PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) - .andReturn(responsePb1); - EasyMock.expect( - bigqueryRpcMock.getQueryResults( - PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) - .andReturn(responsePb2); - EasyMock.expect( - bigqueryRpcMock.listTableData( - PROJECT, DATASET, TABLE, Collections.emptyMap())) - .andReturn( + when(bigqueryRpcMock.create( + JOB_INFO.toPb(), Collections.emptyMap())) + .thenReturn(jobResponsePb1); + when(bigqueryRpcMock.getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) + .thenReturn(responsePb1); + when(bigqueryRpcMock.getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS))) + .thenReturn(responsePb2); + when(bigqueryRpcMock.listTableData( + PROJECT, DATASET, TABLE, Collections.emptyMap())) + .thenReturn( new TableDataList() .setPageToken("") .setRows(ImmutableList.of(TABLE_ROW)) .setTotalRows(1L)); - EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); TableResult result = bigquery.query(QUERY_JOB_CONFIGURATION_FOR_QUERY, queryJob); assertThat(result.getSchema()).isEqualTo(TABLE_SCHEMA); @@ -1856,6 +1816,16 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti assertThat(row.get(0).getBooleanValue()).isFalse(); assertThat(row.get(1).getLongValue()).isEqualTo(1); } + verify(bigqueryRpcMock) + .create(JOB_INFO.toPb(), Collections.emptyMap()); + verify(bigqueryRpcMock) + .getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS)); + verify(bigqueryRpcMock) + .getQueryResults( + PROJECT, JOB, null, BigQueryImpl.optionMap(Job.DEFAULT_QUERY_WAIT_OPTIONS)); + verify(bigqueryRpcMock) + .listTableData(PROJECT, DATASET, TABLE, Collections.emptyMap()); } @Test @@ -1871,13 +1841,13 @@ public void testGetQueryResults() { .setPageToken(CURSOR) .setTotalBytesProcessed(42L) .setTotalRows(BigInteger.valueOf(1L)); - EasyMock.expect(bigqueryRpcMock.getQueryResults(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) - .andReturn(responsePb); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getQueryResults(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) + .thenReturn(responsePb); bigquery = options.getService(); QueryResponse response = bigquery.getQueryResults(queryJob); assertEquals(true, response.getCompleted()); assertEquals(null, response.getSchema()); + verify(bigqueryRpcMock).getQueryResults(PROJECT, JOB, null, EMPTY_RPC_OPTIONS); } @Test @@ -1893,13 +1863,13 @@ public void testGetQueryResultsWithProject() { .setPageToken(CURSOR) .setTotalBytesProcessed(42L) .setTotalRows(BigInteger.valueOf(1L)); - EasyMock.expect(bigqueryRpcMock.getQueryResults(OTHER_PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) - .andReturn(responsePb); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getQueryResults(OTHER_PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) + .thenReturn(responsePb); bigquery = options.getService(); QueryResponse response = bigquery.getQueryResults(queryJob); assertTrue(response.getCompleted()); assertEquals(null, response.getSchema()); + verify(bigqueryRpcMock).getQueryResults(OTHER_PROJECT, JOB, null, EMPTY_RPC_OPTIONS); } @Test @@ -1914,9 +1884,8 @@ public void testGetQueryResultsWithOptions() { .setPageToken(CURSOR) .setTotalBytesProcessed(42L) .setTotalRows(BigInteger.valueOf(1L)); - EasyMock.expect(bigqueryRpcMock.getQueryResults(PROJECT, JOB, null, QUERY_RESULTS_OPTIONS)) - .andReturn(responsePb); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getQueryResults(PROJECT, JOB, null, QUERY_RESULTS_OPTIONS)) + .thenReturn(responsePb); bigquery = options.getService(); QueryResponse response = bigquery.getQueryResults( @@ -1927,14 +1896,14 @@ public void testGetQueryResultsWithOptions() { QUERY_RESULTS_OPTION_PAGE_TOKEN); assertEquals(true, response.getCompleted()); assertEquals(null, response.getSchema()); + verify(bigqueryRpcMock).getQueryResults(PROJECT, JOB, null, QUERY_RESULTS_OPTIONS); } @Test public void testRetryableException() { - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andThrow(new BigQueryException(500, "InternalError")) - .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenThrow(new BigQueryException(500, "InternalError")) + .thenReturn(DATASET_INFO_WITH_PROJECT.toPb()); bigquery = options .toBuilder() @@ -1944,35 +1913,34 @@ public void testRetryableException() { Dataset dataset = bigquery.getDataset(DATASET); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); + verify(bigqueryRpcMock, times(2)).getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andThrow(new BigQueryException(501, exceptionMessage)); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenThrow(new BigQueryException(501, exceptionMessage)); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); - try { bigquery.getDataset(DatasetId.of(DATASET)); Assert.fail(); } catch (BigQueryException ex) { Assert.assertEquals(exceptionMessage, ex.getMessage()); } + verify(bigqueryRpcMock).getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; - EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) - .andThrow(new RuntimeException(exceptionMessage)); - EasyMock.replay(bigqueryRpcMock); + when(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) + .thenThrow(new RuntimeException(exceptionMessage)); bigquery = options .toBuilder() @@ -1985,12 +1953,12 @@ public void testRuntimeException() { } catch (BigQueryException ex) { Assert.assertTrue(ex.getMessage().endsWith(exceptionMessage)); } + verify(bigqueryRpcMock).getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS); } @Test public void testQueryDryRun() throws Exception { // https://github.com/googleapis/google-cloud-java/issues/2479 - EasyMock.replay(bigqueryRpcMock); try { options .toBuilder() 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 dc57c1f9a6..4176ec24dc 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 @@ -17,17 +17,19 @@ package com.google.cloud.bigquery; import com.google.cloud.TransportOptions; -import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class BigQueryOptionsTest { @Test public void testInvalidTransport() { try { - BigQueryOptions.newBuilder() - .setTransportOptions(EasyMock.createMock(TransportOptions.class)); + BigQueryOptions.newBuilder().setTransportOptions(Mockito.mock(TransportOptions.class)); Assert.fail(); } catch (IllegalArgumentException expected) { Assert.assertNotNull(expected.getMessage()); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetTest.java index 3d82221fa4..8e783d396e 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/DatasetTest.java @@ -16,12 +16,6 @@ package com.google.cloud.bigquery; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -29,6 +23,10 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.api.gax.paging.Page; import com.google.cloud.PageImpl; @@ -37,9 +35,14 @@ import com.google.common.collect.Iterables; import java.util.List; import java.util.Map; -import org.junit.After; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.MockitoRule; +@RunWith(MockitoJUnitRunner.class) public class DatasetTest { private static final DatasetId DATASET_ID = DatasetId.of("dataset"); @@ -74,34 +77,26 @@ public class DatasetTest { private static final TableInfo TABLE_INFO3 = TableInfo.newBuilder(TableId.of("dataset", "table3"), EXTERNAL_TABLE_DEFINITION).build(); - private BigQuery serviceMockReturnsOptions = createStrictMock(BigQuery.class); - private BigQueryOptions mockOptions = createMock(BigQueryOptions.class); + @Rule public MockitoRule rule; + private BigQuery bigquery; + private BigQueryOptions mockOptions; private Dataset expectedDataset; private Dataset dataset; - private void initializeExpectedDataset(int optionsCalls) { - expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); - replay(serviceMockReturnsOptions); - bigquery = createStrictMock(BigQuery.class); - expectedDataset = new Dataset(serviceMockReturnsOptions, new Dataset.BuilderImpl(DATASET_INFO)); - } - - private void initializeDataset() { + @Before + public void setUp() { + bigquery = mock(BigQuery.class); + mockOptions = mock(BigQueryOptions.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + expectedDataset = new Dataset(bigquery, new Dataset.BuilderImpl(DATASET_INFO)); dataset = new Dataset(bigquery, new Dataset.BuilderImpl(DATASET_INFO)); } - @After - public void tearDown() throws Exception { - verify(bigquery, serviceMockReturnsOptions); - } - @Test public void testBuilder() { - initializeExpectedDataset(2); - replay(bigquery); Dataset builtDataset = - new Dataset.Builder(serviceMockReturnsOptions, DATASET_ID) + new Dataset.Builder(bigquery, DATASET_ID) .setAcl(ACCESS_RULES) .setCreationTime(CREATION_TIME) .setDefaultTableLifetime(DEFAULT_TABLE_EXPIRATION) @@ -130,242 +125,181 @@ public void testBuilder() { @Test public void testToBuilder() { - initializeExpectedDataset(4); - replay(bigquery); compareDataset(expectedDataset, expectedDataset.toBuilder().build()); } @Test - public void testExists_True() throws Exception { - initializeExpectedDataset(1); + public void testExists_True() { BigQuery.DatasetOption[] expectedOptions = {BigQuery.DatasetOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getDataset(DATASET_INFO.getDatasetId(), expectedOptions)) - .andReturn(expectedDataset); - replay(bigquery); - initializeDataset(); + when(bigquery.getDataset(DATASET_INFO.getDatasetId(), expectedOptions)) + .thenReturn(expectedDataset); assertTrue(dataset.exists()); + verify(bigquery).getDataset(DATASET_INFO.getDatasetId(), expectedOptions); } @Test - public void testExists_False() throws Exception { - initializeExpectedDataset(1); + public void testExists_False() { BigQuery.DatasetOption[] expectedOptions = {BigQuery.DatasetOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getDataset(DATASET_INFO.getDatasetId(), expectedOptions)).andReturn(null); - replay(bigquery); - initializeDataset(); + when(bigquery.getDataset(DATASET_INFO.getDatasetId(), expectedOptions)).thenReturn(null); assertFalse(dataset.exists()); + verify(bigquery).getDataset(DATASET_INFO.getDatasetId(), expectedOptions); } @Test - public void testReload() throws Exception { - initializeExpectedDataset(4); + public void testReload() { DatasetInfo updatedInfo = DATASET_INFO.toBuilder().setDescription("Description").build(); - Dataset expectedDataset = - new Dataset(serviceMockReturnsOptions, new DatasetInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getDataset(DATASET_INFO.getDatasetId().getDataset())) - .andReturn(expectedDataset); - replay(bigquery); - initializeDataset(); + Dataset expectedDataset = new Dataset(bigquery, new DatasetInfo.BuilderImpl(updatedInfo)); + when(bigquery.getDataset(DATASET_INFO.getDatasetId().getDataset())).thenReturn(expectedDataset); Dataset updatedDataset = dataset.reload(); compareDataset(expectedDataset, updatedDataset); + verify(bigquery).getDataset(DATASET_INFO.getDatasetId().getDataset()); } @Test - public void testReloadNull() throws Exception { - initializeExpectedDataset(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getDataset(DATASET_INFO.getDatasetId().getDataset())).andReturn(null); - replay(bigquery); - initializeDataset(); + public void testReloadNull() { + when(bigquery.getDataset(DATASET_INFO.getDatasetId().getDataset())).thenReturn(null); assertNull(dataset.reload()); + verify(bigquery).getDataset(DATASET_INFO.getDatasetId().getDataset()); } @Test - public void testReloadWithOptions() throws Exception { - initializeExpectedDataset(4); + public void testReloadWithOptions() { DatasetInfo updatedInfo = DATASET_INFO.toBuilder().setDescription("Description").build(); - Dataset expectedDataset = - new Dataset(serviceMockReturnsOptions, new DatasetInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect( - bigquery.getDataset( - DATASET_INFO.getDatasetId().getDataset(), BigQuery.DatasetOption.fields())) - .andReturn(expectedDataset); - replay(bigquery); - initializeDataset(); + Dataset expectedDataset = new Dataset(bigquery, new DatasetInfo.BuilderImpl(updatedInfo)); + when(bigquery.getDataset( + DATASET_INFO.getDatasetId().getDataset(), BigQuery.DatasetOption.fields())) + .thenReturn(expectedDataset); Dataset updatedDataset = dataset.reload(BigQuery.DatasetOption.fields()); compareDataset(expectedDataset, updatedDataset); + verify(bigquery) + .getDataset(DATASET_INFO.getDatasetId().getDataset(), BigQuery.DatasetOption.fields()); } @Test public void testUpdate() { - initializeExpectedDataset(4); Dataset expectedUpdatedDataset = expectedDataset.toBuilder().setDescription("Description").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedDataset))).andReturn(expectedUpdatedDataset); - replay(bigquery); - initializeDataset(); + when(bigquery.update(eq(expectedDataset))).thenReturn(expectedUpdatedDataset); Dataset actualUpdatedDataset = dataset.update(); compareDataset(expectedUpdatedDataset, actualUpdatedDataset); + verify(bigquery).update(eq(expectedDataset)); } @Test public void testUpdateWithOptions() { - initializeExpectedDataset(4); Dataset expectedUpdatedDataset = expectedDataset.toBuilder().setDescription("Description").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedDataset), eq(BigQuery.DatasetOption.fields()))) - .andReturn(expectedUpdatedDataset); - replay(bigquery); - initializeDataset(); + when(bigquery.update(eq(expectedDataset), eq(BigQuery.DatasetOption.fields()))) + .thenReturn(expectedUpdatedDataset); Dataset actualUpdatedDataset = dataset.update(BigQuery.DatasetOption.fields()); compareDataset(expectedUpdatedDataset, actualUpdatedDataset); + verify(bigquery).update(eq(expectedDataset), eq(BigQuery.DatasetOption.fields())); } @Test public void testDeleteTrue() { - initializeExpectedDataset(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(DATASET_INFO.getDatasetId())).andReturn(true); - replay(bigquery); - initializeDataset(); + when(bigquery.delete(DATASET_INFO.getDatasetId())).thenReturn(true); assertTrue(dataset.delete()); + verify(bigquery).delete(DATASET_INFO.getDatasetId()); } @Test public void testDeleteFalse() { - initializeExpectedDataset(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(DATASET_INFO.getDatasetId())).andReturn(false); - replay(bigquery); - initializeDataset(); + when(bigquery.delete(DATASET_INFO.getDatasetId())).thenReturn(false); assertFalse(dataset.delete()); + verify(bigquery).delete(DATASET_INFO.getDatasetId()); } @Test - public void testList() throws Exception { - initializeExpectedDataset(4); + public void testList() { List
tableResults = ImmutableList.of( - new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO1)), - new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO2)), - new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3))); + new Table(bigquery, new Table.BuilderImpl(TABLE_INFO1)), + new Table(bigquery, new Table.BuilderImpl(TABLE_INFO2)), + new Table(bigquery, new Table.BuilderImpl(TABLE_INFO3))); PageImpl
expectedPage = new PageImpl<>(null, "c", tableResults); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.listTables(DATASET_INFO.getDatasetId())).andReturn(expectedPage); - replay(bigquery); - initializeDataset(); + when(bigquery.listTables(DATASET_INFO.getDatasetId())).thenReturn(expectedPage); Page
tablePage = dataset.list(); assertArrayEquals( tableResults.toArray(), Iterables.toArray(tablePage.getValues(), Table.class)); assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken()); + verify(bigquery).listTables(DATASET_INFO.getDatasetId()); } @Test - public void testListWithOptions() throws Exception { - initializeExpectedDataset(4); + public void testListWithOptions() { List
tableResults = ImmutableList.of( - new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO1)), - new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO2)), - new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3))); + new Table(bigquery, new Table.BuilderImpl(TABLE_INFO1)), + new Table(bigquery, new Table.BuilderImpl(TABLE_INFO2)), + new Table(bigquery, new Table.BuilderImpl(TABLE_INFO3))); PageImpl
expectedPage = new PageImpl<>(null, "c", tableResults); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.listTables(DATASET_INFO.getDatasetId(), BigQuery.TableListOption.pageSize(10L))) - .andReturn(expectedPage); - replay(bigquery); - initializeDataset(); + when(bigquery.listTables(DATASET_INFO.getDatasetId(), BigQuery.TableListOption.pageSize(10L))) + .thenReturn(expectedPage); Page
tablePage = dataset.list(BigQuery.TableListOption.pageSize(10L)); assertArrayEquals( tableResults.toArray(), Iterables.toArray(tablePage.getValues(), Table.class)); assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken()); + verify(bigquery) + .listTables(DATASET_INFO.getDatasetId(), BigQuery.TableListOption.pageSize(10L)); } @Test - public void testGet() throws Exception { - initializeExpectedDataset(2); - Table expectedTable = - new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(TABLE_INFO1)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO1.getTableId())).andReturn(expectedTable); - replay(bigquery); - initializeDataset(); + public void testGet() { + Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO1)); + when(bigquery.getTable(TABLE_INFO1.getTableId())).thenReturn(expectedTable); Table table = dataset.get(TABLE_INFO1.getTableId().getTable()); assertNotNull(table); assertEquals(expectedTable, table); + verify(bigquery).getTable(TABLE_INFO1.getTableId()); } @Test - public void testGetNull() throws Exception { - initializeExpectedDataset(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO1.getTableId())).andReturn(null); - replay(bigquery); - initializeDataset(); + public void testGetNull() { + when(bigquery.getTable(TABLE_INFO1.getTableId())).thenReturn(null); assertNull(dataset.get(TABLE_INFO1.getTableId().getTable())); + verify(bigquery).getTable(TABLE_INFO1.getTableId()); } @Test - public void testGetWithOptions() throws Exception { - initializeExpectedDataset(2); - Table expectedTable = - new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(TABLE_INFO1)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO1.getTableId(), BigQuery.TableOption.fields())) - .andReturn(expectedTable); - replay(bigquery); - initializeDataset(); + public void testGetWithOptions() { + Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO1)); + when(bigquery.getTable(TABLE_INFO1.getTableId(), BigQuery.TableOption.fields())) + .thenReturn(expectedTable); Table table = dataset.get(TABLE_INFO1.getTableId().getTable(), BigQuery.TableOption.fields()); assertNotNull(table); assertEquals(expectedTable, table); + verify(bigquery).getTable(TABLE_INFO1.getTableId(), BigQuery.TableOption.fields()); } @Test - public void testCreateTable() throws Exception { - initializeExpectedDataset(2); - Table expectedTable = - new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(TABLE_INFO1)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.create(TABLE_INFO1)).andReturn(expectedTable); - replay(bigquery); - initializeDataset(); + public void testCreateTable() { + Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO1)); + when(bigquery.create(TABLE_INFO1)).thenReturn(expectedTable); Table table = dataset.create(TABLE_INFO1.getTableId().getTable(), TABLE_DEFINITION); assertEquals(expectedTable, table); + verify(bigquery).create(TABLE_INFO1); } @Test - public void testCreateTableWithOptions() throws Exception { - initializeExpectedDataset(2); - Table expectedTable = - new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(TABLE_INFO1)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.create(TABLE_INFO1, BigQuery.TableOption.fields())).andReturn(expectedTable); - replay(bigquery); - initializeDataset(); + public void testCreateTableWithOptions() { + Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO1)); + when(bigquery.create(TABLE_INFO1, BigQuery.TableOption.fields())).thenReturn(expectedTable); Table table = dataset.create( TABLE_INFO1.getTableId().getTable(), TABLE_DEFINITION, BigQuery.TableOption.fields()); assertEquals(expectedTable, table); + verify(bigquery).create(TABLE_INFO1, BigQuery.TableOption.fields()); } @Test public void testBigQuery() { - initializeExpectedDataset(1); - replay(bigquery); - assertSame(serviceMockReturnsOptions, expectedDataset.getBigQuery()); + assertSame(bigquery, expectedDataset.getBigQuery()); } @Test public void testToAndFromPb() { - initializeExpectedDataset(4); - replay(bigquery); - compareDataset( - expectedDataset, Dataset.fromPb(serviceMockReturnsOptions, expectedDataset.toPb())); + compareDataset(expectedDataset, Dataset.fromPb(bigquery, expectedDataset.toPb())); } private void compareDataset(Dataset expected, Dataset value) { 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 978405d09c..68ccfd6274 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 @@ -18,20 +18,18 @@ import static com.google.common.collect.ObjectArrays.concat; import static com.google.common.truth.Truth.assertThat; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import com.google.api.core.ApiClock; import com.google.api.core.CurrentMillisClock; import com.google.api.gax.paging.Page; import com.google.cloud.RetryOption; @@ -39,11 +37,16 @@ import com.google.cloud.bigquery.JobStatistics.QueryStatistics; import com.google.common.collect.ImmutableList; import java.util.Collections; -import org.junit.After; import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.MockitoRule; import org.threeten.bp.Duration; +@RunWith(MockitoJUnitRunner.class) public class JobTest { private static final JobId JOB_ID = JobId.of("project", "job"); @@ -78,42 +81,26 @@ public class JobTest { RetryOption.retryDelayMultiplier(1.0) }; - private BigQuery serviceMockReturnsOptions = createStrictMock(BigQuery.class); - private BigQueryOptions mockOptions = createMock(BigQueryOptions.class); + @Rule public MockitoRule rule; + private BigQuery bigquery; + private BigQueryOptions mockOptions; private Job expectedJob; private Job job; - private void initializeExpectedJob(int optionsCalls, JobInfo jobInfo) { - expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); - replay(serviceMockReturnsOptions); - bigquery = createStrictMock(BigQuery.class); - expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(jobInfo)); - } - - private void initializeExpectedJob(int optionsCalls) { - initializeExpectedJob(optionsCalls, JOB_INFO); - } - - private void initializeJob() { - initializeJob(JOB_INFO); - } - - private void initializeJob(JobInfo jobInfo) { - job = new Job(bigquery, new JobInfo.BuilderImpl(jobInfo)); - } - - @After - public void tearDown() throws Exception { - verify(bigquery, serviceMockReturnsOptions); + @Before + public void setUp() { + bigquery = mock(BigQuery.class); + mockOptions = mock(BigQueryOptions.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(JOB_INFO)); + job = new Job(bigquery, new JobInfo.BuilderImpl(JOB_INFO)); } @Test public void testBuilder() { - initializeExpectedJob(2); - replay(bigquery); Job builtJob = - new Job.Builder(serviceMockReturnsOptions, COPY_CONFIGURATION) + new Job.Builder(bigquery, COPY_CONFIGURATION) .setJobId(JOB_ID) .setStatistics(COPY_JOB_STATISTICS) .setJobId(JOB_ID) @@ -131,96 +118,71 @@ public void testBuilder() { assertEquals(JOB_STATUS, builtJob.getStatus()); assertEquals(COPY_CONFIGURATION, builtJob.getConfiguration()); assertEquals(COPY_JOB_STATISTICS, builtJob.getStatistics()); - assertSame(serviceMockReturnsOptions, builtJob.getBigQuery()); + assertSame(bigquery, builtJob.getBigQuery()); } @Test public void testToBuilder() { - initializeExpectedJob(4); - replay(bigquery); compareJob(expectedJob, expectedJob.toBuilder().build()); } @Test - public void testExists_True() throws Exception { - initializeExpectedJob(1); + public void testExists_True() { BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(expectedJob); - replay(bigquery); - initializeJob(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(expectedJob); assertTrue(job.exists()); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test - public void testExists_False() throws Exception { - initializeExpectedJob(1); + public void testExists_False() { BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); - replay(bigquery); - initializeJob(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null); assertFalse(job.exists()); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test - public void testIsDone_True() throws Exception { - initializeExpectedJob(2); + public void testIsDone_True() { BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - JobStatus status = createStrictMock(JobStatus.class); - expect(status.getState()).andReturn(JobStatus.State.DONE); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)) - .andReturn(expectedJob.toBuilder().setStatus(status).build()); - replay(status, bigquery); - initializeJob(); + Job job = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.DONE)).build(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(job); assertTrue(job.isDone()); - verify(status); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test - public void testIsDone_False() throws Exception { - initializeExpectedJob(2); + public void testIsDone_False() { BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - JobStatus status = createStrictMock(JobStatus.class); - expect(status.getState()).andReturn(JobStatus.State.RUNNING); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)) - .andReturn(expectedJob.toBuilder().setStatus(status).build()); - replay(status, bigquery); - initializeJob(); + Job job = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(job); assertFalse(job.isDone()); - verify(status); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test - public void testIsDone_NotExists() throws Exception { - initializeExpectedJob(1); + public void testIsDone_NotExists() { BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); - replay(bigquery); - initializeJob(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null); assertTrue(job.isDone()); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test public void testWaitFor() throws InterruptedException { - initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - JobStatus status = createStrictMock(JobStatus.class); - expect(status.getState()).andReturn(JobStatus.State.DONE); + JobStatus status = mock(JobStatus.class); + when(status.getState()).thenReturn(JobStatus.State.DONE); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() - expect(status.getState()).andReturn(JobStatus.State.DONE); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); + when(status.getState()).thenReturn(JobStatus.State.DONE); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(completedJob); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); - replay(status, bigquery, mockOptions); - initializeJob(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(completedJob); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob); assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS)); - verify(status, mockOptions); + verify(mockOptions).getClock(); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test @@ -245,11 +207,9 @@ public void testWaitForAndGetQueryResultsEmpty() throws InterruptedException { .setStatus(JOB_STATUS) .build(); - initializeExpectedJob(2, jobInfo); - JobStatus status = createStrictMock(JobStatus.class); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); - Job completedJob = expectedJob.toBuilder().setStatus(status).build(); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); + Job completedJob = + expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); QueryResponse completedQuery = QueryResponse.newBuilder() .setCompleted(true) @@ -258,17 +218,17 @@ public void testWaitForAndGetQueryResultsEmpty() throws InterruptedException { .setErrors(ImmutableList.of()) .build(); - expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) - .andReturn(completedQuery); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); - expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) - .andReturn(completedQuery); - - replay(status, bigquery, mockOptions); - initializeJob(jobInfo); + when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) + .thenReturn(completedQuery); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob); + when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) + .thenReturn(completedQuery); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob); + job = this.job.toBuilder().setConfiguration(jobConfig).build(); assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob); assertThat(job.getQueryResults().iterateAll()).isEmpty(); - verify(status, mockOptions); + verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test @@ -293,11 +253,11 @@ public void testWaitForAndGetQueryResultsEmptyWithSchema() throws InterruptedExc .setStatus(JOB_STATUS) .build(); - initializeExpectedJob(2, jobInfo); - JobStatus status = createStrictMock(JobStatus.class); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); - Job completedJob = expectedJob.toBuilder().setStatus(status).build(); + JobStatus status = mock(JobStatus.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); + Job completedJob = + expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); QueryResponse completedQuery = QueryResponse.newBuilder() .setCompleted(true) @@ -305,19 +265,17 @@ public void testWaitForAndGetQueryResultsEmptyWithSchema() throws InterruptedExc .setSchema(Schema.of(Field.of("field1", LegacySQLTypeName.BOOLEAN))) .setErrors(ImmutableList.of()) .build(); - - expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) - .andReturn(completedQuery); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); - expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) - .andReturn(completedQuery); - - replay(status, bigquery, mockOptions); - initializeJob(jobInfo); + when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) + .thenReturn(completedQuery); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob); + when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) + .thenReturn(completedQuery); + job = this.job.toBuilder().setConfiguration(jobConfig).build(); assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob); assertThat(job.getQueryResults().getSchema()) .isEqualTo(Schema.of(Field.of("field1", LegacySQLTypeName.BOOLEAN))); - verify(status, mockOptions); + verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test @@ -342,11 +300,11 @@ public void testWaitForAndGetQueryResults() throws InterruptedException { .setStatus(JOB_STATUS) .build(); - initializeExpectedJob(2, jobInfo); - JobStatus status = createStrictMock(JobStatus.class); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); - Job completedJob = expectedJob.toBuilder().setStatus(status).build(); + JobStatus status = mock(JobStatus.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); + Job completedJob = + expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); // TODO(pongad): remove when we bump gax to 1.15. Page singlePage = new Page() { @@ -384,27 +342,21 @@ public Iterable getValues() { .setErrors(ImmutableList.of()) .build(); - expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) - .andReturn(completedQuery); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); - expect(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) - .andReturn(completedQuery); - expect(bigquery.listTableData(eq(TABLE_ID1), anyObject(Schema.class))).andReturn(result); - - replay(status, bigquery, mockOptions); - initializeJob(jobInfo); + when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) + .thenReturn(completedQuery); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob); + when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS)) + .thenReturn(completedQuery); + when(bigquery.listTableData(eq(TABLE_ID1), any(Schema.class))).thenReturn(result); + job = this.job.toBuilder().setConfiguration(jobConfig).build(); assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob); assertThat(job.getQueryResults().iterateAll()).hasSize(0); - verify(status, mockOptions); + verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test public void testWaitForAndGetQueryResults_Unsupported() throws InterruptedException { - initializeExpectedJob(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - replay(bigquery, mockOptions); - initializeJob(); - try { job.getQueryResults(); Assert.fail(); @@ -415,76 +367,56 @@ public void testWaitForAndGetQueryResults_Unsupported() throws InterruptedExcept @Test public void testWaitFor_Null() throws InterruptedException { - initializeExpectedJob(1); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); - replay(bigquery, mockOptions); - initializeJob(); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null); assertNull(job.waitFor(TEST_RETRY_OPTIONS)); - verify(mockOptions); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test public void testWaitForWithCheckingPeriod() throws InterruptedException { - initializeExpectedJob(3); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - JobStatus status = createStrictMock(JobStatus.class); - expect(status.getState()).andReturn(JobStatus.State.RUNNING); + JobStatus status = mock(JobStatus.class); + when(status.getState()).thenReturn(JobStatus.State.RUNNING); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() - expect(status.getState()).andReturn(JobStatus.State.RUNNING); - expect(status.getState()).andReturn(JobStatus.State.DONE); + when(status.getState()).thenReturn(JobStatus.State.RUNNING); + when(status.getState()).thenReturn(JobStatus.State.DONE); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() - expect(status.getState()).andReturn(JobStatus.State.DONE); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); + when(status.getState()).thenReturn(JobStatus.State.DONE); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); Job runningJob = expectedJob.toBuilder().setStatus(status).build(); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(completedJob); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); - replay(status, bigquery, mockOptions); - initializeJob(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(completedJob); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob); assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS)); - verify(status, mockOptions); + verify(mockOptions).getClock(); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test public void testWaitForWithCheckingPeriod_Null() throws InterruptedException { - initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); Job runningJob = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); - replay(bigquery, mockOptions); - initializeJob(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null); assertNull(job.waitFor(TEST_RETRY_OPTIONS)); - verify(bigquery, mockOptions); + verify(mockOptions).getClock(); + verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions); } @Test public void testWaitForWithTimeout() throws InterruptedException { - initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; - ApiClock clock = createStrictMock(ApiClock.class); - expect(clock.nanoTime()).andReturn(0L); - expect(clock.nanoTime()).andReturn(1_000_000L); - expect(clock.nanoTime()).andReturn(3_000_000L); - JobStatus status = createStrictMock(JobStatus.class); - expect(status.getState()).andReturn(JobStatus.State.RUNNING); - expect(status.getState()).andReturn(JobStatus.State.RUNNING); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(mockOptions.getClock()).andReturn(clock); - Job runningJob = expectedJob.toBuilder().setStatus(status).build(); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); - expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); - replay(status, bigquery, clock, mockOptions); - initializeJob(); - + when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock()); + Job runningJob = + expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob); + when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob); try { job.waitFor(concat(TEST_RETRY_OPTIONS, RetryOption.totalTimeout(Duration.ofMillis(3)))); Assert.fail(); @@ -494,72 +426,52 @@ public void testWaitForWithTimeout() throws InterruptedException { } @Test - public void testReload() throws Exception { - initializeExpectedJob(4); + public void testReload() { JobInfo updatedInfo = JOB_INFO.toBuilder().setEtag("etag").build(); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(expectedJob); - replay(bigquery); - initializeJob(); + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(updatedInfo)); + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(expectedJob); Job updatedJob = job.reload(); compareJob(expectedJob, updatedJob); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test - public void testReloadNull() throws Exception { - initializeExpectedJob(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(null); - replay(bigquery); - initializeJob(); + public void testReloadNull() { + when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(null); assertNull(job.reload()); + verify(bigquery).getJob(JOB_INFO.getJobId()); } @Test - public void testReloadWithOptions() throws Exception { - initializeExpectedJob(4); + public void testReloadWithOptions() { JobInfo updatedInfo = JOB_INFO.toBuilder().setEtag("etag").build(); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getJob(JOB_INFO.getJobId(), BigQuery.JobOption.fields())) - .andReturn(expectedJob); - replay(bigquery); - initializeJob(); + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(updatedInfo)); + when(bigquery.getJob(JOB_INFO.getJobId(), BigQuery.JobOption.fields())).thenReturn(expectedJob); Job updatedJob = job.reload(BigQuery.JobOption.fields()); compareJob(expectedJob, updatedJob); + verify(bigquery).getJob(JOB_INFO.getJobId(), BigQuery.JobOption.fields()); } @Test - public void testCancel() throws Exception { - initializeExpectedJob(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.cancel(JOB_INFO.getJobId())).andReturn(true); - replay(bigquery); - initializeJob(); + public void testCancel() { + when(bigquery.cancel(JOB_INFO.getJobId())).thenReturn(true); assertTrue(job.cancel()); + verify(bigquery).cancel(JOB_INFO.getJobId()); } @Test public void testBigQuery() { - initializeExpectedJob(1); - replay(bigquery); - assertSame(serviceMockReturnsOptions, expectedJob.getBigQuery()); + assertSame(bigquery, expectedJob.getBigQuery()); } @Test public void testToAndFromPb() { - initializeExpectedJob(4); - replay(bigquery); - compareJob(expectedJob, Job.fromPb(serviceMockReturnsOptions, expectedJob.toPb())); + compareJob(expectedJob, Job.fromPb(bigquery, expectedJob.toPb())); } @Test public void testToAndFromPbWithoutConfiguration() { - JobInfo jobInfo = JobInfo.newBuilder(null).build(); - initializeExpectedJob(4, jobInfo); - replay(bigquery); - compareJob(expectedJob, Job.fromPb(serviceMockReturnsOptions, expectedJob.toPb())); + compareJob(expectedJob, Job.fromPb(bigquery, expectedJob.toPb())); } private void compareJob(Job expected, Job value) { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelTest.java index 5ff0f8c89e..756277adc3 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ModelTest.java @@ -16,26 +16,26 @@ package com.google.cloud.bigquery; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import org.junit.After; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.MockitoRule; +@RunWith(MockitoJUnitRunner.class) public class ModelTest { - private BigQuery serviceMockReturnsOptions = createStrictMock(BigQuery.class); - private BigQueryOptions mockOptions = createMock(BigQueryOptions.class); - private static final ModelId MODEL_ID = ModelId.of("dataset", "model"); private static final String ETAG = "etag"; private static final Long CREATION_TIME = 10L; @@ -54,32 +54,26 @@ public class ModelTest { .setFriendlyName(FRIENDLY_NAME) .build(); + @Rule public MockitoRule rule; + private BigQuery bigquery; + private BigQueryOptions mockOptions; private Model expectedModel; private Model model; - private void initializeExpectedModel(int optionsCalls) { - expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); - replay(serviceMockReturnsOptions); - bigquery = createStrictMock(BigQuery.class); - expectedModel = new Model(serviceMockReturnsOptions, new ModelInfo.BuilderImpl(MODEL_INFO)); - } - - private void initializeModel() { + @Before + public void setUp() { + bigquery = mock(BigQuery.class); + mockOptions = mock(BigQueryOptions.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + expectedModel = new Model(bigquery, new ModelInfo.BuilderImpl(MODEL_INFO)); model = new Model(bigquery, new ModelInfo.BuilderImpl(MODEL_INFO)); } - @After - public void tearDown() throws Exception { - verify(bigquery, serviceMockReturnsOptions); - } - @Test public void testBuilder() { - initializeExpectedModel(2); - replay(bigquery); Model builtModel = - new Model.Builder(serviceMockReturnsOptions, MODEL_ID) + new Model.Builder(bigquery, MODEL_ID) .setEtag(ETAG) .setCreationTime(CREATION_TIME) .setExpirationTime(EXPIRATION_TIME) @@ -88,105 +82,78 @@ public void testBuilder() { .setFriendlyName(FRIENDLY_NAME) .build(); assertEquals(ETAG, builtModel.getEtag()); - assertSame(serviceMockReturnsOptions, builtModel.getBigQuery()); + assertSame(bigquery, builtModel.getBigQuery()); } @Test public void testToBuilder() { - initializeExpectedModel(2); - replay(bigquery); compareModelInfo(expectedModel, expectedModel.toBuilder().build()); } @Test - public void testExists_True() throws Exception { - initializeExpectedModel(1); + public void testExists_True() { BigQuery.ModelOption[] expectedOptions = {BigQuery.ModelOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getModel(MODEL_INFO.getModelId(), expectedOptions)).andReturn(expectedModel); - replay(bigquery); - initializeModel(); + when(bigquery.getModel(MODEL_INFO.getModelId(), expectedOptions)).thenReturn(expectedModel); assertTrue(model.exists()); + verify(bigquery).getModel(MODEL_INFO.getModelId(), expectedOptions); } @Test - public void testExists_False() throws Exception { - initializeExpectedModel(1); + public void testExists_False() { BigQuery.ModelOption[] expectedOptions = {BigQuery.ModelOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getModel(MODEL_INFO.getModelId(), expectedOptions)).andReturn(null); - replay(bigquery); - initializeModel(); + when(bigquery.getModel(MODEL_INFO.getModelId(), expectedOptions)).thenReturn(null); assertFalse(model.exists()); + verify(bigquery).getModel(MODEL_INFO.getModelId(), expectedOptions); } @Test - public void testReload() throws Exception { - initializeExpectedModel(4); + public void testReload() { ModelInfo updatedInfo = MODEL_INFO.toBuilder().setDescription("Description").build(); - Model expectedModel = - new Model(serviceMockReturnsOptions, new ModelInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getModel(MODEL_INFO.getModelId())).andReturn(expectedModel); - replay(bigquery); - initializeModel(); + Model expectedModel = new Model(bigquery, new ModelInfo.BuilderImpl(updatedInfo)); + when(bigquery.getModel(MODEL_INFO.getModelId())).thenReturn(expectedModel); Model updatedModel = model.reload(); compareModel(expectedModel, updatedModel); + verify(bigquery).getModel(MODEL_INFO.getModelId()); } @Test - public void testReloadNull() throws Exception { - initializeExpectedModel(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getModel(MODEL_INFO.getModelId())).andReturn(null); - replay(bigquery); - initializeModel(); + public void testReloadNull() { + when(bigquery.getModel(MODEL_INFO.getModelId())).thenReturn(null); assertNull(model.reload()); + verify(bigquery).getModel(MODEL_INFO.getModelId()); } @Test public void testUpdate() { - initializeExpectedModel(4); Model expectedUpdatedModel = expectedModel.toBuilder().setDescription("Description").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedModel))).andReturn(expectedUpdatedModel); - replay(bigquery); - initializeModel(); + when(bigquery.update(eq(expectedModel))).thenReturn(expectedUpdatedModel); Model actualUpdatedModel = model.update(); compareModel(expectedUpdatedModel, actualUpdatedModel); + verify(bigquery).update(eq(expectedModel)); } @Test public void testUpdateWithOptions() { - initializeExpectedModel(4); Model expectedUpdatedModel = expectedModel.toBuilder().setDescription("Description").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedModel), eq(BigQuery.ModelOption.fields()))) - .andReturn(expectedUpdatedModel); - replay(bigquery); - initializeModel(); + when(bigquery.update(eq(expectedModel), eq(BigQuery.ModelOption.fields()))) + .thenReturn(expectedUpdatedModel); Model actualUpdatedModel = model.update(BigQuery.ModelOption.fields()); compareModel(expectedUpdatedModel, actualUpdatedModel); + verify(bigquery).update(eq(expectedModel), eq(BigQuery.ModelOption.fields())); } @Test public void testDeleteTrue() { - initializeExpectedModel(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(MODEL_INFO.getModelId())).andReturn(true); - replay(bigquery); - initializeModel(); + when(bigquery.delete(MODEL_INFO.getModelId())).thenReturn(true); assertTrue(model.delete()); + verify(bigquery).delete(MODEL_INFO.getModelId()); } @Test public void testDeleteFalse() { - initializeExpectedModel(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(MODEL_INFO.getModelId())).andReturn(false); - replay(bigquery); - initializeModel(); + when(bigquery.delete(MODEL_INFO.getModelId())).thenReturn(false); assertFalse(model.delete()); + verify(bigquery).delete(MODEL_INFO.getModelId()); } private void compareModel(Model expected, Model value) { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java index 36301aae58..c51c77193e 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java @@ -15,19 +15,28 @@ */ package com.google.cloud.bigquery; -import static org.easymock.EasyMock.*; -import static org.easymock.EasyMock.replay; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import java.util.List; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.MockitoRule; +@RunWith(MockitoJUnitRunner.class) public class RoutineTest { - private BigQuery serviceMockReturnsOptions = createStrictMock(BigQuery.class); - private BigQueryOptions mockOptions = createMock(BigQueryOptions.class); - private static final RoutineId ROUTINE_ID = RoutineId.of("dataset", "routine"); private static final String ETAG = "etag"; private static final String ROUTINE_TYPE = "SCALAR_FUNCTION"; @@ -64,32 +73,26 @@ public class RoutineTest { .setBody(BODY) .build(); + @Rule public MockitoRule rule; + private BigQuery bigquery; + private BigQueryOptions mockOptions; private Routine expectedRoutine; private Routine routine; - private void initializeExpectedRoutine(int optionsCalls) { - expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); - replay(serviceMockReturnsOptions); - bigquery = createStrictMock(BigQuery.class); - expectedRoutine = - new Routine(serviceMockReturnsOptions, new RoutineInfo.BuilderImpl(ROUTINE_INFO)); - } - - private void initializeRoutine() { + @Before + public void setUp() { + bigquery = mock(BigQuery.class); + mockOptions = mock(BigQueryOptions.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + expectedRoutine = new Routine(bigquery, new RoutineInfo.BuilderImpl(ROUTINE_INFO)); routine = new Routine(bigquery, new RoutineInfo.BuilderImpl(ROUTINE_INFO)); } - private void tearDown() throws Exception { - verify(bigquery, serviceMockReturnsOptions); - } - @Test public void testBuilder() { - initializeExpectedRoutine(2); - replay(bigquery); Routine builtRoutine = - new Routine.Builder(serviceMockReturnsOptions, ROUTINE_ID) + new Routine.Builder(bigquery, ROUTINE_ID) .setEtag(ETAG) .setRoutineType(ROUTINE_TYPE) .setCreationTime(CREATION_TIME) @@ -101,106 +104,79 @@ public void testBuilder() { .setBody(BODY) .build(); assertEquals(ETAG, builtRoutine.getEtag()); - assertSame(serviceMockReturnsOptions, builtRoutine.getBigQuery()); + assertSame(bigquery, builtRoutine.getBigQuery()); } @Test public void testToBuilder() { - initializeExpectedRoutine(2); - replay(bigquery); compareRoutineInfo(expectedRoutine, expectedRoutine.toBuilder().build()); } @Test - public void testExists_True() throws Exception { - initializeExpectedRoutine(1); + public void testExists_True() { BigQuery.RoutineOption[] expectedOptions = {BigQuery.RoutineOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getRoutine(ROUTINE_INFO.getRoutineId(), expectedOptions)).andReturn(null); - replay(bigquery); - initializeRoutine(); + when(bigquery.getRoutine(ROUTINE_INFO.getRoutineId(), expectedOptions)).thenReturn(null); assertFalse(routine.exists()); + verify(bigquery).getRoutine(ROUTINE_INFO.getRoutineId(), expectedOptions); } @Test - public void testExists_False() throws Exception { - initializeExpectedRoutine(1); + public void testExists_False() { BigQuery.RoutineOption[] expectedOptions = {BigQuery.RoutineOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getRoutine(ROUTINE_INFO.getRoutineId(), expectedOptions)) - .andReturn(expectedRoutine); - replay(bigquery); - initializeRoutine(); + when(bigquery.getRoutine(ROUTINE_INFO.getRoutineId(), expectedOptions)) + .thenReturn(expectedRoutine); assertTrue(routine.exists()); + verify(bigquery).getRoutine(ROUTINE_INFO.getRoutineId(), expectedOptions); } @Test - public void testReload() throws Exception { - initializeExpectedRoutine(4); + public void testReload() { RoutineInfo updatedInfo = ROUTINE_INFO.toBuilder().setBody("body2").build(); - Routine expectedRoutine = - new Routine(serviceMockReturnsOptions, new RoutineInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getRoutine(ROUTINE_INFO.getRoutineId())).andReturn(expectedRoutine); - replay(bigquery); - initializeRoutine(); + Routine expectedRoutine = new Routine(bigquery, new RoutineInfo.BuilderImpl(updatedInfo)); + when(bigquery.getRoutine(ROUTINE_INFO.getRoutineId())).thenReturn(expectedRoutine); Routine updatedRoutine = routine.reload(); compareRoutine(expectedRoutine, updatedRoutine); + verify(bigquery).getRoutine(ROUTINE_INFO.getRoutineId()); } @Test - public void testReload_Null() throws Exception { - initializeExpectedRoutine(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getRoutine(ROUTINE_INFO.getRoutineId())).andReturn(null); - replay(bigquery); - initializeRoutine(); + public void testReload_Null() { + when(bigquery.getRoutine(ROUTINE_INFO.getRoutineId())).thenReturn(null); assertNull(routine.reload()); + verify(bigquery).getRoutine(ROUTINE_INFO.getRoutineId()); } @Test public void testUpdate() { - initializeExpectedRoutine(4); Routine expectedUpdatedRoutine = expectedRoutine.toBuilder().setBody("body2").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedRoutine))).andReturn(expectedUpdatedRoutine); - replay(bigquery); - initializeRoutine(); + when(bigquery.update(eq(expectedRoutine))).thenReturn(expectedUpdatedRoutine); Routine actualUpdatedRoutine = routine.update(); compareRoutine(expectedUpdatedRoutine, actualUpdatedRoutine); + verify(bigquery).update(eq(expectedRoutine)); } @Test public void testUpdateWithOptions() { - initializeExpectedRoutine(4); Routine expectedUpdatedRoutine = expectedRoutine.toBuilder().setBody("body2").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedRoutine), eq(BigQuery.RoutineOption.fields()))) - .andReturn(expectedUpdatedRoutine); - replay(bigquery); - initializeRoutine(); + when(bigquery.update(eq(expectedRoutine), eq(BigQuery.RoutineOption.fields()))) + .thenReturn(expectedUpdatedRoutine); Routine actualUpdatedRoutine = routine.update(BigQuery.RoutineOption.fields()); compareRoutine(expectedUpdatedRoutine, actualUpdatedRoutine); + verify(bigquery).update(eq(expectedRoutine), eq(BigQuery.RoutineOption.fields())); } @Test public void testDeleteTrue() { - initializeExpectedRoutine(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(ROUTINE_INFO.getRoutineId())).andReturn(true); - replay(bigquery); - initializeRoutine(); + when(bigquery.delete(ROUTINE_INFO.getRoutineId())).thenReturn(true); assertTrue(routine.delete()); + verify(bigquery).delete(ROUTINE_INFO.getRoutineId()); } @Test public void testDeleteFalse() { - initializeExpectedRoutine(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(ROUTINE_INFO.getRoutineId())).andReturn(false); - replay(bigquery); - initializeRoutine(); + when(bigquery.delete(ROUTINE_INFO.getRoutineId())).thenReturn(false); assertFalse(routine.delete()); + verify(bigquery).delete(ROUTINE_INFO.getRoutineId()); } private void compareRoutine(Routine expected, Routine value) { 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 0b4707db14..a959a89916 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 @@ -16,19 +16,17 @@ package com.google.cloud.bigquery; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.captureLong; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.cloud.RestorableState; import com.google.cloud.WriteChannel; @@ -39,13 +37,15 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Random; -import org.easymock.Capture; -import org.easymock.CaptureType; -import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class TableDataWriteChannelTest { private static final String UPLOAD_ID = "uploadid"; @@ -73,22 +73,21 @@ public class TableDataWriteChannelTest { private BigQuery bigqueryMock; private Job job; + @Captor private ArgumentCaptor capturedBuffer; + @Captor private ArgumentCaptor capturedPosition; + private TableDataWriteChannel writer; @Before public void setUp() { - rpcFactoryMock = createMock(BigQueryRpcFactory.class); - bigqueryRpcMock = createMock(BigQueryRpc.class); - bigqueryFactoryMock = createMock(BigQueryFactory.class); - bigqueryMock = createMock(BigQuery.class); - expect(bigqueryMock.getOptions()).andReturn(options).anyTimes(); - replay(bigqueryMock); + rpcFactoryMock = mock(BigQueryRpcFactory.class); + bigqueryRpcMock = mock(BigQueryRpc.class); + bigqueryFactoryMock = mock(BigQueryFactory.class); + bigqueryMock = mock(BigQuery.class); + when(bigqueryMock.getOptions()).thenReturn(options); job = new Job(bigqueryMock, new JobInfo.BuilderImpl(JOB_INFO)); - expect(rpcFactoryMock.create(anyObject(BigQueryOptions.class))).andReturn(bigqueryRpcMock); - expect(bigqueryFactoryMock.create(anyObject(BigQueryOptions.class))) - .andReturn(bigqueryMock) - .anyTimes(); - replay(rpcFactoryMock, bigqueryFactoryMock); + when(rpcFactoryMock.create(any(BigQueryOptions.class))).thenReturn(bigqueryRpcMock); + when(bigqueryFactoryMock.create(any(BigQueryOptions.class))).thenReturn(bigqueryMock); options = BigQueryOptions.newBuilder() .setProjectId("projectid") @@ -97,124 +96,131 @@ public void setUp() { .build(); } - @After - public void tearDown() throws Exception { - verify(rpcFactoryMock, bigqueryRpcMock, bigqueryFactoryMock, bigqueryMock); - } - @Test public void testCreate() { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertTrue(writer.isOpen()); assertNull(writer.getJob()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); } @Test public void testCreateRetryableError() { BigQueryException exception = new BigQueryException(new SocketException("Socket closed")); - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andThrow(exception); - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenThrow(exception) + .thenReturn(UPLOAD_ID); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertTrue(writer.isOpen()); assertNull(writer.getJob()); + verify(bigqueryRpcMock, times(2)) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); } @Test 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(ex); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenThrow(ex); try (TableDataWriteChannel channel = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION)) { Assert.fail(); } catch (RuntimeException expected) { Assert.assertEquals("java.lang.RuntimeException: expected", expected.getMessage()); } + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); } @Test public void testWriteWithoutFlush() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertEquals(MIN_CHUNK_SIZE, writer.write(ByteBuffer.allocate(MIN_CHUNK_SIZE))); assertNull(writer.getJob()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); } @Test public void testWriteWithFlush() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), - capture(capturedBuffer), - eq(0), - eq(0L), - eq(CUSTOM_CHUNK_SIZE), - eq(false))) - .andReturn(null); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), + capturedBuffer.capture(), + eq(0), + eq(0L), + eq(CUSTOM_CHUNK_SIZE), + eq(false))) + .thenReturn(null); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); writer.setChunkSize(CUSTOM_CHUNK_SIZE); ByteBuffer buffer = randomBuffer(CUSTOM_CHUNK_SIZE); assertEquals(CUSTOM_CHUNK_SIZE, writer.write(buffer)); assertArrayEquals(buffer.array(), capturedBuffer.getValue()); assertNull(writer.getJob()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock) + .write( + eq(UPLOAD_ID), + capturedBuffer.capture(), + eq(0), + eq(0L), + eq(CUSTOM_CHUNK_SIZE), + eq(false)); } @Test public void testWritesAndFlush() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), - capture(capturedBuffer), - eq(0), - eq(0L), - eq(DEFAULT_CHUNK_SIZE), - eq(false))) - .andReturn(null); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), + capturedBuffer.capture(), + eq(0), + eq(0L), + eq(DEFAULT_CHUNK_SIZE), + eq(false))) + .thenReturn(null); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); ByteBuffer[] buffers = new ByteBuffer[DEFAULT_CHUNK_SIZE / MIN_CHUNK_SIZE]; for (int i = 0; i < buffers.length; i++) { @@ -228,50 +234,57 @@ public void testWritesAndFlush() throws IOException { capturedBuffer.getValue(), MIN_CHUNK_SIZE * i, MIN_CHUNK_SIZE * (i + 1))); } assertNull(writer.getJob()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock) + .write( + eq(UPLOAD_ID), + capturedBuffer.capture(), + eq(0), + eq(0L), + eq(DEFAULT_CHUNK_SIZE), + eq(false)); } @Test public void testCloseWithoutFlush() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true))) - .andReturn(job.toPb()); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(0), eq(true))) + .thenReturn(job.toPb()); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertTrue(writer.isOpen()); writer.close(); assertArrayEquals(new byte[0], capturedBuffer.getValue()); assertTrue(!writer.isOpen()); assertEquals(job, writer.getJob()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock) + .write(eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(0), eq(true)); } @Test public void testCloseWithFlush() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); ByteBuffer buffer = randomBuffer(MIN_CHUNK_SIZE); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), - capture(capturedBuffer), - eq(0), - eq(0L), - eq(MIN_CHUNK_SIZE), - eq(true))) - .andReturn(job.toPb()); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(MIN_CHUNK_SIZE), eq(true))) + .thenReturn(job.toPb()); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertTrue(writer.isOpen()); writer.write(buffer); @@ -280,22 +293,26 @@ public void testCloseWithFlush() throws IOException { assertArrayEquals(buffer.array(), Arrays.copyOf(capturedBuffer.getValue(), MIN_CHUNK_SIZE)); assertTrue(!writer.isOpen()); assertEquals(job, writer.getJob()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock) + .write( + eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(MIN_CHUNK_SIZE), eq(true)); } @Test public void testWriteClosed() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true))) - .andReturn(job.toPb()); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(0), eq(true))) + .thenReturn(job.toPb()); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); writer.close(); assertEquals(job, writer.getJob()); @@ -305,57 +322,67 @@ public void testWriteClosed() throws IOException { } catch (IOException ex) { // expected } + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock) + .write(eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(0), eq(true)); } @Test public void testSaveAndRestore() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(CaptureType.ALL); - Capture capturedPosition = Capture.newInstance(CaptureType.ALL); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), - capture(capturedBuffer), - eq(0), - captureLong(capturedPosition), - eq(DEFAULT_CHUNK_SIZE), - eq(false))) - .andReturn(null) - .times(2); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), + capturedBuffer.capture(), + eq(0), + capturedPosition.capture(), + eq(DEFAULT_CHUNK_SIZE), + eq(false))) + .thenReturn(null); ByteBuffer buffer1 = randomBuffer(DEFAULT_CHUNK_SIZE); ByteBuffer buffer2 = randomBuffer(DEFAULT_CHUNK_SIZE); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertEquals(DEFAULT_CHUNK_SIZE, writer.write(buffer1)); - assertArrayEquals(buffer1.array(), capturedBuffer.getValues().get(0)); - assertEquals(new Long(0L), capturedPosition.getValues().get(0)); + assertArrayEquals(buffer1.array(), capturedBuffer.getAllValues().get(0)); + assertEquals(new Long(0L), capturedPosition.getAllValues().get(0)); assertNull(writer.getJob()); RestorableState writerState = writer.capture(); WriteChannel restoredWriter = writerState.restore(); assertEquals(DEFAULT_CHUNK_SIZE, restoredWriter.write(buffer2)); - assertArrayEquals(buffer2.array(), capturedBuffer.getValues().get(1)); - assertEquals(new Long(DEFAULT_CHUNK_SIZE), capturedPosition.getValues().get(1)); + assertArrayEquals(buffer2.array(), capturedBuffer.getAllValues().get(1)); + assertEquals(new Long(DEFAULT_CHUNK_SIZE), capturedPosition.getAllValues().get(1)); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock, times(2)) + .write( + eq(UPLOAD_ID), + capturedBuffer.capture(), + eq(0), + capturedPosition.capture(), + eq(DEFAULT_CHUNK_SIZE), + eq(false)); } @Test public void testSaveAndRestoreClosed() throws IOException { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID); - Capture capturedBuffer = Capture.newInstance(); - expect( - bigqueryRpcMock.write( - eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true))) - .andReturn(job.toPb()); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); + when(bigqueryRpcMock.write( + eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(0), eq(true))) + .thenReturn(job.toPb()); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); writer.close(); assertEquals(job, writer.getJob()); @@ -370,18 +397,22 @@ public void testSaveAndRestoreClosed() throws IOException { WriteChannel restoredWriter = writerState.restore(); assertArrayEquals(new byte[0], capturedBuffer.getValue()); assertEquals(expectedWriterState, restoredWriter.capture()); + verify(bigqueryRpcMock) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); + verify(bigqueryRpcMock) + .write(eq(UPLOAD_ID), capturedBuffer.capture(), eq(0), eq(0L), eq(0), eq(true)); } @Test public void testStateEquals() { - expect( - bigqueryRpcMock.open( - new com.google.api.services.bigquery.model.Job() - .setJobReference(JOB_INFO.getJobId().toPb()) - .setConfiguration(LOAD_CONFIGURATION.toPb()))) - .andReturn(UPLOAD_ID) - .times(2); - replay(bigqueryRpcMock); + when(bigqueryRpcMock.open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb()))) + .thenReturn(UPLOAD_ID); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); // avoid closing when you don't want partial writes upon failure @SuppressWarnings("resource") @@ -392,6 +423,11 @@ public void testStateEquals() { assertEquals(state, state2); assertEquals(state.hashCode(), state2.hashCode()); assertEquals(state.toString(), state2.toString()); + verify(bigqueryRpcMock, times(2)) + .open( + new com.google.api.services.bigquery.model.Job() + .setJobReference(JOB_INFO.getJobId().toPb()) + .setConfiguration(LOAD_CONFIGURATION.toPb())); } private static ByteBuffer randomBuffer(int size) { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableTest.java index 26eb0e9621..860230f30f 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableTest.java @@ -17,17 +17,15 @@ package com.google.cloud.bigquery; import static com.google.common.truth.Truth.assertThat; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.api.gax.paging.Page; import com.google.cloud.PageImpl; @@ -35,9 +33,14 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.List; -import org.junit.After; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.MockitoRule; +@RunWith(MockitoJUnitRunner.class) public class TableTest { private static final String ETAG = "etag"; @@ -86,34 +89,27 @@ public class TableTest { ImmutableList.of( FieldValueList.of(ImmutableList.of(FIELD_VALUE1)).withSchema(SCHEMA.getFields()), FieldValueList.of(ImmutableList.of(FIELD_VALUE2)).withSchema(SCHEMA.getFields())); - private BigQuery serviceMockReturnsOptions = createStrictMock(BigQuery.class); - private BigQueryOptions mockOptions = createMock(BigQueryOptions.class); + + @Rule public MockitoRule rule; + private BigQuery bigquery; + private BigQueryOptions mockOptions; private Table expectedTable; private Table table; - private void initializeExpectedTable(int optionsCalls) { - expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); - replay(serviceMockReturnsOptions); - bigquery = createStrictMock(BigQuery.class); - expectedTable = new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(TABLE_INFO)); - } - - private void initializeTable() { + @Before + public void setUp() { + bigquery = mock(BigQuery.class); + mockOptions = mock(BigQueryOptions.class); + when(bigquery.getOptions()).thenReturn(mockOptions); + expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO)); table = new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO)); } - @After - public void tearDown() throws Exception { - verify(bigquery, serviceMockReturnsOptions); - } - @Test public void testBuilder() { - initializeExpectedTable(2); - replay(bigquery); Table builtTable = - new Table.Builder(serviceMockReturnsOptions, TABLE_ID1, TABLE_DEFINITION) + new Table.Builder(bigquery, TABLE_ID1, TABLE_DEFINITION) .setCreationTime(CREATION_TIME) .setDescription(DESCRIPTION) .setEtag(ETAG) @@ -133,264 +129,199 @@ public void testBuilder() { assertEquals(LAST_MODIFIED_TIME, builtTable.getLastModifiedTime()); assertEquals(TABLE_DEFINITION, builtTable.getDefinition()); assertEquals(SELF_LINK, builtTable.getSelfLink()); - assertSame(serviceMockReturnsOptions, builtTable.getBigQuery()); + assertSame(bigquery, builtTable.getBigQuery()); } @Test public void testToBuilder() { - initializeExpectedTable(4); - replay(bigquery); compareTable(expectedTable, expectedTable.toBuilder().build()); } @Test - public void testExists_True() throws Exception { - initializeExpectedTable(1); + public void testExists_True() { BigQuery.TableOption[] expectedOptions = {BigQuery.TableOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO.getTableId(), expectedOptions)).andReturn(expectedTable); - replay(bigquery); - initializeTable(); + when(bigquery.getTable(TABLE_INFO.getTableId(), expectedOptions)).thenReturn(expectedTable); assertTrue(table.exists()); + verify(bigquery).getTable(TABLE_INFO.getTableId(), expectedOptions); } @Test - public void testExists_False() throws Exception { - initializeExpectedTable(1); + public void testExists_False() { BigQuery.TableOption[] expectedOptions = {BigQuery.TableOption.fields()}; - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO.getTableId(), expectedOptions)).andReturn(null); - replay(bigquery); - initializeTable(); + when(bigquery.getTable(TABLE_INFO.getTableId(), expectedOptions)).thenReturn(null); assertFalse(table.exists()); + verify(bigquery).getTable(TABLE_INFO.getTableId(), expectedOptions); } @Test - public void testReload() throws Exception { - initializeExpectedTable(4); + public void testReload() { TableInfo updatedInfo = TABLE_INFO.toBuilder().setDescription("Description").build(); - Table expectedTable = - new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO.getTableId())).andReturn(expectedTable); - replay(bigquery); - initializeTable(); + Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(updatedInfo)); + when(bigquery.getTable(TABLE_INFO.getTableId())).thenReturn(expectedTable); Table updatedTable = table.reload(); compareTable(expectedTable, updatedTable); + verify(bigquery).getTable(TABLE_INFO.getTableId()); } @Test - public void testReloadNull() throws Exception { - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO.getTableId())).andReturn(null); - replay(bigquery); - initializeTable(); + public void testReloadNull() { + when(bigquery.getTable(TABLE_INFO.getTableId())).thenReturn(null); assertNull(table.reload()); + verify(bigquery).getTable(TABLE_INFO.getTableId()); } @Test - public void testReloadWithOptions() throws Exception { - initializeExpectedTable(4); + public void testReloadWithOptions() { TableInfo updatedInfo = TABLE_INFO.toBuilder().setDescription("Description").build(); - Table expectedTable = - new Table(serviceMockReturnsOptions, new TableInfo.BuilderImpl(updatedInfo)); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.getTable(TABLE_INFO.getTableId(), BigQuery.TableOption.fields())) - .andReturn(expectedTable); - replay(bigquery); - initializeTable(); + Table expectedTable = new Table(bigquery, new TableInfo.BuilderImpl(updatedInfo)); + when(bigquery.getTable(TABLE_INFO.getTableId(), BigQuery.TableOption.fields())) + .thenReturn(expectedTable); Table updatedTable = table.reload(BigQuery.TableOption.fields()); compareTable(expectedTable, updatedTable); + verify(bigquery).getTable(TABLE_INFO.getTableId(), BigQuery.TableOption.fields()); } @Test public void testUpdate() { - initializeExpectedTable(4); Table expectedUpdatedTable = expectedTable.toBuilder().setDescription("Description").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedTable))).andReturn(expectedUpdatedTable); - replay(bigquery); - initializeTable(); + when(bigquery.update(eq(expectedTable))).thenReturn(expectedUpdatedTable); Table actualUpdatedTable = table.update(); compareTable(expectedUpdatedTable, actualUpdatedTable); + verify(bigquery).update(eq(expectedTable)); } @Test public void testUpdateWithOptions() { - initializeExpectedTable(4); Table expectedUpdatedTable = expectedTable.toBuilder().setDescription("Description").build(); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.update(eq(expectedTable), eq(BigQuery.TableOption.fields()))) - .andReturn(expectedUpdatedTable); - replay(bigquery); - initializeTable(); + when(bigquery.update(eq(expectedTable), eq(BigQuery.TableOption.fields()))) + .thenReturn(expectedUpdatedTable); Table actualUpdatedTable = table.update(BigQuery.TableOption.fields()); compareTable(expectedUpdatedTable, actualUpdatedTable); + verify(bigquery).update(eq(expectedTable), eq(BigQuery.TableOption.fields())); } @Test public void testDeleteTrue() { - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(TABLE_INFO.getTableId())).andReturn(true); - replay(bigquery); - initializeTable(); + when(bigquery.delete(TABLE_INFO.getTableId())).thenReturn(true); assertTrue(table.delete()); + verify(bigquery).delete(TABLE_INFO.getTableId()); } @Test public void testDeleteFalse() { - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.delete(TABLE_INFO.getTableId())).andReturn(false); - replay(bigquery); - initializeTable(); + when(bigquery.delete(TABLE_INFO.getTableId())).thenReturn(false); assertFalse(table.delete()); + verify(bigquery).delete(TABLE_INFO.getTableId()); } @Test - public void testInsert() throws Exception { - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.insertAll(INSERT_ALL_REQUEST)).andReturn(EMPTY_INSERT_ALL_RESPONSE); - replay(bigquery); - initializeTable(); + public void testInsert() { + when(bigquery.insertAll(INSERT_ALL_REQUEST)).thenReturn(EMPTY_INSERT_ALL_RESPONSE); InsertAllResponse response = table.insert(ROWS_TO_INSERT); assertSame(EMPTY_INSERT_ALL_RESPONSE, response); + verify(bigquery).insertAll(INSERT_ALL_REQUEST); } @Test - public void testInsertComplete() throws Exception { - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.insertAll(INSERT_ALL_REQUEST_COMPLETE)).andReturn(EMPTY_INSERT_ALL_RESPONSE); - replay(bigquery); - initializeTable(); + public void testInsertComplete() { + when(bigquery.insertAll(INSERT_ALL_REQUEST_COMPLETE)).thenReturn(EMPTY_INSERT_ALL_RESPONSE); InsertAllResponse response = table.insert(ROWS_TO_INSERT, true, true); assertSame(EMPTY_INSERT_ALL_RESPONSE, response); + verify(bigquery).insertAll(INSERT_ALL_REQUEST_COMPLETE); } @Test - public void testList() throws Exception { + public void testList() { Page page = new PageImpl<>(null, "c", ROWS); - - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.listTableData(TABLE_ID1)).andReturn(new TableResult(null, ROWS.size(), page)); - expect(bigquery.listTableData(TABLE_ID1, SCHEMA)) - .andReturn(new TableResult(SCHEMA, ROWS.size(), page)); - replay(bigquery); - initializeTable(); + when(bigquery.listTableData(TABLE_ID1)).thenReturn(new TableResult(null, ROWS.size(), page)); + when(bigquery.listTableData(TABLE_ID1, SCHEMA)) + .thenReturn(new TableResult(SCHEMA, ROWS.size(), page)); Page dataPage = table.list(); assertThat(dataPage.getValues()).containsExactlyElementsIn(ROWS).inOrder(); - dataPage = table.list(SCHEMA); assertThat(dataPage.getValues()).containsExactlyElementsIn(ROWS_WITH_SCHEMA).inOrder(); + verify(bigquery).listTableData(TABLE_ID1); + verify(bigquery).listTableData(TABLE_ID1, SCHEMA); } @Test - public void testListWithOptions() throws Exception { + public void testListWithOptions() { Page page = new PageImpl<>(null, "c", ROWS); - initializeExpectedTable(1); - expect(bigquery.getOptions()).andReturn(mockOptions); - expect(bigquery.listTableData(TABLE_ID1, BigQuery.TableDataListOption.pageSize(10L))) - .andReturn(new TableResult(null, ROWS.size(), page)); - expect(bigquery.listTableData(TABLE_ID1, SCHEMA, BigQuery.TableDataListOption.pageSize(10L))) - .andReturn(new TableResult(SCHEMA, ROWS.size(), page)); - replay(bigquery); - initializeTable(); + when(bigquery.listTableData(TABLE_ID1, BigQuery.TableDataListOption.pageSize(10L))) + .thenReturn(new TableResult(null, ROWS.size(), page)); + when(bigquery.listTableData(TABLE_ID1, SCHEMA, BigQuery.TableDataListOption.pageSize(10L))) + .thenReturn(new TableResult(SCHEMA, ROWS.size(), page)); Page dataPage = table.list(BigQuery.TableDataListOption.pageSize(10L)); assertThat(dataPage.getValues()).containsExactlyElementsIn(ROWS).inOrder(); dataPage = table.list(SCHEMA, BigQuery.TableDataListOption.pageSize(10L)); assertThat(dataPage.getValues()).containsExactlyElementsIn(ROWS_WITH_SCHEMA).inOrder(); + verify(bigquery).listTableData(TABLE_ID1, BigQuery.TableDataListOption.pageSize(10L)); + verify(bigquery).listTableData(TABLE_ID1, SCHEMA, BigQuery.TableDataListOption.pageSize(10L)); } @Test - public void testCopyFromString() throws Exception { - initializeExpectedTable(2); - expect(bigquery.getOptions()).andReturn(mockOptions); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(COPY_JOB_INFO)); - expect(bigquery.create(COPY_JOB_INFO)).andReturn(expectedJob); - replay(bigquery); - initializeTable(); + public void testCopyFromString() { + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(COPY_JOB_INFO)); + when(bigquery.create(COPY_JOB_INFO)).thenReturn(expectedJob); Job job = table.copy(TABLE_ID2.getDataset(), TABLE_ID2.getTable()); assertSame(expectedJob, job); + verify(bigquery).create(COPY_JOB_INFO); } @Test - public void testCopyFromId() throws Exception { - initializeExpectedTable(2); - expect(bigquery.getOptions()).andReturn(mockOptions); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(COPY_JOB_INFO)); - expect(bigquery.create(COPY_JOB_INFO)).andReturn(expectedJob); - replay(bigquery); - initializeTable(); + public void testCopyFromId() { + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(COPY_JOB_INFO)); + when(bigquery.create(COPY_JOB_INFO)).thenReturn(expectedJob); Job job = table.copy(TABLE_ID2.getDataset(), TABLE_ID2.getTable()); assertSame(expectedJob, job); + verify(bigquery).create(COPY_JOB_INFO); } @Test - public void testLoadDataUri() throws Exception { - initializeExpectedTable(2); - expect(bigquery.getOptions()).andReturn(mockOptions); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(LOAD_JOB_INFO)); - expect(bigquery.create(LOAD_JOB_INFO)).andReturn(expectedJob); - replay(bigquery); - initializeTable(); + public void testLoadDataUri() { + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(LOAD_JOB_INFO)); + when(bigquery.create(LOAD_JOB_INFO)).thenReturn(expectedJob); Job job = table.load(FormatOptions.json(), "URI"); assertSame(expectedJob, job); + verify(bigquery).create(LOAD_JOB_INFO); } @Test - public void testLoadDataUris() throws Exception { - initializeExpectedTable(2); - expect(bigquery.getOptions()).andReturn(mockOptions); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(LOAD_JOB_INFO)); - expect(bigquery.create(LOAD_JOB_INFO)).andReturn(expectedJob); - replay(bigquery); - initializeTable(); + public void testLoadDataUris() { + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(LOAD_JOB_INFO)); + when(bigquery.create(LOAD_JOB_INFO)).thenReturn(expectedJob); Job job = table.load(FormatOptions.json(), ImmutableList.of("URI")); assertSame(expectedJob, job); + verify(bigquery).create(LOAD_JOB_INFO); } @Test - public void testExtractDataUri() throws Exception { - initializeExpectedTable(2); - expect(bigquery.getOptions()).andReturn(mockOptions); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); - expect(bigquery.create(EXTRACT_JOB_INFO)).andReturn(expectedJob); - replay(bigquery); - initializeTable(); + public void testExtractDataUri() { + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); + when(bigquery.create(EXTRACT_JOB_INFO)).thenReturn(expectedJob); Job job = table.extract("CSV", "URI"); assertSame(expectedJob, job); + verify(bigquery).create(EXTRACT_JOB_INFO); } @Test - public void testExtractDataUris() throws Exception { - initializeExpectedTable(2); - expect(bigquery.getOptions()).andReturn(mockOptions); - Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); - expect(bigquery.create(EXTRACT_JOB_INFO)).andReturn(expectedJob); - replay(bigquery); - initializeTable(); + public void testExtractDataUris() { + Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); + when(bigquery.create(EXTRACT_JOB_INFO)).thenReturn(expectedJob); Job job = table.extract("CSV", ImmutableList.of("URI")); assertSame(expectedJob, job); + verify(bigquery).create(EXTRACT_JOB_INFO); } @Test public void testBigQuery() { - initializeExpectedTable(1); - replay(bigquery); - assertSame(serviceMockReturnsOptions, expectedTable.getBigQuery()); + assertSame(bigquery, expectedTable.getBigQuery()); } @Test public void testToAndFromPb() { - initializeExpectedTable(4); - replay(bigquery); - compareTable(expectedTable, Table.fromPb(serviceMockReturnsOptions, expectedTable.toPb())); + compareTable(expectedTable, Table.fromPb(bigquery, expectedTable.toPb())); } private void compareTable(Table expected, Table value) { 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 e994df433c..9b2ef4804f 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 @@ -26,10 +26,13 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.concurrent.ExecutionException; -import org.easymock.EasyMock; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import org.threeten.bp.Duration; +@RunWith(MockitoJUnitRunner.class) public class RemoteBigQueryHelperTest { private static final String DATASET_NAME = "dataset-name"; @@ -65,12 +68,11 @@ public class RemoteBigQueryHelperTest { @Test public void testForceDelete() throws InterruptedException, ExecutionException { - BigQuery bigqueryMock = EasyMock.createMock(BigQuery.class); - EasyMock.expect(bigqueryMock.delete(DATASET_NAME, DatasetDeleteOption.deleteContents())) - .andReturn(true); - EasyMock.replay(bigqueryMock); + BigQuery bigqueryMock = Mockito.mock(BigQuery.class); + Mockito.when(bigqueryMock.delete(DATASET_NAME, DatasetDeleteOption.deleteContents())) + .thenReturn(true); assertTrue(RemoteBigQueryHelper.forceDelete(bigqueryMock, DATASET_NAME)); - EasyMock.verify(bigqueryMock); + Mockito.verify(bigqueryMock).delete(DATASET_NAME, DatasetDeleteOption.deleteContents()); } @Test diff --git a/pom.xml b/pom.xml index cddbd6ab22..e522f01407 100644 --- a/pom.xml +++ b/pom.xml @@ -95,18 +95,11 @@ - org.easymock - easymock - 3.6 + org.mockito + mockito-core + 2.28.2 test - - org.objenesis - objenesis - 2.6 - test - - com.google.cloud google-cloud-storage From 2f9fca56b6b742014cde5a95dbee358a46b38c48 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 19 May 2020 13:01:35 -0400 Subject: [PATCH 10/10] chore: release 1.115.1 (#361) * updated CHANGELOG.md [ci skip] * updated README.md [ci skip] * updated versions.txt [ci skip] * updated samples/pom.xml [ci skip] * updated google-cloud-bigquery/pom.xml [ci skip] * updated samples/snapshot/pom.xml [ci skip] * updated samples/install-without-bom/pom.xml [ci skip] * updated samples/snippets/pom.xml [ci skip] * updated pom.xml [ci skip] Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ README.md | 4 ++-- google-cloud-bigquery/pom.xml | 4 ++-- pom.xml | 4 ++-- samples/snapshot/pom.xml | 2 +- versions.txt | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4343a671d2..48d1d5d048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +### [1.115.1](https://www.github.com/googleapis/java-bigquery/compare/v1.115.0...v1.115.1) (2020-05-19) + + +### Dependencies + +* update dependency com.google.cloud:google-cloud-shared-dependencies to v0.4.0 ([#362](https://www.github.com/googleapis/java-bigquery/issues/362)) ([7a256f7](https://www.github.com/googleapis/java-bigquery/commit/7a256f734aab3a26a8290a66b11cbcb91fe05d7a)) + + +### Documentation + +* **samples:** Added UpdateTableDescription example. ([#360](https://www.github.com/googleapis/java-bigquery/issues/360)) ([96d2c87](https://www.github.com/googleapis/java-bigquery/commit/96d2c87bf087f980106f57ffaac0933274c84b96)) + ## [1.115.0](https://www.github.com/googleapis/java-bigquery/compare/v1.114.0...v1.115.0) (2020-05-13) diff --git a/README.md b/README.md index 3a9e42de40..43625789a3 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,11 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-bigquery:1.115.0' +compile 'com.google.cloud:google-cloud-bigquery:1.115.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "1.115.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "1.115.1" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index 198d38a5b4..a49fcce005 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-bigquery - 1.115.1-SNAPSHOT + 1.115.1 jar BigQuery https://github.com/googleapis/java-bigquery @@ -11,7 +11,7 @@ com.google.cloud google-cloud-bigquery-parent - 1.115.1-SNAPSHOT + 1.115.1 google-cloud-bigquery diff --git a/pom.xml b/pom.xml index e522f01407..88b9f33c1b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bigquery-parent pom - 1.115.1-SNAPSHOT + 1.115.1 BigQuery Parent https://github.com/googleapis/java-bigquery @@ -91,7 +91,7 @@ com.google.cloud google-cloud-bigquery - 1.115.1-SNAPSHOT + 1.115.1 diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 4c90b1576c..bbc681a138 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -44,7 +44,7 @@ com.google.cloud google-cloud-bigquery - 1.115.1-SNAPSHOT + 1.115.1 diff --git a/versions.txt b/versions.txt index 2c900ad0e0..80b9b93a55 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-bigquery:1.115.0:1.115.1-SNAPSHOT \ No newline at end of file +google-cloud-bigquery:1.115.1:1.115.1 \ No newline at end of file