From 6be48bd7191e8e4c64af699c75533765f975f73f Mon Sep 17 00:00:00 2001 From: Kristen O'Leary Date: Mon, 13 Sep 2021 16:44:27 -0400 Subject: [PATCH 1/6] [wip] migrate to mockito-core 3.12.4 --- google-cloud-bigtable/pom.xml | 2 +- .../v2/BigtableInstanceAdminClientTest.java | 9 ++++-- .../v2/stub/AwaitReplicationCallableTest.java | 10 +++++-- .../data/v2/BigtableDataClientTest.java | 29 +++++++++---------- .../data/v2/stub/MutateRowCallableTest.java | 4 +-- .../readrows/ReadRowsFirstCallableTest.java | 9 ++++-- .../v2/stub/readrows/ReadRowsRetryTest.java | 4 +-- pom.xml | 4 +-- 8 files changed, 42 insertions(+), 29 deletions(-) diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index 8f0ff451b0..132460849e 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -273,7 +273,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java index 2c3d81c084..a1e457027f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java @@ -61,17 +61,22 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.quality.Strictness; import org.mockito.stubbing.Answer; -@RunWith(MockitoJUnitRunner.class) +@RunWith(JUnit4.class) public class BigtableInstanceAdminClientTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); private static final String PROJECT_ID = "my-project"; private static final String INSTANCE_ID = "my-instance"; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java index f5aedb5c6f..ac9941b2fc 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitReplicationCallableTest.java @@ -35,15 +35,21 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.quality.Strictness; import org.threeten.bp.Duration; -@RunWith(MockitoJUnitRunner.class) +@RunWith(JUnit4.class) public class AwaitReplicationCallableTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); + private static final TableName TABLE_NAME = TableName.of("my-project", "my-instance", "my-table"); private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index 67befad2a4..30e2b513ee 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -22,7 +22,6 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.gax.batching.Batcher; -import com.google.api.gax.grpc.GrpcCallContext; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -44,17 +43,24 @@ import java.util.Collections; import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.mockito.Answers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.quality.Strictness; import org.mockito.stubbing.Answer; -@RunWith(MockitoJUnitRunner.class) +@RunWith(JUnit4.class) public class BigtableDataClientTest { + + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); + @Mock private EnhancedBigtableStub mockStub; @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -81,13 +87,9 @@ public void setUp() { Mockito.when(mockStub.bulkMutateRowsCallable()).thenReturn(mockBulkMutateRowsCallable); Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable); Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable); - Mockito.when( - mockStub.newMutateRowsBatcher( - Mockito.any(String.class), Mockito.any(GrpcCallContext.class))) + Mockito.when(mockStub.newMutateRowsBatcher(Mockito.any(String.class), Mockito.any())) .thenReturn(mockBulkMutationBatcher); - Mockito.when( - mockStub.newBulkReadRowsBatcher( - Mockito.any(Query.class), Mockito.any(GrpcCallContext.class))) + Mockito.when(mockStub.newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any())) .thenReturn(mockBulkReadRowsBatcher); } @@ -379,8 +381,7 @@ public void proxyNewBulkMutationBatcherTest() { ApiFuture actualRes = batcher.add(request); assertThat(actualRes).isSameInstanceAs(expectedResponse); - Mockito.verify(mockStub) - .newMutateRowsBatcher(Mockito.any(String.class), Mockito.any(GrpcCallContext.class)); + Mockito.verify(mockStub).newMutateRowsBatcher(Mockito.any(String.class), Mockito.any()); } @Test @@ -396,8 +397,7 @@ public void proxyNewBulkReadRowsTest() { ApiFuture actualResponse = batcher.add(request); assertThat(actualResponse).isSameInstanceAs(expectedResponse); - Mockito.verify(mockStub) - .newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any(GrpcCallContext.class)); + Mockito.verify(mockStub).newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any()); } @Test @@ -414,8 +414,7 @@ public void proxyNewBulkReadRowsWithFilterTest() { ApiFuture actualResponse = batcher.add(request); assertThat(actualResponse).isSameInstanceAs(expectedResponse); - Mockito.verify(mockStub) - .newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any(GrpcCallContext.class)); + Mockito.verify(mockStub).newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any()); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java index 2b68829257..b66ab8f9b4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java @@ -16,7 +16,6 @@ package com.google.cloud.bigtable.data.v2.stub; import com.google.api.core.SettableApiFuture; -import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.v2.MutateRowRequest; import com.google.bigtable.v2.MutateRowResponse; @@ -45,8 +44,7 @@ public void setUp() { innerCallable = Mockito.mock(UnaryCallable.class); innerMutation = ArgumentCaptor.forClass(MutateRowRequest.class); innerResult = SettableApiFuture.create(); - Mockito.when( - innerCallable.futureCall(innerMutation.capture(), Mockito.any(ApiCallContext.class))) + Mockito.when(innerCallable.futureCall(innerMutation.capture(), Mockito.any())) .thenReturn(innerResult); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java index e7fb90941e..edc20e6081 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java @@ -16,21 +16,26 @@ package com.google.cloud.bigtable.data.v2.stub.readrows; import com.google.api.core.SettableApiFuture; -import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.Query; import com.google.cloud.bigtable.data.v2.models.Row; import com.google.common.truth.Truth; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.quality.Strictness; @RunWith(JUnit4.class) public class ReadRowsFirstCallableTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN); + private static final RequestContext REQUEST_CONTEXT = RequestContext.create("fake-project", "fake-instance", "fake-profile"); private UnaryCallable innerCallable; @@ -43,7 +48,7 @@ public void setUp() { innerCallable = Mockito.mock(UnaryCallable.class); innerQuery = ArgumentCaptor.forClass(Query.class); innerResult = SettableApiFuture.create(); - Mockito.when(innerCallable.futureCall(innerQuery.capture(), Mockito.any(ApiCallContext.class))) + Mockito.when(innerCallable.futureCall(innerQuery.capture(), Mockito.any())) .thenReturn(innerResult); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java index 1536b01e01..178dab1f12 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java @@ -53,9 +53,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.junit.runners.JUnit4; -@RunWith(MockitoJUnitRunner.class) +@RunWith(JUnit4.class) public class ReadRowsRetryTest { private static final String PROJECT_ID = "fake-project"; private static final String INSTANCE_ID = "fake-instance"; diff --git a/pom.xml b/pom.xml index 974c338f27..28daaef654 100644 --- a/pom.xml +++ b/pom.xml @@ -180,8 +180,8 @@ org.mockito - mockito-all - 1.10.19 + mockito-core + 3.12.4 From 04e088bb0be0abdba0ca71f95802ab8b5dc433d3 Mon Sep 17 00:00:00 2001 From: Kristen O'Leary Date: Tue, 14 Sep 2021 10:41:45 -0400 Subject: [PATCH 2/6] fix errors --- .../data/v2/stub/metrics/MetricsTracerTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java index eb7bdaa998..cfbc4617e3 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java @@ -132,7 +132,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { } }) .when(mockService) - .readRows(any(ReadRowsRequest.class), anyObserver(ReadRowsResponse.class)); + .readRows(any(ReadRowsRequest.class), any()); Stopwatch stopwatch = Stopwatch.createStarted(); Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); @@ -169,7 +169,7 @@ public Object answer(InvocationOnMock invocation) { } }) .when(mockService) - .readRows(any(ReadRowsRequest.class), anyObserver(ReadRowsResponse.class)); + .readRows(any(ReadRowsRequest.class), any()); Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); @@ -210,7 +210,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { } }) .when(mockService) - .readRows(any(ReadRowsRequest.class), anyObserver(ReadRowsResponse.class)); + .readRows(any(ReadRowsRequest.class), any()); Stopwatch stopwatch = Stopwatch.createStarted(); Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); @@ -258,7 +258,7 @@ public Object answer(InvocationOnMock invocation) { } }) .when(mockService) - .readRows(any(ReadRowsRequest.class), anyObserver(ReadRowsResponse.class)); + .readRows(any(ReadRowsRequest.class), any()); Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); @@ -305,7 +305,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { } }) .when(mockService) - .readRows(any(ReadRowsRequest.class), anyObserver(ReadRowsResponse.class)); + .readRows(any(ReadRowsRequest.class), any()); Stopwatch stopwatch = Stopwatch.createStarted(); Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID))); From 7a7c3d8607d8dcff7c78a63250c4ff8f95fae30a Mon Sep 17 00:00:00 2001 From: Kristen O'Leary Date: Tue, 14 Sep 2021 11:28:23 -0400 Subject: [PATCH 3/6] cleanup deprecated method use and mockito warnings --- .../v2/BigtableInstanceAdminClientTest.java | 77 ++++++---- .../v2/BigtableTableAdminClientTest.java | 133 ++++++++---------- .../data/v2/BigtableDataClientTest.java | 103 ++++++++++---- 3 files changed, 179 insertions(+), 134 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java index a1e457027f..528a51cf11 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java @@ -65,7 +65,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -196,30 +196,6 @@ public class BigtableInstanceAdminClientTest { @Before public void setUp() { adminClient = BigtableInstanceAdminClient.create(PROJECT_ID, mockStub); - - Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable); - Mockito.when(mockStub.partialUpdateInstanceOperationCallable()) - .thenReturn(mockUpdateInstanceCallable); - Mockito.when(mockStub.getInstanceCallable()).thenReturn(mockGetInstanceCallable); - Mockito.when(mockStub.listInstancesCallable()).thenReturn(mockListInstancesCallable); - Mockito.when(mockStub.deleteInstanceCallable()).thenReturn(mockDeleteInstanceCallable); - - Mockito.when(mockStub.createClusterOperationCallable()).thenReturn(mockCreateClusterCallable); - Mockito.when(mockStub.getClusterCallable()).thenReturn(mockGetClusterCallable); - Mockito.when(mockStub.listClustersCallable()).thenReturn(mockListClustersCallable); - Mockito.when(mockStub.updateClusterOperationCallable()).thenReturn(mockUpdateClusterCallable); - Mockito.when(mockStub.deleteClusterCallable()).thenReturn(mockDeleteClusterCallable); - - Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); - Mockito.when(mockStub.getAppProfileCallable()).thenReturn(mockGetAppProfileCallable); - Mockito.when(mockStub.listAppProfilesPagedCallable()).thenReturn(mockListAppProfilesCallable); - Mockito.when(mockStub.updateAppProfileOperationCallable()) - .thenReturn(mockUpdateAppProfileCallable); - Mockito.when(mockStub.deleteAppProfileCallable()).thenReturn(mockDeleteAppProfileCallable); - - Mockito.when(mockStub.getIamPolicyCallable()).thenReturn(mockGetIamPolicyCallable); - Mockito.when(mockStub.setIamPolicyCallable()).thenReturn(mockSetIamPolicyCallable); - Mockito.when(mockStub.testIamPermissionsCallable()).thenReturn(mockTestIamPermissionsCallable); } @Test @@ -236,6 +212,8 @@ public void testClose() { @Test public void testCreateInstance() { // Setup + Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable); + com.google.bigtable.admin.v2.CreateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.CreateInstanceRequest.newBuilder() .setParent(PROJECT_NAME) @@ -272,6 +250,9 @@ public void testCreateInstance() { @Test public void testUpdateInstance() { // Setup + Mockito.when(mockStub.partialUpdateInstanceOperationCallable()) + .thenReturn(mockUpdateInstanceCallable); + com.google.bigtable.admin.v2.PartialUpdateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.PartialUpdateInstanceRequest.newBuilder() .setUpdateMask(FieldMask.newBuilder().addPaths("display_name")) @@ -298,6 +279,8 @@ public void testUpdateInstance() { @Test public void testGetInstance() { // Setup + Mockito.when(mockStub.getInstanceCallable()).thenReturn(mockGetInstanceCallable); + com.google.bigtable.admin.v2.GetInstanceRequest expectedRequest = com.google.bigtable.admin.v2.GetInstanceRequest.newBuilder().setName(INSTANCE_NAME).build(); @@ -317,6 +300,8 @@ public void testGetInstance() { @Test public void testListInstances() { // Setup + Mockito.when(mockStub.listInstancesCallable()).thenReturn(mockListInstancesCallable); + com.google.bigtable.admin.v2.ListInstancesRequest expectedRequest = com.google.bigtable.admin.v2.ListInstancesRequest.newBuilder() .setParent(PROJECT_NAME) @@ -350,6 +335,8 @@ public void testListInstances() { @Test public void testListInstancesFailedZone() { // Setup + Mockito.when(mockStub.listInstancesCallable()).thenReturn(mockListInstancesCallable); + com.google.bigtable.admin.v2.ListInstancesRequest expectedRequest = com.google.bigtable.admin.v2.ListInstancesRequest.newBuilder() .setParent(PROJECT_NAME) @@ -389,6 +376,8 @@ public void testListInstancesFailedZone() { @Test public void testDeleteInstance() { // Setup + Mockito.when(mockStub.deleteInstanceCallable()).thenReturn(mockDeleteInstanceCallable); + com.google.bigtable.admin.v2.DeleteInstanceRequest expectedRequest = com.google.bigtable.admin.v2.DeleteInstanceRequest.newBuilder() .setName(INSTANCE_NAME) @@ -416,6 +405,8 @@ public ApiFuture answer(InvocationOnMock invocationOnMock) { @Test public void testCreateCluster() { // Setup + Mockito.when(mockStub.createClusterOperationCallable()).thenReturn(mockCreateClusterCallable); + com.google.bigtable.admin.v2.CreateClusterRequest expectedRequest = com.google.bigtable.admin.v2.CreateClusterRequest.newBuilder() .setParent(INSTANCE_NAME) @@ -444,6 +435,8 @@ public void testCreateCluster() { @Test public void testGetCluster() { // Setup + Mockito.when(mockStub.getClusterCallable()).thenReturn(mockGetClusterCallable); + com.google.bigtable.admin.v2.GetClusterRequest expectedRequest = com.google.bigtable.admin.v2.GetClusterRequest.newBuilder().setName(CLUSTER_NAME).build(); @@ -463,6 +456,8 @@ public void testGetCluster() { @Test public void testListClusters() { // Setup + Mockito.when(mockStub.listClustersCallable()).thenReturn(mockListClustersCallable); + com.google.bigtable.admin.v2.ListClustersRequest expectedRequest = com.google.bigtable.admin.v2.ListClustersRequest.newBuilder() .setParent(INSTANCE_NAME) @@ -492,6 +487,8 @@ public void testListClusters() { @Test public void testListClustersFailedZone() { // Setup + Mockito.when(mockStub.listClustersCallable()).thenReturn(mockListClustersCallable); + com.google.bigtable.admin.v2.ListClustersRequest expectedRequest = com.google.bigtable.admin.v2.ListClustersRequest.newBuilder() .setParent(INSTANCE_NAME) @@ -527,6 +524,8 @@ public void testListClustersFailedZone() { @Test public void testResizeCluster() { // Setup + Mockito.when(mockStub.updateClusterOperationCallable()).thenReturn(mockUpdateClusterCallable); + com.google.bigtable.admin.v2.Cluster expectedRequest = com.google.bigtable.admin.v2.Cluster.newBuilder() .setName(CLUSTER_NAME) @@ -552,6 +551,8 @@ public void testResizeCluster() { @Test public void testDeleteCluster() { // Setup + Mockito.when(mockStub.deleteClusterCallable()).thenReturn(mockDeleteClusterCallable); + com.google.bigtable.admin.v2.DeleteClusterRequest expectedRequest = com.google.bigtable.admin.v2.DeleteClusterRequest.newBuilder() .setName(CLUSTER_NAME) @@ -579,6 +580,8 @@ public ApiFuture answer(InvocationOnMock invocationOnMock) { @Test public void testCreateAppProfile() { // Setup + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) @@ -617,6 +620,8 @@ public void testCreateAppProfile() { @Test public void testGetAppProfile() { // Setup + Mockito.when(mockStub.getAppProfileCallable()).thenReturn(mockGetAppProfileCallable); + com.google.bigtable.admin.v2.GetAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.GetAppProfileRequest.newBuilder() .setName(APP_PROFILE_NAME) @@ -644,6 +649,8 @@ public void testGetAppProfile() { @Test public void testListAppProfiles() { // Setup + Mockito.when(mockStub.listAppProfilesPagedCallable()).thenReturn(mockListAppProfilesCallable); + com.google.bigtable.admin.v2.ListAppProfilesRequest expectedRequest = com.google.bigtable.admin.v2.ListAppProfilesRequest.newBuilder() .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) @@ -664,7 +671,6 @@ public void testListAppProfiles() { // 2 on the first page ListAppProfilesPage page0 = Mockito.mock(ListAppProfilesPage.class); Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2)); - Mockito.when(page0.getNextPageToken()).thenReturn("next-page"); Mockito.when(page0.hasNextPage()).thenReturn(true); // 1 on the last page @@ -696,6 +702,9 @@ public void testListAppProfiles() { @Test public void testUpdateAppProfile() { // Setup + Mockito.when(mockStub.updateAppProfileOperationCallable()) + .thenReturn(mockUpdateAppProfileCallable); + com.google.bigtable.admin.v2.UpdateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.UpdateAppProfileRequest.newBuilder() .setAppProfile( @@ -729,6 +738,8 @@ public void testUpdateAppProfile() { @Test public void testDeleteAppProfile() throws Exception { // Setup + Mockito.when(mockStub.deleteAppProfileCallable()).thenReturn(mockDeleteAppProfileCallable); + com.google.bigtable.admin.v2.DeleteAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.DeleteAppProfileRequest.newBuilder() .setName(APP_PROFILE_NAME) @@ -795,6 +806,8 @@ private void mockOperationResult( @Test public void testGetIamPolicy() { // Setup + Mockito.when(mockStub.getIamPolicyCallable()).thenReturn(mockGetIamPolicyCallable); + com.google.iam.v1.GetIamPolicyRequest expectedRequest = com.google.iam.v1.GetIamPolicyRequest.newBuilder() .setResource(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) @@ -827,6 +840,8 @@ public void testGetIamPolicy() { @Test public void testSetIamPolicy() { // Setup + Mockito.when(mockStub.setIamPolicyCallable()).thenReturn(mockSetIamPolicyCallable); + com.google.iam.v1.SetIamPolicyRequest expectedRequest = com.google.iam.v1.SetIamPolicyRequest.newBuilder() .setResource(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) @@ -870,6 +885,8 @@ public void testSetIamPolicy() { @Test public void testTestIamPermissions() { // Setup + Mockito.when(mockStub.testIamPermissionsCallable()).thenReturn(mockTestIamPermissionsCallable); + com.google.iam.v1.TestIamPermissionsRequest expectedRequest = com.google.iam.v1.TestIamPermissionsRequest.newBuilder() .setResource(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) @@ -895,12 +912,14 @@ public void testTestIamPermissions() { @Test public void testExistsTrue() { // Setup + Mockito.when(mockStub.getInstanceCallable()).thenReturn(mockGetInstanceCallable); + com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder() .setName(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) .build(); - Mockito.when(mockGetInstanceCallable.futureCall(Matchers.any(GetInstanceRequest.class))) + Mockito.when(mockGetInstanceCallable.futureCall(ArgumentMatchers.any(GetInstanceRequest.class))) .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute @@ -913,10 +932,12 @@ public void testExistsTrue() { @Test public void testExistsFalse() { // Setup + Mockito.when(mockStub.getInstanceCallable()).thenReturn(mockGetInstanceCallable); + NotFoundException exception = new NotFoundException("fake-error", null, GrpcStatusCode.of(Status.Code.NOT_FOUND), false); - Mockito.when(mockGetInstanceCallable.futureCall(Matchers.any(GetInstanceRequest.class))) + Mockito.when(mockGetInstanceCallable.futureCall(ArgumentMatchers.any(GetInstanceRequest.class))) .thenReturn( ApiFutures.immediateFailedFuture(exception)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java index 2b34c570a9..6e6b445758 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java @@ -67,7 +67,6 @@ import com.google.common.collect.Lists; import com.google.common.io.BaseEncoding; import com.google.longrunning.Operation; -import com.google.protobuf.Any; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; import com.google.protobuf.Timestamp; @@ -83,10 +82,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.stubbing.Answer; @@ -129,10 +127,6 @@ public class BigtableTableAdminClientTest { @Mock private UnaryCallable mockDropRowRangeCallable; @Mock private UnaryCallable mockAwaitReplicationCallable; - @Mock - private UnaryCallable - mockCreateBackupCallable; - @Mock private OperationCallable< com.google.bigtable.admin.v2.CreateBackupRequest, @@ -179,32 +173,13 @@ public class BigtableTableAdminClientTest { @Before public void setUp() { adminClient = BigtableTableAdminClient.create(PROJECT_ID, INSTANCE_ID, mockStub); - - Mockito.when(mockStub.createTableCallable()).thenReturn(mockCreateTableCallable); - Mockito.when(mockStub.modifyColumnFamiliesCallable()).thenReturn(mockModifyTableCallable); - Mockito.when(mockStub.deleteTableCallable()).thenReturn(mockDeleteTableCallable); - Mockito.when(mockStub.getTableCallable()).thenReturn(mockGetTableCallable); - Mockito.when(mockStub.listTablesPagedCallable()).thenReturn(mockListTableCallable); - Mockito.when(mockStub.dropRowRangeCallable()).thenReturn(mockDropRowRangeCallable); - Mockito.when(mockStub.awaitReplicationCallable()).thenReturn(mockAwaitReplicationCallable); - Mockito.when(mockStub.createBackupOperationCallable()) - .thenReturn(mockCreateBackupOperationCallable); - Mockito.when(mockStub.createBackupCallable()).thenReturn(mockCreateBackupCallable); - Mockito.when(mockStub.getBackupCallable()).thenReturn(mockGetBackupCallable); - Mockito.when(mockStub.listBackupsPagedCallable()).thenReturn(mockListBackupCallable); - Mockito.when(mockStub.updateBackupCallable()).thenReturn(mockUpdateBackupCallable); - Mockito.when(mockStub.deleteBackupCallable()).thenReturn(mockDeleteBackupCallable); - Mockito.when(mockStub.restoreTableCallable()).thenReturn(mockRestoreTableCallable); - Mockito.when(mockStub.restoreTableOperationCallable()) - .thenReturn(mockRestoreTableOperationCallable); - Mockito.when(mockStub.getIamPolicyCallable()).thenReturn(mockGetIamPolicyCallable); - Mockito.when(mockStub.setIamPolicyCallable()).thenReturn(mockSetIamPolicyCallable); - Mockito.when(mockStub.testIamPermissionsCallable()).thenReturn(mockTestIamPermissionsCallable); } @Test public void testCreateTable() { // Setup + Mockito.when(mockStub.createTableCallable()).thenReturn(mockCreateTableCallable); + com.google.bigtable.admin.v2.CreateTableRequest expectedRequest = com.google.bigtable.admin.v2.CreateTableRequest.newBuilder() .setParent(INSTANCE_NAME) @@ -227,6 +202,8 @@ public void testCreateTable() { @Test public void testModifyFamilies() { // Setup + Mockito.when(mockStub.modifyColumnFamiliesCallable()).thenReturn(mockModifyTableCallable); + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest expectedRequest = com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.newBuilder() .setName(TABLE_NAME) @@ -257,6 +234,8 @@ public void testModifyFamilies() { @Test public void testDeleteTable() { // Setup + Mockito.when(mockStub.deleteTableCallable()).thenReturn(mockDeleteTableCallable); + DeleteTableRequest expectedRequest = DeleteTableRequest.newBuilder().setName(TABLE_NAME).build(); @@ -264,13 +243,11 @@ public void testDeleteTable() { Mockito.when(mockDeleteTableCallable.futureCall(expectedRequest)) .thenAnswer( - new Answer>() { - @Override - public ApiFuture answer(InvocationOnMock invocationOnMock) { - wasCalled.set(true); - return ApiFutures.immediateFuture(Empty.getDefaultInstance()); - } - }); + (Answer>) + invocationOnMock -> { + wasCalled.set(true); + return ApiFutures.immediateFuture(Empty.getDefaultInstance()); + }); // Execute adminClient.deleteTable(TABLE_ID); @@ -282,6 +259,8 @@ public ApiFuture answer(InvocationOnMock invocationOnMock) { @Test public void testGetTable() { // Setup + Mockito.when(mockStub.getTableCallable()).thenReturn(mockGetTableCallable); + GetTableRequest expectedRequest = GetTableRequest.newBuilder().setName(TABLE_NAME).setView(View.SCHEMA_VIEW).build(); @@ -301,6 +280,8 @@ public void testGetTable() { @Test public void testGetEncryptionInfos() { // Setup + Mockito.when(mockStub.getTableCallable()).thenReturn(mockGetTableCallable); + GetTableRequest expectedRequest = GetTableRequest.newBuilder().setName(TABLE_NAME).setView(View.ENCRYPTION_VIEW).build(); @@ -340,6 +321,8 @@ public void testGetEncryptionInfos() { @Test public void testListTables() { // Setup + Mockito.when(mockStub.listTablesPagedCallable()).thenReturn(mockListTableCallable); + com.google.bigtable.admin.v2.ListTablesRequest expectedRequest = com.google.bigtable.admin.v2.ListTablesRequest.newBuilder() .setParent(INSTANCE_NAME) @@ -354,7 +337,6 @@ public void testListTables() { // 2 on the first page ListTablesPage page0 = Mockito.mock(ListTablesPage.class); Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2)); - Mockito.when(page0.getNextPageToken()).thenReturn("next-page"); Mockito.when(page0.hasNextPage()).thenReturn(true); // 1 on the last page @@ -386,6 +368,8 @@ public void testListTables() { @Test public void testDropRowRange() { // Setup + Mockito.when(mockStub.dropRowRangeCallable()).thenReturn(mockDropRowRangeCallable); + DropRowRangeRequest expectedRequest = DropRowRangeRequest.newBuilder() .setName(TABLE_NAME) @@ -398,13 +382,11 @@ public void testDropRowRange() { Mockito.when(mockDropRowRangeCallable.futureCall(expectedRequest)) .thenAnswer( - new Answer>() { - @Override - public ApiFuture answer(InvocationOnMock invocationOnMock) { - wasCalled.set(true); - return ApiFutures.immediateFuture(expectedResponse); - } - }); + (Answer>) + invocationOnMock -> { + wasCalled.set(true); + return ApiFutures.immediateFuture(expectedResponse); + }); // Execute adminClient.dropRowRange(TABLE_ID, "rowKeyPrefix"); @@ -416,19 +398,19 @@ public ApiFuture answer(InvocationOnMock invocationOnMock) { @Test public void testAwaitReplication() { // Setup + Mockito.when(mockStub.awaitReplicationCallable()).thenReturn(mockAwaitReplicationCallable); + TableName expectedRequest = TableName.parse(TABLE_NAME); final AtomicBoolean wasCalled = new AtomicBoolean(false); Mockito.when(mockAwaitReplicationCallable.futureCall(expectedRequest)) .thenAnswer( - new Answer>() { - @Override - public ApiFuture answer(InvocationOnMock invocationOnMock) { - wasCalled.set(true); - return ApiFutures.immediateFuture(null); - } - }); + (Answer>) + invocationOnMock -> { + wasCalled.set(true); + return ApiFutures.immediateFuture(null); + }); // Execute adminClient.awaitReplication(TABLE_ID); @@ -440,10 +422,12 @@ public ApiFuture answer(InvocationOnMock invocationOnMock) { @Test public void testExistsTrue() { // Setup + Mockito.when(mockStub.getTableCallable()).thenReturn(mockGetTableCallable); + com.google.bigtable.admin.v2.Table expectedResponse = com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build(); - Mockito.when(mockGetTableCallable.futureCall(Matchers.any(GetTableRequest.class))) + Mockito.when(mockGetTableCallable.futureCall(ArgumentMatchers.any(GetTableRequest.class))) .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute @@ -456,10 +440,12 @@ public void testExistsTrue() { @Test public void testExistsFalse() { // Setup + Mockito.when(mockStub.getTableCallable()).thenReturn(mockGetTableCallable); + NotFoundException exception = new NotFoundException("fake error", null, GrpcStatusCode.of(Status.Code.NOT_FOUND), false); - Mockito.when(mockGetTableCallable.futureCall(Matchers.any(GetTableRequest.class))) + Mockito.when(mockGetTableCallable.futureCall(ArgumentMatchers.any(GetTableRequest.class))) .thenReturn( ApiFutures.immediateFailedFuture(exception)); @@ -473,6 +459,9 @@ public void testExistsFalse() { @Test public void testCreateBackup() { // Setup + Mockito.when(mockStub.createBackupOperationCallable()) + .thenReturn(mockCreateBackupOperationCallable); + String backupName = NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID); Timestamp startTime = Timestamp.newBuilder().setSeconds(123).build(); Timestamp endTime = Timestamp.newBuilder().setSeconds(456).build(); @@ -515,6 +504,8 @@ public void testCreateBackup() { @Test public void testGetBackup() { // Setup + Mockito.when(mockStub.getBackupCallable()).thenReturn(mockGetBackupCallable); + Timestamp expireTime = Timestamp.newBuilder().setSeconds(123456789).build(); Timestamp startTime = Timestamp.newBuilder().setSeconds(1234).build(); Timestamp endTime = Timestamp.newBuilder().setSeconds(5678).build(); @@ -557,6 +548,8 @@ public void testGetBackup() { @Test public void testUpdateBackup() { // Setup + Mockito.when(mockStub.updateBackupCallable()).thenReturn(mockUpdateBackupCallable); + Timestamp expireTime = Timestamp.newBuilder().setSeconds(123456789).build(); long sizeBytes = 12345L; UpdateBackupRequest req = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID); @@ -585,32 +578,13 @@ public void testUpdateBackup() { @Test public void testRestoreTable() throws ExecutionException, InterruptedException { // Setup + Mockito.when(mockStub.restoreTableOperationCallable()) + .thenReturn(mockRestoreTableOperationCallable); + Timestamp startTime = Timestamp.newBuilder().setSeconds(1234).build(); Timestamp endTime = Timestamp.newBuilder().setSeconds(5678).build(); String operationName = "my-operation"; RestoreTableRequest req = RestoreTableRequest.of(CLUSTER_ID, BACKUP_ID).setTableId(TABLE_ID); - Mockito.when(mockRestoreTableCallable.futureCall(req.toProto(PROJECT_ID, INSTANCE_ID))) - .thenReturn( - ApiFutures.immediateFuture( - Operation.newBuilder() - .setMetadata( - Any.pack( - RestoreTableMetadata.newBuilder() - .setName( - NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) - .setOptimizeTableOperationName(operationName) - .setSourceType(RestoreSourceType.BACKUP) - .setBackupInfo( - BackupInfo.newBuilder() - .setBackup(BACKUP_ID) - .setSourceTable( - NameUtil.formatTableName( - PROJECT_ID, INSTANCE_ID, TABLE_ID)) - .setStartTime(startTime) - .setEndTime(endTime) - .build()) - .build())) - .build())); mockOperationResult( mockRestoreTableOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -637,6 +611,8 @@ public void testRestoreTable() throws ExecutionException, InterruptedException { @Test public void testDeleteBackup() { // Setup + Mockito.when(mockStub.deleteBackupCallable()).thenReturn(mockDeleteBackupCallable); + DeleteBackupRequest testRequest = DeleteBackupRequest.newBuilder() .setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)) @@ -654,6 +630,8 @@ public void testDeleteBackup() { @Test public void testListBackups() { // Setup + Mockito.when(mockStub.listBackupsPagedCallable()).thenReturn(mockListBackupCallable); + com.google.bigtable.admin.v2.ListBackupsRequest testRequest = com.google.bigtable.admin.v2.ListBackupsRequest.newBuilder() .setParent(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)) @@ -672,7 +650,6 @@ public void testListBackups() { // 2 on the first page ListBackupsPage page0 = Mockito.mock(ListBackupsPage.class); Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2)); - Mockito.when(page0.getNextPageToken()).thenReturn("next-page"); Mockito.when(page0.hasNextPage()).thenReturn(true); // 1 on the last page @@ -704,6 +681,8 @@ public void testListBackups() { @Test public void testGetBackupIamPolicy() { // Setup + Mockito.when(mockStub.getIamPolicyCallable()).thenReturn(mockGetIamPolicyCallable); + com.google.iam.v1.GetIamPolicyRequest expectedRequest = com.google.iam.v1.GetIamPolicyRequest.newBuilder() .setResource(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)) @@ -736,6 +715,8 @@ public void testGetBackupIamPolicy() { @Test public void testSetIamPolicy() { // Setup + Mockito.when(mockStub.setIamPolicyCallable()).thenReturn(mockSetIamPolicyCallable); + com.google.iam.v1.SetIamPolicyRequest expectedRequest = com.google.iam.v1.SetIamPolicyRequest.newBuilder() .setResource(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)) @@ -780,6 +761,8 @@ public void testSetIamPolicy() { @Test public void testTestIamPermissions() { // Setup + Mockito.when(mockStub.testIamPermissionsCallable()).thenReturn(mockTestIamPermissionsCallable); + com.google.iam.v1.TestIamPermissionsRequest expectedRequest = com.google.iam.v1.TestIamPermissionsRequest.newBuilder() .setResource(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index 30e2b513ee..940d632c12 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -17,7 +17,6 @@ import static com.google.cloud.bigtable.data.v2.models.Filters.FILTERS; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Matchers.any; import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; @@ -48,9 +47,9 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Answers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; @@ -80,27 +79,18 @@ public class BigtableDataClientTest { @Before public void setUp() { bigtableDataClient = new BigtableDataClient(mockStub); - Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable); - Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); - Mockito.when(mockStub.sampleRowKeysCallable()).thenReturn(mockSampleRowKeysCallable); - Mockito.when(mockStub.mutateRowCallable()).thenReturn(mockMutateRowCallable); - Mockito.when(mockStub.bulkMutateRowsCallable()).thenReturn(mockBulkMutateRowsCallable); - Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable); - Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable); - Mockito.when(mockStub.newMutateRowsBatcher(Mockito.any(String.class), Mockito.any())) - .thenReturn(mockBulkMutationBatcher); - Mockito.when(mockStub.newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any())) - .thenReturn(mockBulkReadRowsBatcher); } @Test - public void proxyCloseTest() throws Exception { + public void proxyCloseTest() { bigtableDataClient.close(); Mockito.verify(mockStub).close(); } @Test public void existsTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + Query expectedQuery = Query.create("fake-table") .rowKey("fake-row-key") @@ -126,6 +116,8 @@ public void existsTest() { @Test public void existsAsyncTest() throws Exception { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + Query expectedQuery = Query.create("fake-table") .rowKey("fake-row-key") @@ -152,11 +144,14 @@ public void existsAsyncTest() throws Exception { @Test public void proxyReadRowsCallableTest() { + Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable); assertThat(bigtableDataClient.readRowsCallable()).isSameInstanceAs(mockReadRowsCallable); } @Test public void proxyReadRowAsyncTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + bigtableDataClient.readRowAsync("fake-table", ByteString.copyFromUtf8("fake-row-key")); Mockito.verify(mockReadRowCallable) .futureCall(Query.create("fake-table").rowKey("fake-row-key")); @@ -164,6 +159,8 @@ public void proxyReadRowAsyncTest() { @Test public void proxyReadRowStrAsyncTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + bigtableDataClient.readRowAsync("fake-table", "fake-row-key"); Mockito.verify(mockReadRowCallable) .futureCall(Query.create("fake-table").rowKey("fake-row-key")); @@ -171,6 +168,8 @@ public void proxyReadRowStrAsyncTest() { @Test public void readRowFilterAsyncTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + // Build the filter expression Filter filter = FILTERS @@ -185,6 +184,8 @@ public void readRowFilterAsyncTest() { @Test public void readRowFilterStrAsyncTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + // Build the filter expression Filter filter = FILTERS @@ -199,6 +200,8 @@ public void readRowFilterStrAsyncTest() { @Test public void readRowTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.of()); Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key"))) @@ -212,6 +215,8 @@ public void readRowTest() { @Test public void readRowStrTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.of()); Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key"))) @@ -224,6 +229,8 @@ public void readRowStrTest() { @Test public void readRowFilterTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + // Build the filter expression Filter filter = FILTERS @@ -246,6 +253,8 @@ public void readRowFilterTest() { @Test public void readRowStrFilterTest() { + Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable); + // Build the filter expression Filter filter = FILTERS @@ -266,6 +275,8 @@ public void readRowStrFilterTest() { @Test public void proxyReadRowsSyncTest() { + Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable); + Query query = Query.create("fake-table"); bigtableDataClient.readRows(query); @@ -274,6 +285,8 @@ public void proxyReadRowsSyncTest() { @Test public void proxyReadRowsAsyncTest() { + Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable); + Query query = Query.create("fake-table"); @SuppressWarnings("unchecked") ResponseObserver mockObserver = Mockito.mock(ResponseObserver.class); @@ -284,19 +297,25 @@ public void proxyReadRowsAsyncTest() { @Test public void proxySampleRowKeysCallableTest() { + Mockito.when(mockStub.sampleRowKeysCallable()).thenReturn(mockSampleRowKeysCallable); + assertThat(bigtableDataClient.sampleRowKeysCallable()) .isSameInstanceAs(mockSampleRowKeysCallable); } @Test public void proxySampleRowKeysTest() { + Mockito.when(mockStub.sampleRowKeysCallable()).thenReturn(mockSampleRowKeysCallable); + bigtableDataClient.sampleRowKeysAsync("fake-table"); Mockito.verify(mockSampleRowKeysCallable).futureCall("fake-table"); } @Test public void sampleRowKeysTest() { - Mockito.when(mockSampleRowKeysCallable.futureCall(any(String.class))) + Mockito.when(mockStub.sampleRowKeysCallable()).thenReturn(mockSampleRowKeysCallable); + + Mockito.when(mockSampleRowKeysCallable.futureCall(ArgumentMatchers.any(String.class))) .thenReturn(ApiFutures.immediateFuture(Collections.emptyList())); bigtableDataClient.sampleRowKeys("fake-table"); Mockito.verify(mockSampleRowKeysCallable).futureCall("fake-table"); @@ -304,11 +323,15 @@ public void sampleRowKeysTest() { @Test public void proxyMutateRowCallableTest() { + Mockito.when(mockStub.mutateRowCallable()).thenReturn(mockMutateRowCallable); + assertThat(bigtableDataClient.mutateRowCallable()).isSameInstanceAs(mockMutateRowCallable); } @Test public void proxyMutateRowTest() { + Mockito.when(mockStub.mutateRowCallable()).thenReturn(mockMutateRowCallable); + RowMutation request = RowMutation.create("fake-table", "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); @@ -319,14 +342,10 @@ public void proxyMutateRowTest() { @Test public void mutateRowTest() { - Mockito.when(mockMutateRowCallable.futureCall(any(RowMutation.class))) + Mockito.when(mockStub.mutateRowCallable()).thenReturn(mockMutateRowCallable); + Mockito.when(mockMutateRowCallable.futureCall(ArgumentMatchers.any(RowMutation.class))) .thenAnswer( - new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - return ApiFutures.immediateFuture(Empty.getDefaultInstance()); - } - }); + (Answer) invocationOnMock -> ApiFutures.immediateFuture(Empty.getDefaultInstance())); RowMutation request = RowMutation.create("fake-table", "some-key") @@ -338,6 +357,8 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { @Test public void proxyBulkMutatesRowTest() { + Mockito.when(mockStub.bulkMutateRowsCallable()).thenReturn(mockBulkMutateRowsCallable); + BulkMutation request = BulkMutation.create("fake-table") .add( @@ -350,14 +371,11 @@ public void proxyBulkMutatesRowTest() { @Test public void bulkMutatesRowTest() { - Mockito.when(mockBulkMutateRowsCallable.futureCall(any(BulkMutation.class))) + Mockito.when(mockStub.bulkMutateRowsCallable()).thenReturn(mockBulkMutateRowsCallable); + + Mockito.when(mockBulkMutateRowsCallable.futureCall(ArgumentMatchers.any(BulkMutation.class))) .thenAnswer( - new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - return ApiFutures.immediateFuture(Empty.getDefaultInstance()); - } - }); + (Answer) invocationOnMock -> ApiFutures.immediateFuture(Empty.getDefaultInstance())); BulkMutation request = BulkMutation.create("fake-table") @@ -371,6 +389,9 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { @Test public void proxyNewBulkMutationBatcherTest() { + Mockito.when(mockStub.newMutateRowsBatcher(Mockito.any(String.class), Mockito.any())) + .thenReturn(mockBulkMutationBatcher); + ApiFuture expectedResponse = ApiFutures.immediateFuture(null); Batcher batcher = bigtableDataClient.newBulkMutationBatcher("fake-table"); @@ -386,6 +407,9 @@ public void proxyNewBulkMutationBatcherTest() { @Test public void proxyNewBulkReadRowsTest() { + Mockito.when(mockStub.newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any())) + .thenReturn(mockBulkReadRowsBatcher); + ApiFuture expectedResponse = ApiFutures.immediateFuture( Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList())); @@ -402,6 +426,9 @@ public void proxyNewBulkReadRowsTest() { @Test public void proxyNewBulkReadRowsWithFilterTest() { + Mockito.when(mockStub.newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any())) + .thenReturn(mockBulkReadRowsBatcher); + ApiFuture expectedResponse = ApiFutures.immediateFuture( Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList())); @@ -425,6 +452,8 @@ public void proxyCheckAndMutateRowCallableTest() { @Test public void proxyCheckAndMutateRowTest() { + Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable); + ConditionalRowMutation mutation = ConditionalRowMutation.create("fake-table", "fake-key") .then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); @@ -435,7 +464,11 @@ public void proxyCheckAndMutateRowTest() { @Test public void checkAndMutateRowTest() { - Mockito.when(mockCheckAndMutateRowCallable.futureCall(any(ConditionalRowMutation.class))) + Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable); + + Mockito.when( + mockCheckAndMutateRowCallable.futureCall( + ArgumentMatchers.any(ConditionalRowMutation.class))) .thenReturn(ApiFutures.immediateFuture(Boolean.TRUE)); ConditionalRowMutation mutation = ConditionalRowMutation.create("fake-table", "fake-key") @@ -447,6 +480,8 @@ public void checkAndMutateRowTest() { @Test public void proxyReadModifyWriteRowTest() { + Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable); + ReadModifyWriteRow request = ReadModifyWriteRow.create("fake-table", "some-key") .append("fake-family", "fake-qualifier", "suffix"); @@ -456,7 +491,11 @@ public void proxyReadModifyWriteRowTest() { @Test public void readModifyWriteRowTest() { - Mockito.when(mockReadModifyWriteRowCallable.futureCall(any(ReadModifyWriteRow.class))) + Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable); + + Mockito.when( + mockReadModifyWriteRowCallable.futureCall( + ArgumentMatchers.any(ReadModifyWriteRow.class))) .thenReturn( ApiFutures.immediateFuture( Row.create( @@ -470,6 +509,8 @@ public void readModifyWriteRowTest() { @Test public void proxyReadModifyWriterRowCallableTest() { + Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable); + assertThat(bigtableDataClient.readModifyWriteRowCallable()) .isSameInstanceAs(mockReadModifyWriteRowCallable); } From 60a9aead7f22b71489e485099355262c9842c1e1 Mon Sep 17 00:00:00 2001 From: Kristen O'Leary Date: Tue, 14 Sep 2021 12:48:06 -0400 Subject: [PATCH 4/6] cleanup deprecated method use and mockito warnings --- .../cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java index cfbc4617e3..735629977f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java @@ -16,7 +16,7 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import com.google.api.gax.rpc.ClientContext; From f2b699a9ac2d14e3d3bbb2d969cfe729dbf591f8 Mon Sep 17 00:00:00 2001 From: Kristen O'Leary Date: Tue, 14 Sep 2021 13:03:18 -0400 Subject: [PATCH 5/6] cleanup deprecated method use and mockito warnings --- .../cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java index 735629977f..cfbc4617e3 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java @@ -16,7 +16,7 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import com.google.api.gax.rpc.ClientContext; From e28f47e62ab97afea8c25e8d7afdd40f630b60a3 Mon Sep 17 00:00:00 2001 From: Kristen O'Leary Date: Tue, 14 Sep 2021 12:48:06 -0400 Subject: [PATCH 6/6] cleanup deprecated method use and mockito warnings --- .../cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java index cfbc4617e3..735629977f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java @@ -16,7 +16,7 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import com.google.api.gax.rpc.ClientContext;