Skip to content

Commit cd3e524

Browse files
authored
test(bigquery-jdbc): fix JSpecify compatibility issues on Java 8 (#13818)
Update Mockito mocks in BigQuery JDBC tests to ignore annotations, preventing ArrayStoreException when running tests on Java 8. Specifically, mock Page, ApiException, and StatusCode classes with withSettings().withoutAnnotations().
1 parent 61b89b3 commit cd3e524

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryConnectionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.mockito.Mockito.times;
2828
import static org.mockito.Mockito.verify;
2929
import static org.mockito.Mockito.when;
30+
import static org.mockito.Mockito.withSettings;
3031

3132
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
3233
import com.google.api.gax.paging.Page;
@@ -535,7 +536,7 @@ public void testGetDiscoveredProjects_Success() throws Exception {
535536
BigQuery mockBigQuery = mock(BigQuery.class);
536537
connection.bigQuery = mockBigQuery;
537538

538-
Page<Project> mockPage = mock(Page.class);
539+
Page<Project> mockPage = mock(Page.class, withSettings().withoutAnnotations());
539540
Project project1 = mock(Project.class);
540541
when(project1.getProjectId()).thenReturn("discovered-p1");
541542
Project project2 = mock(Project.class);

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ public void testFindMatchingBigQueryObjects_Routines_ListWithPattern() throws Ex
10091009
Routine func1 = mockBigQueryRoutine(catalog, schema, "func_123", "FUNCTION", "f1");
10101010
Routine otherProc = mockBigQueryRoutine(catalog, schema, "another_proc", "PROCEDURE", "p3");
10111011

1012-
Page<Routine> page = mock(Page.class);
1012+
Page<Routine> page = mock(Page.class, withSettings().withoutAnnotations());
10131013
when(page.iterateAll()).thenReturn(Arrays.asList(proc1, func1, proc2, otherProc));
10141014
when(bigqueryClient.listRoutines(eq(datasetId), any(BigQuery.RoutineListOption[].class)))
10151015
.thenReturn(page);
@@ -1053,7 +1053,7 @@ public void testFindMatchingBigQueryObjects_Routines_ListNoPattern() throws Exce
10531053
Routine proc1 = mockBigQueryRoutine(catalog, schema, "proc_abc", "PROCEDURE", "p1");
10541054
Routine func1 = mockBigQueryRoutine(catalog, schema, "func_123", "FUNCTION", "f1");
10551055

1056-
Page<Routine> page = mock(Page.class);
1056+
Page<Routine> page = mock(Page.class, withSettings().withoutAnnotations());
10571057
when(page.iterateAll()).thenReturn(Arrays.asList(proc1, func1));
10581058
when(bigqueryClient.listRoutines(eq(datasetId), any(BigQuery.RoutineListOption[].class)))
10591059
.thenReturn(page);
@@ -1545,12 +1545,12 @@ public void testListMatchingProcedureIdsFromDatasets() throws Exception {
15451545
Routine func1_ds1 = mockBigQueryRoutine(catalog, schema1Name, "func_b", "FUNCTION", "desc b");
15461546
Routine proc2_ds2 = mockBigQueryRoutine(catalog, schema2Name, "proc_c", "PROCEDURE", "desc c");
15471547

1548-
Page<Routine> page1 = mock(Page.class);
1548+
Page<Routine> page1 = mock(Page.class, withSettings().withoutAnnotations());
15491549
when(page1.iterateAll()).thenReturn(Arrays.asList(proc1_ds1, func1_ds1));
15501550
when(bigqueryClient.listRoutines(eq(dataset1.getDatasetId()), any(RoutineListOption.class)))
15511551
.thenReturn(page1);
15521552

1553-
Page<Routine> page2 = mock(Page.class);
1553+
Page<Routine> page2 = mock(Page.class, withSettings().withoutAnnotations());
15541554
when(page2.iterateAll()).thenReturn(Collections.singletonList(proc2_ds2));
15551555
when(bigqueryClient.listRoutines(eq(dataset2.getDatasetId()), any(RoutineListOption.class)))
15561556
.thenReturn(page2);
@@ -3309,20 +3309,20 @@ public void testGetSchemas_WithProjectDiscovery() throws SQLException {
33093309
when(bigQueryConnection.getDiscoveredProjects()).thenReturn(Arrays.asList("discovered-1"));
33103310
when(bigQueryConnection.getAdditionalProjects()).thenReturn("additional-1");
33113311

3312-
Page<Dataset> pagePrimary = mock(Page.class);
3312+
Page<Dataset> pagePrimary = mock(Page.class, withSettings().withoutAnnotations());
33133313
Dataset dsPrimary = mockBigQueryDataset("primary-project", "dataset_p");
33143314
when(pagePrimary.iterateAll()).thenReturn(Collections.singletonList(dsPrimary));
33153315
when(bigqueryClient.listDatasets(
33163316
eq("primary-project"), any(BigQuery.DatasetListOption[].class)))
33173317
.thenReturn(pagePrimary);
33183318

3319-
Page<Dataset> pageAdditional = mock(Page.class);
3319+
Page<Dataset> pageAdditional = mock(Page.class, withSettings().withoutAnnotations());
33203320
Dataset dsAdditional = mockBigQueryDataset("additional-1", "dataset_a");
33213321
when(pageAdditional.iterateAll()).thenReturn(Collections.singletonList(dsAdditional));
33223322
when(bigqueryClient.listDatasets(eq("additional-1"), any(BigQuery.DatasetListOption[].class)))
33233323
.thenReturn(pageAdditional);
33243324

3325-
Page<Dataset> pageDiscovered = mock(Page.class);
3325+
Page<Dataset> pageDiscovered = mock(Page.class, withSettings().withoutAnnotations());
33263326
Dataset dsDiscovered = mockBigQueryDataset("discovered-1", "dataset_d");
33273327
when(pageDiscovered.iterateAll()).thenReturn(Collections.singletonList(dsDiscovered));
33283328
when(bigqueryClient.listDatasets(eq("discovered-1"), any(BigQuery.DatasetListOption[].class)))
@@ -3354,14 +3354,14 @@ public void testGetSchemas_WithoutProjectDiscovery() throws SQLException {
33543354
when(bigQueryConnection.getDiscoveredProjects()).thenReturn(Arrays.asList("discovered-1"));
33553355
when(bigQueryConnection.getAdditionalProjects()).thenReturn("additional-1");
33563356

3357-
Page<Dataset> pagePrimary = mock(Page.class);
3357+
Page<Dataset> pagePrimary = mock(Page.class, withSettings().withoutAnnotations());
33583358
Dataset dsPrimary = mockBigQueryDataset("primary-project", "dataset_p");
33593359
when(pagePrimary.iterateAll()).thenReturn(Collections.singletonList(dsPrimary));
33603360
when(bigqueryClient.listDatasets(
33613361
eq("primary-project"), any(BigQuery.DatasetListOption[].class)))
33623362
.thenReturn(pagePrimary);
33633363

3364-
Page<Dataset> pageAdditional = mock(Page.class);
3364+
Page<Dataset> pageAdditional = mock(Page.class, withSettings().withoutAnnotations());
33653365
Dataset dsAdditional = mockBigQueryDataset("additional-1", "dataset_a");
33663366
when(pageAdditional.iterateAll()).thenReturn(Collections.singletonList(dsAdditional));
33673367
when(bigqueryClient.listDatasets(eq("additional-1"), any(BigQuery.DatasetListOption[].class)))
@@ -3388,7 +3388,7 @@ public void testGetSchemas_WithoutProjectDiscovery() throws SQLException {
33883388
}
33893389

33903390
private void mockDatasetIteration(DatasetId datasetId) {
3391-
Page<Dataset> pagePrimary = mock(Page.class);
3391+
Page<Dataset> pagePrimary = mock(Page.class, withSettings().withoutAnnotations());
33923392
Dataset dsPrimary = mock(Dataset.class);
33933393
when(dsPrimary.getDatasetId()).thenReturn(datasetId);
33943394
when(pagePrimary.iterateAll()).thenReturn(Collections.singletonList(dsPrimary));
@@ -3411,7 +3411,7 @@ private Table mockTableWithConstraints(TableId tableId, TableConstraints constra
34113411
}
34123412

34133413
private void mockTableIteration(DatasetId datasetId, Table... tables) {
3414-
Page<Table> pageTables = mock(Page.class);
3414+
Page<Table> pageTables = mock(Page.class, withSettings().withoutAnnotations());
34153415
when(pageTables.iterateAll()).thenReturn(Arrays.asList(tables));
34163416
when(bigqueryClient.listTables(eq(datasetId), any(BigQuery.TableListOption[].class)))
34173417
.thenReturn(pageTables);

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.mockito.Mockito.doReturn;
2828
import static org.mockito.Mockito.mock;
2929
import static org.mockito.Mockito.verify;
30+
import static org.mockito.Mockito.withSettings;
3031

3132
import com.google.api.gax.rpc.ApiException;
3233
import com.google.api.gax.rpc.StatusCode;
@@ -596,8 +597,8 @@ private TableResult mockTableResultWithJob(String jobId) {
596597
}
597598

598599
private ApiException mockApiException(StatusCode.Code code) {
599-
ApiException apiExceptionMock = mock(ApiException.class);
600-
StatusCode statusCodeMock = mock(StatusCode.class);
600+
ApiException apiExceptionMock = mock(ApiException.class, withSettings().withoutAnnotations());
601+
StatusCode statusCodeMock = mock(StatusCode.class, withSettings().withoutAnnotations());
601602
doReturn(statusCodeMock).when(apiExceptionMock).getStatusCode();
602603
doReturn(code).when(statusCodeMock).getCode();
603604
return apiExceptionMock;

0 commit comments

Comments
 (0)