61
61
import java .util .concurrent .atomic .AtomicBoolean ;
62
62
import java .util .concurrent .atomic .AtomicInteger ;
63
63
import org .junit .Before ;
64
+ import org .junit .Rule ;
64
65
import org .junit .Test ;
65
66
import org .junit .runner .RunWith ;
66
- import org .mockito .Matchers ;
67
+ import org .junit .runners .JUnit4 ;
68
+ import org .mockito .ArgumentMatchers ;
67
69
import org .mockito .Mock ;
68
70
import org .mockito .Mockito ;
69
71
import 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 ;
71
75
import org .mockito .stubbing .Answer ;
72
76
73
- @ RunWith (MockitoJUnitRunner .class )
77
+ @ RunWith (JUnit4 .class )
74
78
public class BigtableInstanceAdminClientTest {
79
+ @ Rule public MockitoRule mockitoRule = MockitoJUnit .rule ().strictness (Strictness .WARN );
75
80
76
81
private static final String PROJECT_ID = "my-project" ;
77
82
private static final String INSTANCE_ID = "my-instance" ;
@@ -191,30 +196,6 @@ public class BigtableInstanceAdminClientTest {
191
196
@ Before
192
197
public void setUp () {
193
198
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 );
218
199
}
219
200
220
201
@ Test
@@ -231,6 +212,8 @@ public void testClose() {
231
212
@ Test
232
213
public void testCreateInstance () {
233
214
// Setup
215
+ Mockito .when (mockStub .createInstanceOperationCallable ()).thenReturn (mockCreateInstanceCallable );
216
+
234
217
com .google .bigtable .admin .v2 .CreateInstanceRequest expectedRequest =
235
218
com .google .bigtable .admin .v2 .CreateInstanceRequest .newBuilder ()
236
219
.setParent (PROJECT_NAME )
@@ -267,6 +250,9 @@ public void testCreateInstance() {
267
250
@ Test
268
251
public void testUpdateInstance () {
269
252
// Setup
253
+ Mockito .when (mockStub .partialUpdateInstanceOperationCallable ())
254
+ .thenReturn (mockUpdateInstanceCallable );
255
+
270
256
com .google .bigtable .admin .v2 .PartialUpdateInstanceRequest expectedRequest =
271
257
com .google .bigtable .admin .v2 .PartialUpdateInstanceRequest .newBuilder ()
272
258
.setUpdateMask (FieldMask .newBuilder ().addPaths ("display_name" ))
@@ -293,6 +279,8 @@ public void testUpdateInstance() {
293
279
@ Test
294
280
public void testGetInstance () {
295
281
// Setup
282
+ Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
283
+
296
284
com .google .bigtable .admin .v2 .GetInstanceRequest expectedRequest =
297
285
com .google .bigtable .admin .v2 .GetInstanceRequest .newBuilder ().setName (INSTANCE_NAME ).build ();
298
286
@@ -312,6 +300,8 @@ public void testGetInstance() {
312
300
@ Test
313
301
public void testListInstances () {
314
302
// Setup
303
+ Mockito .when (mockStub .listInstancesCallable ()).thenReturn (mockListInstancesCallable );
304
+
315
305
com .google .bigtable .admin .v2 .ListInstancesRequest expectedRequest =
316
306
com .google .bigtable .admin .v2 .ListInstancesRequest .newBuilder ()
317
307
.setParent (PROJECT_NAME )
@@ -345,6 +335,8 @@ public void testListInstances() {
345
335
@ Test
346
336
public void testListInstancesFailedZone () {
347
337
// Setup
338
+ Mockito .when (mockStub .listInstancesCallable ()).thenReturn (mockListInstancesCallable );
339
+
348
340
com .google .bigtable .admin .v2 .ListInstancesRequest expectedRequest =
349
341
com .google .bigtable .admin .v2 .ListInstancesRequest .newBuilder ()
350
342
.setParent (PROJECT_NAME )
@@ -384,6 +376,8 @@ public void testListInstancesFailedZone() {
384
376
@ Test
385
377
public void testDeleteInstance () {
386
378
// Setup
379
+ Mockito .when (mockStub .deleteInstanceCallable ()).thenReturn (mockDeleteInstanceCallable );
380
+
387
381
com .google .bigtable .admin .v2 .DeleteInstanceRequest expectedRequest =
388
382
com .google .bigtable .admin .v2 .DeleteInstanceRequest .newBuilder ()
389
383
.setName (INSTANCE_NAME )
@@ -411,6 +405,8 @@ public ApiFuture<Empty> answer(InvocationOnMock invocationOnMock) {
411
405
@ Test
412
406
public void testCreateCluster () {
413
407
// Setup
408
+ Mockito .when (mockStub .createClusterOperationCallable ()).thenReturn (mockCreateClusterCallable );
409
+
414
410
com .google .bigtable .admin .v2 .CreateClusterRequest expectedRequest =
415
411
com .google .bigtable .admin .v2 .CreateClusterRequest .newBuilder ()
416
412
.setParent (INSTANCE_NAME )
@@ -439,6 +435,8 @@ public void testCreateCluster() {
439
435
@ Test
440
436
public void testGetCluster () {
441
437
// Setup
438
+ Mockito .when (mockStub .getClusterCallable ()).thenReturn (mockGetClusterCallable );
439
+
442
440
com .google .bigtable .admin .v2 .GetClusterRequest expectedRequest =
443
441
com .google .bigtable .admin .v2 .GetClusterRequest .newBuilder ().setName (CLUSTER_NAME ).build ();
444
442
@@ -458,6 +456,8 @@ public void testGetCluster() {
458
456
@ Test
459
457
public void testListClusters () {
460
458
// Setup
459
+ Mockito .when (mockStub .listClustersCallable ()).thenReturn (mockListClustersCallable );
460
+
461
461
com .google .bigtable .admin .v2 .ListClustersRequest expectedRequest =
462
462
com .google .bigtable .admin .v2 .ListClustersRequest .newBuilder ()
463
463
.setParent (INSTANCE_NAME )
@@ -487,6 +487,8 @@ public void testListClusters() {
487
487
@ Test
488
488
public void testListClustersFailedZone () {
489
489
// Setup
490
+ Mockito .when (mockStub .listClustersCallable ()).thenReturn (mockListClustersCallable );
491
+
490
492
com .google .bigtable .admin .v2 .ListClustersRequest expectedRequest =
491
493
com .google .bigtable .admin .v2 .ListClustersRequest .newBuilder ()
492
494
.setParent (INSTANCE_NAME )
@@ -522,6 +524,8 @@ public void testListClustersFailedZone() {
522
524
@ Test
523
525
public void testResizeCluster () {
524
526
// Setup
527
+ Mockito .when (mockStub .updateClusterOperationCallable ()).thenReturn (mockUpdateClusterCallable );
528
+
525
529
com .google .bigtable .admin .v2 .Cluster expectedRequest =
526
530
com .google .bigtable .admin .v2 .Cluster .newBuilder ()
527
531
.setName (CLUSTER_NAME )
@@ -547,6 +551,8 @@ public void testResizeCluster() {
547
551
@ Test
548
552
public void testDeleteCluster () {
549
553
// Setup
554
+ Mockito .when (mockStub .deleteClusterCallable ()).thenReturn (mockDeleteClusterCallable );
555
+
550
556
com .google .bigtable .admin .v2 .DeleteClusterRequest expectedRequest =
551
557
com .google .bigtable .admin .v2 .DeleteClusterRequest .newBuilder ()
552
558
.setName (CLUSTER_NAME )
@@ -574,6 +580,8 @@ public ApiFuture<Empty> answer(InvocationOnMock invocationOnMock) {
574
580
@ Test
575
581
public void testCreateAppProfile () {
576
582
// Setup
583
+ Mockito .when (mockStub .createAppProfileCallable ()).thenReturn (mockCreateAppProfileCallable );
584
+
577
585
com .google .bigtable .admin .v2 .CreateAppProfileRequest expectedRequest =
578
586
com .google .bigtable .admin .v2 .CreateAppProfileRequest .newBuilder ()
579
587
.setParent (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -612,6 +620,8 @@ public void testCreateAppProfile() {
612
620
@ Test
613
621
public void testGetAppProfile () {
614
622
// Setup
623
+ Mockito .when (mockStub .getAppProfileCallable ()).thenReturn (mockGetAppProfileCallable );
624
+
615
625
com .google .bigtable .admin .v2 .GetAppProfileRequest expectedRequest =
616
626
com .google .bigtable .admin .v2 .GetAppProfileRequest .newBuilder ()
617
627
.setName (APP_PROFILE_NAME )
@@ -639,6 +649,8 @@ public void testGetAppProfile() {
639
649
@ Test
640
650
public void testListAppProfiles () {
641
651
// Setup
652
+ Mockito .when (mockStub .listAppProfilesPagedCallable ()).thenReturn (mockListAppProfilesCallable );
653
+
642
654
com .google .bigtable .admin .v2 .ListAppProfilesRequest expectedRequest =
643
655
com .google .bigtable .admin .v2 .ListAppProfilesRequest .newBuilder ()
644
656
.setParent (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -659,7 +671,6 @@ public void testListAppProfiles() {
659
671
// 2 on the first page
660
672
ListAppProfilesPage page0 = Mockito .mock (ListAppProfilesPage .class );
661
673
Mockito .when (page0 .getValues ()).thenReturn (expectedProtos .subList (0 , 2 ));
662
- Mockito .when (page0 .getNextPageToken ()).thenReturn ("next-page" );
663
674
Mockito .when (page0 .hasNextPage ()).thenReturn (true );
664
675
665
676
// 1 on the last page
@@ -691,6 +702,9 @@ public void testListAppProfiles() {
691
702
@ Test
692
703
public void testUpdateAppProfile () {
693
704
// Setup
705
+ Mockito .when (mockStub .updateAppProfileOperationCallable ())
706
+ .thenReturn (mockUpdateAppProfileCallable );
707
+
694
708
com .google .bigtable .admin .v2 .UpdateAppProfileRequest expectedRequest =
695
709
com .google .bigtable .admin .v2 .UpdateAppProfileRequest .newBuilder ()
696
710
.setAppProfile (
@@ -724,6 +738,8 @@ public void testUpdateAppProfile() {
724
738
@ Test
725
739
public void testDeleteAppProfile () throws Exception {
726
740
// Setup
741
+ Mockito .when (mockStub .deleteAppProfileCallable ()).thenReturn (mockDeleteAppProfileCallable );
742
+
727
743
com .google .bigtable .admin .v2 .DeleteAppProfileRequest expectedRequest =
728
744
com .google .bigtable .admin .v2 .DeleteAppProfileRequest .newBuilder ()
729
745
.setName (APP_PROFILE_NAME )
@@ -790,6 +806,8 @@ private <ReqT, RespT, MetaT> void mockOperationResult(
790
806
@ Test
791
807
public void testGetIamPolicy () {
792
808
// Setup
809
+ Mockito .when (mockStub .getIamPolicyCallable ()).thenReturn (mockGetIamPolicyCallable );
810
+
793
811
com .google .iam .v1 .GetIamPolicyRequest expectedRequest =
794
812
com .google .iam .v1 .GetIamPolicyRequest .newBuilder ()
795
813
.setResource (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -822,6 +840,8 @@ public void testGetIamPolicy() {
822
840
@ Test
823
841
public void testSetIamPolicy () {
824
842
// Setup
843
+ Mockito .when (mockStub .setIamPolicyCallable ()).thenReturn (mockSetIamPolicyCallable );
844
+
825
845
com .google .iam .v1 .SetIamPolicyRequest expectedRequest =
826
846
com .google .iam .v1 .SetIamPolicyRequest .newBuilder ()
827
847
.setResource (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -865,6 +885,8 @@ public void testSetIamPolicy() {
865
885
@ Test
866
886
public void testTestIamPermissions () {
867
887
// Setup
888
+ Mockito .when (mockStub .testIamPermissionsCallable ()).thenReturn (mockTestIamPermissionsCallable );
889
+
868
890
com .google .iam .v1 .TestIamPermissionsRequest expectedRequest =
869
891
com .google .iam .v1 .TestIamPermissionsRequest .newBuilder ()
870
892
.setResource (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
@@ -890,12 +912,14 @@ public void testTestIamPermissions() {
890
912
@ Test
891
913
public void testExistsTrue () {
892
914
// Setup
915
+ Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
916
+
893
917
com .google .bigtable .admin .v2 .Instance expectedResponse =
894
918
com .google .bigtable .admin .v2 .Instance .newBuilder ()
895
919
.setName (NameUtil .formatInstanceName (PROJECT_ID , INSTANCE_ID ))
896
920
.build ();
897
921
898
- Mockito .when (mockGetInstanceCallable .futureCall (Matchers .any (GetInstanceRequest .class )))
922
+ Mockito .when (mockGetInstanceCallable .futureCall (ArgumentMatchers .any (GetInstanceRequest .class )))
899
923
.thenReturn (ApiFutures .immediateFuture (expectedResponse ));
900
924
901
925
// Execute
@@ -908,10 +932,12 @@ public void testExistsTrue() {
908
932
@ Test
909
933
public void testExistsFalse () {
910
934
// Setup
935
+ Mockito .when (mockStub .getInstanceCallable ()).thenReturn (mockGetInstanceCallable );
936
+
911
937
NotFoundException exception =
912
938
new NotFoundException ("fake-error" , null , GrpcStatusCode .of (Status .Code .NOT_FOUND ), false );
913
939
914
- Mockito .when (mockGetInstanceCallable .futureCall (Matchers .any (GetInstanceRequest .class )))
940
+ Mockito .when (mockGetInstanceCallable .futureCall (ArgumentMatchers .any (GetInstanceRequest .class )))
915
941
.thenReturn (
916
942
ApiFutures .<com .google .bigtable .admin .v2 .Instance >immediateFailedFuture (exception ));
917
943
0 commit comments