Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: migrate to mockito-core 3.12.4 #1008

Merged
merged 6 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.mockito.Matchers;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
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";
Expand Down Expand Up @@ -191,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
Expand All @@ -231,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)
Expand Down Expand Up @@ -267,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"))
Expand All @@ -293,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();

Expand All @@ -312,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)
Expand Down Expand Up @@ -345,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)
Expand Down Expand Up @@ -384,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)
Expand Down Expand Up @@ -411,6 +405,8 @@ public ApiFuture<Empty> 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)
Expand Down Expand Up @@ -439,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();

Expand All @@ -458,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)
Expand Down Expand Up @@ -487,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)
Expand Down Expand Up @@ -522,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)
Expand All @@ -547,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)
Expand Down Expand Up @@ -574,6 +580,8 @@ public ApiFuture<Empty> 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))
Expand Down Expand Up @@ -612,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)
Expand Down Expand Up @@ -639,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))
Expand All @@ -659,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
Expand Down Expand Up @@ -691,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(
Expand Down Expand Up @@ -724,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)
Expand Down Expand Up @@ -790,6 +806,8 @@ private <ReqT, RespT, MetaT> 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))
Expand Down Expand Up @@ -822,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))
Expand Down Expand Up @@ -865,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))
Expand All @@ -890,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
Expand All @@ -908,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.<com.google.bigtable.admin.v2.Instance>immediateFailedFuture(exception));

Expand Down
Loading