6161import java .util .concurrent .atomic .AtomicBoolean ;
6262import java .util .concurrent .atomic .AtomicInteger ;
6363import org .junit .Before ;
64+ import org .junit .Rule ;
6465import org .junit .Test ;
6566import org .junit .runner .RunWith ;
66- import org .mockito .Matchers ;
67+ import org .junit .runners .JUnit4 ;
68+ import org .mockito .ArgumentMatchers ;
6769import org .mockito .Mock ;
6870import org .mockito .Mockito ;
6971import org .mockito .invocation .InvocationOnMock ;
70- import org .mockito .runners .MockitoJUnitRunner ;
72+ import org .mockito .junit .MockitoJUnit ;
73+ import org .mockito .junit .MockitoRule ;
74+ import org .mockito .quality .Strictness ;
7175import org .mockito .stubbing .Answer ;
7276
73- @ RunWith (MockitoJUnitRunner .class )
77+ @ RunWith (JUnit4 .class )
7478public class BigtableInstanceAdminClientTest {
79+ @ Rule public MockitoRule mockitoRule = MockitoJUnit .rule ().strictness (Strictness .WARN );
7580
7681 private static final String PROJECT_ID = "my-project" ;
7782 private static final String INSTANCE_ID = "my-instance" ;
@@ -191,30 +196,6 @@ public class BigtableInstanceAdminClientTest {
191196 @ Before
192197 public void setUp () {
193198 adminClient = BigtableInstanceAdminClient .create (PROJECT_ID , mockStub );
194-
195- Mockito .when (mockStub .createInstanceOperationCallable ()).thenReturn (mockCreateInstanceCallable );
196- Mockito .when (mockStub .partialUpdateInstanceOperationCallable ())
197- .thenReturn (mockUpdateInstanceCallable );
198- Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
199- Mockito .when (mockStub .listInstancesCallable ()).thenReturn (mockListInstancesCallable );
200- Mockito .when (mockStub .deleteInstanceCallable ()).thenReturn (mockDeleteInstanceCallable );
201-
202- Mockito .when (mockStub .createClusterOperationCallable ()).thenReturn (mockCreateClusterCallable );
203- Mockito .when (mockStub .getClusterCallable ()).thenReturn (mockGetClusterCallable );
204- Mockito .when (mockStub .listClustersCallable ()).thenReturn (mockListClustersCallable );
205- Mockito .when (mockStub .updateClusterOperationCallable ()).thenReturn (mockUpdateClusterCallable );
206- Mockito .when (mockStub .deleteClusterCallable ()).thenReturn (mockDeleteClusterCallable );
207-
208- Mockito .when (mockStub .createAppProfileCallable ()).thenReturn (mockCreateAppProfileCallable );
209- Mockito .when (mockStub .getAppProfileCallable ()).thenReturn (mockGetAppProfileCallable );
210- Mockito .when (mockStub .listAppProfilesPagedCallable ()).thenReturn (mockListAppProfilesCallable );
211- Mockito .when (mockStub .updateAppProfileOperationCallable ())
212- .thenReturn (mockUpdateAppProfileCallable );
213- Mockito .when (mockStub .deleteAppProfileCallable ()).thenReturn (mockDeleteAppProfileCallable );
214-
215- Mockito .when (mockStub .getIamPolicyCallable ()).thenReturn (mockGetIamPolicyCallable );
216- Mockito .when (mockStub .setIamPolicyCallable ()).thenReturn (mockSetIamPolicyCallable );
217- Mockito .when (mockStub .testIamPermissionsCallable ()).thenReturn (mockTestIamPermissionsCallable );
218199 }
219200
220201 @ Test
@@ -231,6 +212,8 @@ public void testClose() {
231212 @ Test
232213 public void testCreateInstance () {
233214 // Setup
215+ Mockito .when (mockStub .createInstanceOperationCallable ()).thenReturn (mockCreateInstanceCallable );
216+
234217 com .google .bigtable .admin .v2 .CreateInstanceRequest expectedRequest =
235218 com .google .bigtable .admin .v2 .CreateInstanceRequest .newBuilder ()
236219 .setParent (PROJECT_NAME )
@@ -267,6 +250,9 @@ public void testCreateInstance() {
267250 @ Test
268251 public void testUpdateInstance () {
269252 // Setup
253+ Mockito .when (mockStub .partialUpdateInstanceOperationCallable ())
254+ .thenReturn (mockUpdateInstanceCallable );
255+
270256 com .google .bigtable .admin .v2 .PartialUpdateInstanceRequest expectedRequest =
271257 com .google .bigtable .admin .v2 .PartialUpdateInstanceRequest .newBuilder ()
272258 .setUpdateMask (FieldMask .newBuilder ().addPaths ("display_name" ))
@@ -293,6 +279,8 @@ public void testUpdateInstance() {
293279 @ Test
294280 public void testGetInstance () {
295281 // Setup
282+ Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
283+
296284 com .google .bigtable .admin .v2 .GetInstanceRequest expectedRequest =
297285 com .google .bigtable .admin .v2 .GetInstanceRequest .newBuilder ().setName (INSTANCE_NAME ).build ();
298286
@@ -312,6 +300,8 @@ public void testGetInstance() {
312300 @ Test
313301 public void testListInstances () {
314302 // Setup
303+ Mockito .when (mockStub .listInstancesCallable ()).thenReturn (mockListInstancesCallable );
304+
315305 com .google .bigtable .admin .v2 .ListInstancesRequest expectedRequest =
316306 com .google .bigtable .admin .v2 .ListInstancesRequest .newBuilder ()
317307 .setParent (PROJECT_NAME )
@@ -345,6 +335,8 @@ public void testListInstances() {
345335 @ Test
346336 public void testListInstancesFailedZone () {
347337 // Setup
338+ Mockito .when (mockStub .listInstancesCallable ()).thenReturn (mockListInstancesCallable );
339+
348340 com .google .bigtable .admin .v2 .ListInstancesRequest expectedRequest =
349341 com .google .bigtable .admin .v2 .ListInstancesRequest .newBuilder ()
350342 .setParent (PROJECT_NAME )
@@ -384,6 +376,8 @@ public void testListInstancesFailedZone() {
384376 @ Test
385377 public void testDeleteInstance () {
386378 // Setup
379+ Mockito .when (mockStub .deleteInstanceCallable ()).thenReturn (mockDeleteInstanceCallable );
380+
387381 com .google .bigtable .admin .v2 .DeleteInstanceRequest expectedRequest =
388382 com .google .bigtable .admin .v2 .DeleteInstanceRequest .newBuilder ()
389383 .setName (INSTANCE_NAME )
@@ -411,6 +405,8 @@ public ApiFuture<Empty> answer(InvocationOnMock invocationOnMock) {
411405 @ Test
412406 public void testCreateCluster () {
413407 // Setup
408+ Mockito .when (mockStub .createClusterOperationCallable ()).thenReturn (mockCreateClusterCallable );
409+
414410 com .google .bigtable .admin .v2 .CreateClusterRequest expectedRequest =
415411 com .google .bigtable .admin .v2 .CreateClusterRequest .newBuilder ()
416412 .setParent (INSTANCE_NAME )
@@ -439,6 +435,8 @@ public void testCreateCluster() {
439435 @ Test
440436 public void testGetCluster () {
441437 // Setup
438+ Mockito .when (mockStub .getClusterCallable ()).thenReturn (mockGetClusterCallable );
439+
442440 com .google .bigtable .admin .v2 .GetClusterRequest expectedRequest =
443441 com .google .bigtable .admin .v2 .GetClusterRequest .newBuilder ().setName (CLUSTER_NAME ).build ();
444442
@@ -458,6 +456,8 @@ public void testGetCluster() {
458456 @ Test
459457 public void testListClusters () {
460458 // Setup
459+ Mockito .when (mockStub .listClustersCallable ()).thenReturn (mockListClustersCallable );
460+
461461 com .google .bigtable .admin .v2 .ListClustersRequest expectedRequest =
462462 com .google .bigtable .admin .v2 .ListClustersRequest .newBuilder ()
463463 .setParent (INSTANCE_NAME )
@@ -487,6 +487,8 @@ public void testListClusters() {
487487 @ Test
488488 public void testListClustersFailedZone () {
489489 // Setup
490+ Mockito .when (mockStub .listClustersCallable ()).thenReturn (mockListClustersCallable );
491+
490492 com .google .bigtable .admin .v2 .ListClustersRequest expectedRequest =
491493 com .google .bigtable .admin .v2 .ListClustersRequest .newBuilder ()
492494 .setParent (INSTANCE_NAME )
@@ -522,6 +524,8 @@ public void testListClustersFailedZone() {
522524 @ Test
523525 public void testResizeCluster () {
524526 // Setup
527+ Mockito .when (mockStub .updateClusterOperationCallable ()).thenReturn (mockUpdateClusterCallable );
528+
525529 com .google .bigtable .admin .v2 .Cluster expectedRequest =
526530 com .google .bigtable .admin .v2 .Cluster .newBuilder ()
527531 .setName (CLUSTER_NAME )
@@ -547,6 +551,8 @@ public void testResizeCluster() {
547551 @ Test
548552 public void testDeleteCluster () {
549553 // Setup
554+ Mockito .when (mockStub .deleteClusterCallable ()).thenReturn (mockDeleteClusterCallable );
555+
550556 com .google .bigtable .admin .v2 .DeleteClusterRequest expectedRequest =
551557 com .google .bigtable .admin .v2 .DeleteClusterRequest .newBuilder ()
552558 .setName (CLUSTER_NAME )
@@ -574,6 +580,8 @@ public ApiFuture<Empty> answer(InvocationOnMock invocationOnMock) {
574580 @ Test
575581 public void testCreateAppProfile () {
576582 // Setup
583+ Mockito .when (mockStub .createAppProfileCallable ()).thenReturn (mockCreateAppProfileCallable );
584+
577585 com .google .bigtable .admin .v2 .CreateAppProfileRequest expectedRequest =
578586 com .google .bigtable .admin .v2 .CreateAppProfileRequest .newBuilder ()
579587 .setParent (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -612,6 +620,8 @@ public void testCreateAppProfile() {
612620 @ Test
613621 public void testGetAppProfile () {
614622 // Setup
623+ Mockito .when (mockStub .getAppProfileCallable ()).thenReturn (mockGetAppProfileCallable );
624+
615625 com .google .bigtable .admin .v2 .GetAppProfileRequest expectedRequest =
616626 com .google .bigtable .admin .v2 .GetAppProfileRequest .newBuilder ()
617627 .setName (APP_PROFILE_NAME )
@@ -639,6 +649,8 @@ public void testGetAppProfile() {
639649 @ Test
640650 public void testListAppProfiles () {
641651 // Setup
652+ Mockito .when (mockStub .listAppProfilesPagedCallable ()).thenReturn (mockListAppProfilesCallable );
653+
642654 com .google .bigtable .admin .v2 .ListAppProfilesRequest expectedRequest =
643655 com .google .bigtable .admin .v2 .ListAppProfilesRequest .newBuilder ()
644656 .setParent (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -659,7 +671,6 @@ public void testListAppProfiles() {
659671 // 2 on the first page
660672 ListAppProfilesPage page0 = Mockito .mock (ListAppProfilesPage .class );
661673 Mockito .when (page0 .getValues ()).thenReturn (expectedProtos .subList (0 , 2 ));
662- Mockito .when (page0 .getNextPageToken ()).thenReturn ("next-page" );
663674 Mockito .when (page0 .hasNextPage ()).thenReturn (true );
664675
665676 // 1 on the last page
@@ -691,6 +702,9 @@ public void testListAppProfiles() {
691702 @ Test
692703 public void testUpdateAppProfile () {
693704 // Setup
705+ Mockito .when (mockStub .updateAppProfileOperationCallable ())
706+ .thenReturn (mockUpdateAppProfileCallable );
707+
694708 com .google .bigtable .admin .v2 .UpdateAppProfileRequest expectedRequest =
695709 com .google .bigtable .admin .v2 .UpdateAppProfileRequest .newBuilder ()
696710 .setAppProfile (
@@ -724,6 +738,8 @@ public void testUpdateAppProfile() {
724738 @ Test
725739 public void testDeleteAppProfile () throws Exception {
726740 // Setup
741+ Mockito .when (mockStub .deleteAppProfileCallable ()).thenReturn (mockDeleteAppProfileCallable );
742+
727743 com .google .bigtable .admin .v2 .DeleteAppProfileRequest expectedRequest =
728744 com .google .bigtable .admin .v2 .DeleteAppProfileRequest .newBuilder ()
729745 .setName (APP_PROFILE_NAME )
@@ -790,6 +806,8 @@ private <ReqT, RespT, MetaT> void mockOperationResult(
790806 @ Test
791807 public void testGetIamPolicy () {
792808 // Setup
809+ Mockito .when (mockStub .getIamPolicyCallable ()).thenReturn (mockGetIamPolicyCallable );
810+
793811 com .google .iam .v1 .GetIamPolicyRequest expectedRequest =
794812 com .google .iam .v1 .GetIamPolicyRequest .newBuilder ()
795813 .setResource (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -822,6 +840,8 @@ public void testGetIamPolicy() {
822840 @ Test
823841 public void testSetIamPolicy () {
824842 // Setup
843+ Mockito .when (mockStub .setIamPolicyCallable ()).thenReturn (mockSetIamPolicyCallable );
844+
825845 com .google .iam .v1 .SetIamPolicyRequest expectedRequest =
826846 com .google .iam .v1 .SetIamPolicyRequest .newBuilder ()
827847 .setResource (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -865,6 +885,8 @@ public void testSetIamPolicy() {
865885 @ Test
866886 public void testTestIamPermissions () {
867887 // Setup
888+ Mockito .when (mockStub .testIamPermissionsCallable ()).thenReturn (mockTestIamPermissionsCallable );
889+
868890 com .google .iam .v1 .TestIamPermissionsRequest expectedRequest =
869891 com .google .iam .v1 .TestIamPermissionsRequest .newBuilder ()
870892 .setResource (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -890,12 +912,14 @@ public void testTestIamPermissions() {
890912 @ Test
891913 public void testExistsTrue () {
892914 // Setup
915+ Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
916+
893917 com .google .bigtable .admin .v2 .Instance expectedResponse =
894918 com .google .bigtable .admin .v2 .Instance .newBuilder ()
895919 .setName (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
896920 .build ();
897921
898- Mockito .when (mockGetInstanceCallable .futureCall (Matchers .any (GetInstanceRequest .class )))
922+ Mockito .when (mockGetInstanceCallable .futureCall (ArgumentMatchers .any (GetInstanceRequest .class )))
899923 .thenReturn (ApiFutures .immediateFuture (expectedResponse ));
900924
901925 // Execute
@@ -908,10 +932,12 @@ public void testExistsTrue() {
908932 @ Test
909933 public void testExistsFalse () {
910934 // Setup
935+ Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
936+
911937 NotFoundException exception =
912938 new NotFoundException ("fake-error" , null , GrpcStatusCode .of (Status .Code .NOT_FOUND ), false );
913939
914- Mockito .when (mockGetInstanceCallable .futureCall (Matchers .any (GetInstanceRequest .class )))
940+ Mockito .when (mockGetInstanceCallable .futureCall (ArgumentMatchers .any (GetInstanceRequest .class )))
915941 .thenReturn (
916942 ApiFutures .<com .google .bigtable .admin .v2 .Instance >immediateFailedFuture (exception ));
917943
0 commit comments