Skip to content

Commit b1c6fad

Browse files
authored
chore(bq jdbc): migrate to junit5 (#12079)
1 parent e0d9bd2 commit b1c6fad

39 files changed

Lines changed: 773 additions & 650 deletions

java-bigquery/google-cloud-bigquery-jdbc/pom.xml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<version>0.6.0-SNAPSHOT</version><!-- {x-version-update:google-cloud-bigquery-jdbc:current} -->
2424
<packaging>jar</packaging>
2525
<name>BigQuery JDBC</name>
26-
<url>https://github.com/googleapis/google-cloud-java-jdbc</url>
26+
<url>https://github.com/googleapis/google-cloud-java</url>
2727
<description>JDBC for BigQuery</description>
2828

2929
<properties>
@@ -179,6 +179,7 @@
179179
</exclusions>
180180
</dependency>
181181

182+
<!-- Transitive Dependencies -->
182183
<dependency>
183184
<groupId>com.google.api</groupId>
184185
<artifactId>api-common</artifactId>
@@ -268,22 +269,35 @@
268269
<artifactId>httpcore5</artifactId>
269270
</dependency>
270271

272+
<!-- Test Dependencies -->
271273
<dependency>
272274
<groupId>com.google.truth</groupId>
273275
<artifactId>truth</artifactId>
274-
<version>1.1.3</version>
275276
<scope>test</scope>
276277
</dependency>
277278
<dependency>
278-
<groupId>junit</groupId>
279-
<artifactId>junit</artifactId>
280-
<version>4.13.2</version>
279+
<groupId>org.junit.jupiter</groupId>
280+
<artifactId>junit-jupiter-api</artifactId>
281+
<scope>test</scope>
282+
</dependency>
283+
<dependency>
284+
<groupId>org.junit.jupiter</groupId>
285+
<artifactId>junit-jupiter-engine</artifactId>
286+
<scope>test</scope>
287+
</dependency>
288+
<dependency>
289+
<groupId>org.junit.jupiter</groupId>
290+
<artifactId>junit-jupiter-params</artifactId>
281291
<scope>test</scope>
282292
</dependency>
283293
<dependency>
284294
<groupId>org.mockito</groupId>
285295
<artifactId>mockito-core</artifactId>
286-
<version>4.11.0</version>
296+
<scope>test</scope>
297+
</dependency>
298+
<dependency>
299+
<groupId>org.mockito</groupId>
300+
<artifactId>mockito-junit-jupiter</artifactId>
287301
<scope>test</scope>
288302
</dependency>
289303
</dependencies>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
import org.apache.arrow.vector.util.JsonStringArrayList;
3737
import org.apache.arrow.vector.util.JsonStringHashMap;
3838
import org.apache.arrow.vector.util.Text;
39-
import org.junit.Rule;
40-
import org.junit.Test;
39+
import org.junit.jupiter.api.Test;
40+
import org.junit.jupiter.api.extension.RegisterExtension;
4141

4242
public class ArrowFormatTypeBigQueryCoercionUtilityTest {
4343

44-
@Rule public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC");
44+
@RegisterExtension public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC");
4545

4646
private static final Range RANGE_DATE =
4747
Range.newBuilder()

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

Lines changed: 110 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import static java.time.Month.MARCH;
3939
import static java.util.Arrays.copyOfRange;
4040
import static java.util.Collections.emptyMap;
41-
import static org.junit.Assert.assertThrows;
41+
import static org.junit.jupiter.api.Assertions.assertThrows;
4242

4343
import com.google.cloud.Tuple;
4444
import com.google.cloud.bigquery.Field;
@@ -62,44 +62,15 @@
6262
import java.util.stream.Stream;
6363
import org.apache.arrow.vector.util.JsonStringArrayList;
6464
import org.apache.arrow.vector.util.Text;
65-
import org.junit.Before;
66-
import org.junit.ClassRule;
67-
import org.junit.Test;
68-
import org.junit.function.ThrowingRunnable;
69-
import org.junit.runner.RunWith;
70-
import org.junit.runners.Parameterized;
71-
import org.junit.runners.Parameterized.Parameters;
65+
import org.junit.jupiter.api.extension.RegisterExtension;
66+
import org.junit.jupiter.api.function.Executable;
67+
import org.junit.jupiter.params.ParameterizedTest;
68+
import org.junit.jupiter.params.provider.MethodSource;
7269

73-
@RunWith(Parameterized.class)
7470
public class BigQueryArrowArrayOfPrimitivesTest {
7571

76-
private final Field schema;
77-
private final JsonStringArrayList<?> arrayValues;
78-
private final Object[] expected;
79-
private final int javaSqlTypeCode;
80-
private Array array;
81-
private final StandardSQLTypeName currentType;
72+
@RegisterExtension public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC");
8273

83-
@ClassRule public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC");
84-
85-
public BigQueryArrowArrayOfPrimitivesTest(
86-
StandardSQLTypeName currentType,
87-
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
88-
Object[] expected,
89-
int javaSqlTypeCode) {
90-
this.currentType = currentType;
91-
this.schema = schemaAndValue.x();
92-
this.arrayValues = schemaAndValue.y();
93-
this.expected = expected;
94-
this.javaSqlTypeCode = javaSqlTypeCode;
95-
}
96-
97-
@Before
98-
public void setUp() {
99-
array = new BigQueryArrowArray(this.schema, this.arrayValues);
100-
}
101-
102-
@Parameters(name = "{index}: primitive array of {0}")
10374
public static Collection<Object[]> data() {
10475
timeZoneRule.enforce();
10576
LocalDateTime aTimeStamp = LocalDateTime.of(2023, MARCH, 30, 11, 14, 19, 820227000);
@@ -254,48 +225,82 @@ STRING, new Text("one"), new Text("two"), new Text("three"), new Text("four")),
254225
});
255226
}
256227

257-
@Test
258-
public void getArray() throws SQLException {
259-
assertThat(array.getArray()).isEqualTo(this.expected);
228+
@ParameterizedTest(name = "{index}: primitive array of {0}")
229+
@MethodSource("data")
230+
public void getArray(
231+
StandardSQLTypeName currentType,
232+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
233+
Object[] expected,
234+
int javaSqlTypeCode)
235+
throws SQLException {
236+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
237+
assertThat(array.getArray()).isEqualTo(expected);
260238
}
261239

262-
@Test
263-
public void getSlicedArray() throws SQLException {
240+
@ParameterizedTest(name = "{index}: primitive array of {0}")
241+
@MethodSource("data")
242+
public void getSlicedArray(
243+
StandardSQLTypeName currentType,
244+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
245+
Object[] expected,
246+
int javaSqlTypeCode)
247+
throws SQLException {
248+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
264249
int fromIndex = 1;
265250
int toIndexExclusive = 3;
266251
Object[] expectedSlicedArray =
267-
copyOfRange(this.expected, fromIndex, toIndexExclusive); // copying index(1,2)
252+
copyOfRange(expected, fromIndex, toIndexExclusive); // copying index(1,2)
268253

269254
// the first element is at index 1
270255
assertThat(array.getArray(fromIndex + 1, 2)).isEqualTo(expectedSlicedArray);
271256
}
272257

273-
@Test
274-
public void getSlicedArrayWhenCountIsGreaterThanOriginalArrayLength() {
258+
@ParameterizedTest(name = "{index}: primitive array of {0}")
259+
@MethodSource("data")
260+
public void getSlicedArrayWhenCountIsGreaterThanOriginalArrayLength(
261+
StandardSQLTypeName currentType,
262+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
263+
Object[] expected,
264+
int javaSqlTypeCode) {
265+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
275266
IllegalArgumentException illegalArgumentException =
276267
assertThrows(IllegalArgumentException.class, () -> array.getArray(2, 10));
277268
assertThat(illegalArgumentException.getMessage())
278269
.isEqualTo("The array index is out of range: 12, number of elements: 4.");
279270
}
280271

281-
@Test
282-
public void getResultSet() throws SQLException {
283-
ResultSet resultSet = this.array.getResultSet();
272+
@ParameterizedTest(name = "{index}: primitive array of {0}")
273+
@MethodSource("data")
274+
public void getResultSet(
275+
StandardSQLTypeName currentType,
276+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
277+
Object[] expected,
278+
int javaSqlTypeCode)
279+
throws SQLException {
280+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
281+
ResultSet resultSet = array.getResultSet();
284282
Tuple<ArrayList<Object>, ArrayList<Object>> indexAndValues =
285283
nestedResultSetToColumnLists(resultSet);
286284
ArrayList<Object> indexList = indexAndValues.x();
287285
ArrayList<Object> columnValues = indexAndValues.y();
288286

289287
assertThat(indexList.toArray()).isEqualTo(new Object[] {1, 2, 3, 4});
290-
assertThat(columnValues.toArray()).isEqualTo(this.expected);
288+
assertThat(columnValues.toArray()).isEqualTo(expected);
291289
}
292290

293-
@Test
294-
public void getSlicedResultSet() throws SQLException {
291+
@ParameterizedTest(name = "{index}: primitive array of {0}")
292+
@MethodSource("data")
293+
public void getSlicedResultSet(
294+
StandardSQLTypeName currentType,
295+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
296+
Object[] expected,
297+
int javaSqlTypeCode)
298+
throws SQLException {
299+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
295300
int fromIndex = 1;
296301
int toIndexExclusive = 3;
297302
Object[] expectedSlicedArray =
298-
copyOfRange(this.expected, fromIndex, toIndexExclusive); // copying index(1,2)
303+
copyOfRange(expected, fromIndex, toIndexExclusive); // copying index(1,2)
299304

300305
// the first element is at index 1
301306
ResultSet resultSet = array.getResultSet(fromIndex + 1, 2);
@@ -309,27 +314,54 @@ public void getSlicedResultSet() throws SQLException {
309314
assertThat(columnValues.toArray()).isEqualTo(expectedSlicedArray);
310315
}
311316

312-
@Test
313-
public void getSlicedResultSetWhenCountIsGreaterThanOriginalArrayLength() {
317+
@ParameterizedTest(name = "{index}: primitive array of {0}")
318+
@MethodSource("data")
319+
public void getSlicedResultSetWhenCountIsGreaterThanOriginalArrayLength(
320+
StandardSQLTypeName currentType,
321+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
322+
Object[] expected,
323+
int javaSqlTypeCode) {
324+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
314325
IllegalArgumentException illegalArgumentException =
315326
assertThrows(IllegalArgumentException.class, () -> array.getResultSet(2, 10));
316327
assertThat(illegalArgumentException.getMessage())
317328
.isEqualTo("The array index is out of range: 12, number of elements: 4.");
318329
}
319330

320-
@Test
321-
public void getBaseTypeName() throws SQLException {
322-
assertThat(array.getBaseTypeName()).isEqualTo(this.currentType.name());
331+
@ParameterizedTest(name = "{index}: primitive array of {0}")
332+
@MethodSource("data")
333+
public void getBaseTypeName(
334+
StandardSQLTypeName currentType,
335+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
336+
Object[] expected,
337+
int javaSqlTypeCode)
338+
throws SQLException {
339+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
340+
assertThat(array.getBaseTypeName()).isEqualTo(currentType.name());
323341
}
324342

325-
@Test
326-
public void getBaseType() throws SQLException {
327-
assertThat(array.getBaseType()).isEqualTo(this.javaSqlTypeCode);
343+
@ParameterizedTest(name = "{index}: primitive array of {0}")
344+
@MethodSource("data")
345+
public void getBaseType(
346+
StandardSQLTypeName currentType,
347+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
348+
Object[] expected,
349+
int javaSqlTypeCode)
350+
throws SQLException {
351+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
352+
assertThat(array.getBaseType()).isEqualTo(javaSqlTypeCode);
328353
}
329354

330-
@Test
331-
public void free() throws SQLException {
332-
this.array.free();
355+
@ParameterizedTest(name = "{index}: primitive array of {0}")
356+
@MethodSource("data")
357+
public void free(
358+
StandardSQLTypeName currentType,
359+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
360+
Object[] expected,
361+
int javaSqlTypeCode)
362+
throws SQLException {
363+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
364+
array.free();
333365

334366
ensureArrayIsInvalid(() -> array.getArray());
335367
ensureArrayIsInvalid(() -> array.getArray(1, 2));
@@ -339,8 +371,14 @@ public void free() throws SQLException {
339371
ensureArrayIsInvalid(() -> array.getBaseType());
340372
}
341373

342-
@Test
343-
public void getArrayWithCustomTypeMappingsIsNotSupported() {
374+
@ParameterizedTest(name = "{index}: primitive array of {0}")
375+
@MethodSource("data")
376+
public void getArrayWithCustomTypeMappingsIsNotSupported(
377+
StandardSQLTypeName currentType,
378+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
379+
Object[] expected,
380+
int javaSqlTypeCode) {
381+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
344382
Exception exception1 =
345383
assertThrows(SQLFeatureNotSupportedException.class, () -> array.getArray(emptyMap()));
346384
Exception exception2 =
@@ -349,8 +387,14 @@ public void getArrayWithCustomTypeMappingsIsNotSupported() {
349387
assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
350388
}
351389

352-
@Test
353-
public void getResultSetWithCustomTypeMappingsIsNotSupported() {
390+
@ParameterizedTest(name = "{index}: primitive array of {0}")
391+
@MethodSource("data")
392+
public void getResultSetWithCustomTypeMappingsIsNotSupported(
393+
StandardSQLTypeName currentType,
394+
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
395+
Object[] expected,
396+
int javaSqlTypeCode) {
397+
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
354398
Exception exception1 =
355399
assertThrows(SQLFeatureNotSupportedException.class, () -> array.getResultSet(emptyMap()));
356400
Exception exception2 =
@@ -360,7 +404,7 @@ public void getResultSetWithCustomTypeMappingsIsNotSupported() {
360404
assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
361405
}
362406

363-
private void ensureArrayIsInvalid(ThrowingRunnable block) {
407+
private void ensureArrayIsInvalid(Executable block) {
364408
Exception exception = assertThrows(IllegalStateException.class, block);
365409
assertThat(exception.getMessage()).isEqualTo(INVALID_ARRAY);
366410
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static java.lang.Boolean.TRUE;
3131
import static java.util.Arrays.asList;
3232
import static java.util.Collections.emptyMap;
33-
import static org.junit.Assert.assertThrows;
33+
import static org.junit.jupiter.api.Assertions.assertThrows;
3434

3535
import com.google.cloud.Tuple;
3636
import com.google.cloud.bigquery.Field;
@@ -48,15 +48,15 @@
4848
import org.apache.arrow.vector.util.JsonStringArrayList;
4949
import org.apache.arrow.vector.util.JsonStringHashMap;
5050
import org.apache.arrow.vector.util.Text;
51-
import org.junit.Before;
52-
import org.junit.Test;
53-
import org.junit.function.ThrowingRunnable;
51+
import org.junit.jupiter.api.BeforeEach;
52+
import org.junit.jupiter.api.Test;
53+
import org.junit.jupiter.api.function.Executable;
5454

5555
public class BigQueryArrowArrayOfStructTest {
5656

5757
private Array array;
5858

59-
@Before
59+
@BeforeEach
6060
public void setUp() {
6161
FieldList profileSchema =
6262
FieldList.of(
@@ -198,7 +198,7 @@ public void getResultSetWithCustomTypeMappingsIsNotSupported() {
198198
assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
199199
}
200200

201-
private void ensureArrayIsInvalid(ThrowingRunnable block) {
201+
private void ensureArrayIsInvalid(Executable block) {
202202
Exception exception = assertThrows(IllegalStateException.class, block);
203203
assertThat(exception.getMessage()).isEqualTo(INVALID_ARRAY);
204204
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
import org.apache.arrow.vector.types.pojo.FieldType;
5858
import org.apache.arrow.vector.util.JsonStringArrayList;
5959
import org.apache.arrow.vector.util.Text;
60-
import org.junit.Before;
61-
import org.junit.Test;
60+
import org.junit.jupiter.api.BeforeEach;
61+
import org.junit.jupiter.api.Test;
6262

6363
public class BigQueryArrowResultSetTest {
6464

@@ -194,7 +194,7 @@ private JsonStringArrayList<Long> getJsonStringArrayList() {
194194
return jsonStringArrayList;
195195
}
196196

197-
@Before
197+
@BeforeEach
198198
public void setUp() throws SQLException, IOException {
199199
buffer = new LinkedBlockingDeque<>();
200200
bufferWithTwoRows = new LinkedBlockingDeque<>();

0 commit comments

Comments
 (0)