diff --git a/google-cloud-bigquery-jdbc/pom.xml b/google-cloud-bigquery-jdbc/pom.xml index 2f225b6d87..a3e5183339 100644 --- a/google-cloud-bigquery-jdbc/pom.xml +++ b/google-cloud-bigquery-jdbc/pom.xml @@ -276,9 +276,21 @@ test - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-api + 5.11.4 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.11.4 + test + + + org.junit.jupiter + junit-jupiter-params + 5.11.4 test @@ -287,6 +299,12 @@ 4.11.0 test + + org.mockito + mockito-junit-jupiter + 4.11.0 + test + diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/ArrowFormatTypeBigQueryCoercionUtilityTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/ArrowFormatTypeBigQueryCoercionUtilityTest.java index 0524fc87d1..4011f23b93 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/ArrowFormatTypeBigQueryCoercionUtilityTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/ArrowFormatTypeBigQueryCoercionUtilityTest.java @@ -36,12 +36,12 @@ import org.apache.arrow.vector.util.JsonStringArrayList; import org.apache.arrow.vector.util.JsonStringHashMap; import org.apache.arrow.vector.util.Text; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.Test; public class ArrowFormatTypeBigQueryCoercionUtilityTest { - @Rule public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); + @RegisterExtension public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); private static final Range RANGE_DATE = Range.newBuilder() diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfPrimitivesTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfPrimitivesTest.java index 5b33fda788..e933ddfc66 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfPrimitivesTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfPrimitivesTest.java @@ -38,7 +38,7 @@ import static java.time.Month.MARCH; import static java.util.Arrays.copyOfRange; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.Tuple; import com.google.cloud.bigquery.Field; @@ -62,44 +62,20 @@ import java.util.stream.Stream; import org.apache.arrow.vector.util.JsonStringArrayList; import org.apache.arrow.vector.util.Text; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.api.function.Executable; -@RunWith(Parameterized.class) -public class BigQueryArrowArrayOfPrimitivesTest { - private final Field schema; - private final JsonStringArrayList arrayValues; - private final Object[] expected; - private final int javaSqlTypeCode; - private Array array; - private final StandardSQLTypeName currentType; +public class BigQueryArrowArrayOfPrimitivesTest { - @ClassRule public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); + @RegisterExtension + public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); - public BigQueryArrowArrayOfPrimitivesTest( - StandardSQLTypeName currentType, - Tuple> schemaAndValue, - Object[] expected, - int javaSqlTypeCode) { - this.currentType = currentType; - this.schema = schemaAndValue.x(); - this.arrayValues = schemaAndValue.y(); - this.expected = expected; - this.javaSqlTypeCode = javaSqlTypeCode; - } - - @Before - public void setUp() { - array = new BigQueryArrowArray(this.schema, this.arrayValues); - } - @Parameters(name = "{index}: primitive array of {0}") + public static Collection data() { timeZoneRule.enforce(); LocalDateTime aTimeStamp = LocalDateTime.of(2023, MARCH, 30, 11, 14, 19, 820227000); @@ -254,48 +230,58 @@ STRING, new Text("one"), new Text("two"), new Text("three"), new Text("four")), }); } - @Test - public void getArray() throws SQLException { - assertThat(array.getArray()).isEqualTo(this.expected); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getArray(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); + assertThat(array.getArray()).isEqualTo(expected); } - @Test - public void getSlicedArray() throws SQLException { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedArray(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); int fromIndex = 1; int toIndexExclusive = 3; Object[] expectedSlicedArray = - copyOfRange(this.expected, fromIndex, toIndexExclusive); // copying index(1,2) + copyOfRange(expected, fromIndex, toIndexExclusive); // copying index(1,2) // the first element is at index 1 assertThat(array.getArray(fromIndex + 1, 2)).isEqualTo(expectedSlicedArray); } - @Test - public void getSlicedArrayWhenCountIsGreaterThanOriginalArrayLength() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedArrayWhenCountIsGreaterThanOriginalArrayLength(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class, () -> array.getArray(2, 10)); assertThat(illegalArgumentException.getMessage()) .isEqualTo("The array index is out of range: 12, number of elements: 4."); } - @Test - public void getResultSet() throws SQLException { - ResultSet resultSet = this.array.getResultSet(); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getResultSet(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); + ResultSet resultSet = array.getResultSet(); Tuple, ArrayList> indexAndValues = nestedResultSetToColumnLists(resultSet); ArrayList indexList = indexAndValues.x(); ArrayList columnValues = indexAndValues.y(); assertThat(indexList.toArray()).isEqualTo(new Object[] {1, 2, 3, 4}); - assertThat(columnValues.toArray()).isEqualTo(this.expected); + assertThat(columnValues.toArray()).isEqualTo(expected); } - @Test - public void getSlicedResultSet() throws SQLException { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedResultSet(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); int fromIndex = 1; int toIndexExclusive = 3; Object[] expectedSlicedArray = - copyOfRange(this.expected, fromIndex, toIndexExclusive); // copying index(1,2) + copyOfRange(expected, fromIndex, toIndexExclusive); // copying index(1,2) // the first element is at index 1 ResultSet resultSet = array.getResultSet(fromIndex + 1, 2); @@ -309,27 +295,35 @@ public void getSlicedResultSet() throws SQLException { assertThat(columnValues.toArray()).isEqualTo(expectedSlicedArray); } - @Test - public void getSlicedResultSetWhenCountIsGreaterThanOriginalArrayLength() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedResultSetWhenCountIsGreaterThanOriginalArrayLength(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class, () -> array.getResultSet(2, 10)); assertThat(illegalArgumentException.getMessage()) .isEqualTo("The array index is out of range: 12, number of elements: 4."); } - @Test - public void getBaseTypeName() throws SQLException { - assertThat(array.getBaseTypeName()).isEqualTo(this.currentType.name()); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getBaseTypeName(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); + assertThat(array.getBaseTypeName()).isEqualTo(currentType.name()); } - @Test - public void getBaseType() throws SQLException { - assertThat(array.getBaseType()).isEqualTo(this.javaSqlTypeCode); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getBaseType(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); + assertThat(array.getBaseType()).isEqualTo(javaSqlTypeCode); } - @Test - public void free() throws SQLException { - this.array.free(); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void free(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); + array.free(); ensureArrayIsInvalid(() -> array.getArray()); ensureArrayIsInvalid(() -> array.getArray(1, 2)); @@ -339,8 +333,10 @@ public void free() throws SQLException { ensureArrayIsInvalid(() -> array.getBaseType()); } - @Test - public void getArrayWithCustomTypeMappingsIsNotSupported() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getArrayWithCustomTypeMappingsIsNotSupported(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); Exception exception1 = assertThrows(SQLFeatureNotSupportedException.class, () -> array.getArray(emptyMap())); Exception exception2 = @@ -349,8 +345,10 @@ public void getArrayWithCustomTypeMappingsIsNotSupported() { assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED); } - @Test - public void getResultSetWithCustomTypeMappingsIsNotSupported() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getResultSetWithCustomTypeMappingsIsNotSupported(StandardSQLTypeName currentType, Tuple> schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y()); Exception exception1 = assertThrows(SQLFeatureNotSupportedException.class, () -> array.getResultSet(emptyMap())); Exception exception2 = @@ -360,7 +358,7 @@ public void getResultSetWithCustomTypeMappingsIsNotSupported() { assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED); } - private void ensureArrayIsInvalid(ThrowingRunnable block) { + private void ensureArrayIsInvalid(Executable block) { Exception exception = assertThrows(IllegalStateException.class, block); assertThat(exception.getMessage()).isEqualTo(INVALID_ARRAY); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfStructTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfStructTest.java index 7cb84e70ab..1242721b26 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfStructTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfStructTest.java @@ -30,7 +30,7 @@ import static java.lang.Boolean.TRUE; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.Tuple; import com.google.cloud.bigquery.Field; @@ -48,15 +48,15 @@ import org.apache.arrow.vector.util.JsonStringArrayList; import org.apache.arrow.vector.util.JsonStringHashMap; import org.apache.arrow.vector.util.Text; -import org.junit.Before; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; public class BigQueryArrowArrayOfStructTest { private Array array; - @Before + @BeforeEach public void setUp() { FieldList profileSchema = FieldList.of( @@ -198,7 +198,7 @@ public void getResultSetWithCustomTypeMappingsIsNotSupported() { assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED); } - private void ensureArrayIsInvalid(ThrowingRunnable block) { + private void ensureArrayIsInvalid(Executable block) { Exception exception = assertThrows(IllegalStateException.class, block); assertThat(exception.getMessage()).isEqualTo(INVALID_ARRAY); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSetTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSetTest.java index efde49309d..442ebff3cd 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSetTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSetTest.java @@ -57,8 +57,8 @@ import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.util.JsonStringArrayList; import org.apache.arrow.vector.util.Text; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryArrowResultSetTest { @@ -194,7 +194,7 @@ private JsonStringArrayList getJsonStringArrayList() { return jsonStringArrayList; } - @Before + @BeforeEach public void setUp() throws SQLException, IOException { buffer = new LinkedBlockingDeque<>(); bufferWithTwoRows = new LinkedBlockingDeque<>(); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowStructTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowStructTest.java index 2c3bedcc4c..a69adf50d6 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowStructTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowStructTest.java @@ -38,7 +38,7 @@ import static java.time.Month.MARCH; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.Tuple; import com.google.cloud.bigquery.Field; @@ -63,17 +63,17 @@ import org.apache.arrow.vector.util.JsonStringArrayList; import org.apache.arrow.vector.util.JsonStringHashMap; import org.apache.arrow.vector.util.Text; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.Test; public class BigQueryArrowStructTest { - @Rule public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); + @RegisterExtension public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); private Struct structWithPrimitiveValues; - @Before + @BeforeEach public void setUp() { Tuple> schemaAndValues = arrowStructOf( diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSetTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSetTest.java index 90dad9935a..31610628d0 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSetTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSetTest.java @@ -17,7 +17,7 @@ package com.google.cloud.bigquery.jdbc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.doReturn; @@ -28,8 +28,8 @@ import com.google.cloud.bigquery.JobId; import com.google.cloud.bigquery.JobStatistics.QueryStatistics; import java.lang.reflect.Field; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryBaseResultSetTest { private BigQuery bigQuery; @@ -37,7 +37,7 @@ public class BigQueryBaseResultSetTest { private Job job; private QueryStatistics statistics; - @Before + @BeforeEach public void setUp() { // Using mock() for QueryStatistics because Builder() seems to not be available // from outside. diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBigQueryTypeCoercerBuilderTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBigQueryTypeCoercerBuilderTest.java index 4af1632456..fe4b694fac 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBigQueryTypeCoercerBuilderTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryBigQueryTypeCoercerBuilderTest.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import com.google.cloud.bigquery.jdbc.TestType.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BigQueryBigQueryTypeCoercerBuilderTest { diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatementTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatementTest.java index f9729bf21e..a1d7c05365 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatementTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatementTest.java @@ -15,11 +15,11 @@ */ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -33,8 +33,8 @@ import java.util.Calendar; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryCallableStatementTest { @@ -42,7 +42,7 @@ public class BigQueryCallableStatementTest { private static final String GET_PARAM_KEY = "ParamKey"; private static final String PARAM_KEY = GET_PARAM_KEY; - @Before + @BeforeEach public void setUp() throws IOException, SQLException { bigQueryConnection = mock(BigQueryConnection.class); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryConnectionTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryConnectionTest.java index 0927271add..d3c69c1b74 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryConnectionTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryConnectionTest.java @@ -16,7 +16,7 @@ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.rpc.HeaderProvider; @@ -30,8 +30,8 @@ import java.io.InputStream; import java.sql.SQLException; import java.util.Properties; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryConnectionTest { @@ -42,7 +42,7 @@ public class BigQueryConnectionTest { + "OAuthType=2;OAuthAccessToken=redacted;ProjectId=project;"; private String expectedVersion; - @Before + @BeforeEach public void setUp() throws IOException { // Read the expected version from the dependencies.properties file once. expectedVersion = getExpectedVersion(); @@ -275,9 +275,7 @@ public void testFilterTablesOnDefaultDatasetProperty() throws SQLException, IOEx + "OAuthAccessToken=redactedToken;OAuthClientId=redactedToken;" + "OAuthClientSecret=redactedToken;"; try (BigQueryConnection connectionDefault = new BigQueryConnection(urlDefault)) { - assertFalse( - "Default value for FilterTablesOnDefaultDataset should be false", - connectionDefault.isFilterTablesOnDefaultDataset()); + assertFalse(connectionDefault.isFilterTablesOnDefaultDataset(), "Default value for FilterTablesOnDefaultDataset should be false"); } catch (SQLException | IOException e) { throw new BigQueryJdbcException(e); } @@ -290,9 +288,7 @@ public void testFilterTablesOnDefaultDatasetProperty() throws SQLException, IOEx + "OAuthClientSecret=redactedToken;" + "FilterTablesOnDefaultDataset=1;"; try (BigQueryConnection connectionTrue = new BigQueryConnection(urlTrue)) { - assertTrue( - "FilterTablesOnDefaultDataset should be true when set to 1", - connectionTrue.isFilterTablesOnDefaultDataset()); + assertTrue(connectionTrue.isFilterTablesOnDefaultDataset(), "FilterTablesOnDefaultDataset should be true when set to 1"); } catch (SQLException | IOException e) { throw new BigQueryJdbcException(e); } @@ -308,10 +304,7 @@ public void testRequestGoogleDriveScopeProperty() throws IOException, SQLExcepti + "OAuthClientSecret=redactedToken;" + "RequestGoogleDriveScope=1;"; try (BigQueryConnection connectionEnabled = new BigQueryConnection(urlEnabled)) { - assertEquals( - "RequestGoogleDriveScope should be enabled when set to 1", - 1, - connectionEnabled.isRequestGoogleDriveScope()); + assertEquals(1, connectionEnabled.isRequestGoogleDriveScope(), "RequestGoogleDriveScope should be enabled when set to 1"); } catch (SQLException | IOException e) { throw new BigQueryJdbcException(e); } @@ -324,10 +317,7 @@ public void testRequestGoogleDriveScopeProperty() throws IOException, SQLExcepti + "OAuthClientSecret=redactedToken;" + "RequestGoogleDriveScope=0;"; try (BigQueryConnection connectionDisabled = new BigQueryConnection(urlDisabled)) { - assertEquals( - "RequestGoogleDriveScope should be disabled when set to 0", - 0, - connectionDisabled.isRequestGoogleDriveScope()); + assertEquals(0, connectionDisabled.isRequestGoogleDriveScope(), "RequestGoogleDriveScope should be disabled when set to 0"); } catch (SQLException | IOException e) { throw new BigQueryJdbcException(e); } @@ -342,10 +332,7 @@ public void testMetaDataFetchThreadCountProperty() throws SQLException, IOExcept + "OAuthAccessToken=redactedToken;OAuthClientId=redactedToken;" + "OAuthClientSecret=redactedToken;"; try (BigQueryConnection connectionDefault = new BigQueryConnection(urlDefault)) { - assertEquals( - "Should use the default value when the property is not set", - BigQueryJdbcUrlUtility.DEFAULT_METADATA_FETCH_THREAD_COUNT_VALUE, - connectionDefault.getMetadataFetchThreadCount()); + assertEquals(BigQueryJdbcUrlUtility.DEFAULT_METADATA_FETCH_THREAD_COUNT_VALUE, connectionDefault.getMetadataFetchThreadCount(), "Should use the default value when the property is not set"); } // Test Case 2: Should use the custom value when a valid integer is provided. @@ -356,10 +343,7 @@ public void testMetaDataFetchThreadCountProperty() throws SQLException, IOExcept + "OAuthClientSecret=redactedToken;" + "MetaDataFetchThreadCount=16;"; try (BigQueryConnection connectionCustom = new BigQueryConnection(urlCustom)) { - assertEquals( - "Should use the custom value when a valid integer is provided", - 16, - connectionCustom.getMetadataFetchThreadCount()); + assertEquals(16, connectionCustom.getMetadataFetchThreadCount(), "Should use the custom value when a valid integer is provided"); } } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDaemonPollingTaskTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDaemonPollingTaskTest.java index b99ff4bec5..29941152e7 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDaemonPollingTaskTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDaemonPollingTaskTest.java @@ -22,8 +22,8 @@ import java.lang.ref.ReferenceQueue; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryDaemonPollingTaskTest { @@ -32,7 +32,7 @@ public class BigQueryDaemonPollingTaskTest { static List arrowResultSetFinalizers; static List jsonResultSetFinalizers; - @Before + @BeforeEach public void setUp() { referenceQueueArrowRs = new ReferenceQueue<>(); referenceQueueJsonRs = new ReferenceQueue<>(); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java index 536aae15bf..e41aadf582 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java @@ -16,13 +16,13 @@ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -44,8 +44,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.regex.Pattern; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryDatabaseMetaDataTest { @@ -53,7 +53,7 @@ public class BigQueryDatabaseMetaDataTest { private BigQueryDatabaseMetaData dbMetadata; private BigQuery bigqueryClient; - @Before + @BeforeEach public void setUp() throws SQLException { bigQueryConnection = mock(BigQueryConnection.class); bigqueryClient = mock(BigQuery.class); @@ -161,12 +161,12 @@ public void testReadSqlFromFile() throws SQLException { @Test public void testNeedsListing() { - assertTrue("Null pattern should require listing", dbMetadata.needsListing(null)); - assertTrue("Pattern with % should require listing", dbMetadata.needsListing("abc%def")); - assertTrue("Pattern with _ should require listing", dbMetadata.needsListing("abc_def")); - assertTrue("Pattern with both wildcards", dbMetadata.needsListing("a%c_d%f")); - assertFalse("Empty pattern should not require listing", dbMetadata.needsListing("")); - assertFalse("Pattern without wildcards", dbMetadata.needsListing("exactName")); + assertTrue(dbMetadata.needsListing(null), "Null pattern should require listing"); + assertTrue(dbMetadata.needsListing("abc%def"), "Pattern with % should require listing"); + assertTrue(dbMetadata.needsListing("abc_def"), "Pattern with _ should require listing"); + assertTrue(dbMetadata.needsListing("a%c_d%f"), "Pattern with both wildcards"); + assertFalse(dbMetadata.needsListing(""), "Empty pattern should not require listing"); + assertFalse(dbMetadata.needsListing("exactName"), "Pattern without wildcards"); } @Test @@ -616,7 +616,7 @@ public void testSortResults_Tables() { assertEquals(6, results.size()); // 1. Null cat, sch_b, table_0, TABLE - assertTrue("Row 0 TABLE_CAT should be null", results.get(0).get("TABLE_CAT").isNull()); + assertTrue(results.get(0).get("TABLE_CAT").isNull(), "Row 0 TABLE_CAT should be null"); assertEquals("sch_b", results.get(0).get("TABLE_SCHEM").getStringValue()); assertEquals("table_0", results.get(0).get("TABLE_NAME").getStringValue()); assertEquals("TABLE", results.get(0).get("TABLE_TYPE").getStringValue()); @@ -641,7 +641,7 @@ public void testSortResults_Tables() { // 5. cat_a, null, view_0, VIEW assertEquals("cat_a", results.get(4).get("TABLE_CAT").getStringValue()); - assertTrue("Row 4 TABLE_SCHEM should be null", results.get(4).get("TABLE_SCHEM").isNull()); + assertTrue(results.get(4).get("TABLE_SCHEM").isNull(), "Row 4 TABLE_SCHEM should be null"); assertEquals("view_0", results.get(4).get("TABLE_NAME").getStringValue()); assertEquals("VIEW", results.get(4).get("TABLE_TYPE").getStringValue()); @@ -734,7 +734,7 @@ public void testSortResults_Schemas() { assertEquals(5, results.size()); // 1. Null catalog, schema_x - assertTrue("Row 0 TABLE_CATALOG should be null", results.get(0).get("TABLE_CATALOG").isNull()); + assertTrue(results.get(0).get("TABLE_CATALOG").isNull(), "Row 0 TABLE_CATALOG should be null"); assertEquals("schema_x", results.get(0).get("TABLE_SCHEM").getStringValue()); // 2. proj_a, schema_c @@ -913,14 +913,14 @@ public void testSortResults_Procedures() { assertEquals(6, results.size()); // 1. Null cat, sch_y, proc_gamma, proc_gamma_spec - assertTrue("Row 0 PROC_CAT should be null", results.get(0).get("PROCEDURE_CAT").isNull()); + assertTrue(results.get(0).get("PROCEDURE_CAT").isNull(), "Row 0 PROC_CAT should be null"); assertEquals("sch_y", results.get(0).get("PROCEDURE_SCHEM").getStringValue()); assertEquals("proc_gamma", results.get(0).get("PROCEDURE_NAME").getStringValue()); assertEquals("proc_gamma_spec", results.get(0).get("SPECIFIC_NAME").getStringValue()); // 2. cat_a, Null schem, proc_delta, proc_delta_spec assertEquals("cat_a", results.get(1).get("PROCEDURE_CAT").getStringValue()); - assertTrue("Row 1 PROC_SCHEM should be null", results.get(1).get("PROCEDURE_SCHEM").isNull()); + assertTrue(results.get(1).get("PROCEDURE_SCHEM").isNull(), "Row 1 PROC_SCHEM should be null"); assertEquals("proc_delta", results.get(1).get("PROCEDURE_NAME").getStringValue()); assertEquals("proc_delta_spec", results.get(1).get("SPECIFIC_NAME").getStringValue()); @@ -1004,11 +1004,11 @@ public void testFindMatchingBigQueryObjects_Routines_ListWithPattern() { assertNotNull(results); List resultList = new ArrayList<>(results); - assertEquals("Should contain only matching routines", 2, resultList.size()); - assertTrue("Should contain proc_abc", resultList.contains(proc1)); - assertTrue("Should contain proc_xyz", resultList.contains(proc2)); - assertFalse("Should not contain func_123", resultList.contains(func1)); - assertFalse("Should not contain another_proc", resultList.contains(otherProc)); + assertEquals(2, resultList.size(), "Should contain only matching routines"); + assertTrue(resultList.contains(proc1), "Should contain proc_abc"); + assertTrue(resultList.contains(proc2), "Should contain proc_xyz"); + assertFalse(resultList.contains(func1), "Should not contain func_123"); + assertFalse(resultList.contains(otherProc), "Should not contain another_proc"); } @Test @@ -1045,9 +1045,9 @@ public void testFindMatchingBigQueryObjects_Routines_ListNoPattern() { assertNotNull(results); List resultList = new ArrayList<>(results); - assertEquals("Should contain all routines when pattern is null", 2, resultList.size()); - assertTrue("Should contain proc_abc", resultList.contains(proc1)); - assertTrue("Should contain func_123", resultList.contains(func1)); + assertEquals(2, resultList.size(), "Should contain all routines when pattern is null"); + assertTrue(resultList.contains(proc1), "Should contain proc_abc"); + assertTrue(resultList.contains(func1), "Should contain func_123"); } @Test @@ -1617,18 +1617,15 @@ public void testSubmitProcedureArgumentProcessingJobs_Basic() throws Interrupted public void testDefineGetTableTypesSchema() { Schema schema = BigQueryDatabaseMetaData.defineGetTableTypesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Should have one column", 1, fields.size()); + assertEquals(1, fields.size(), "Should have one column"); Field tableTypeField = fields.get("TABLE_TYPE"); - assertNotNull("TABLE_TYPE field should exist", tableTypeField); - assertEquals("Field name should be TABLE_TYPE", "TABLE_TYPE", tableTypeField.getName()); - assertEquals( - "Field type should be STRING", - StandardSQLTypeName.STRING, - tableTypeField.getType().getStandardType()); - assertEquals("Field mode should be REQUIRED", Field.Mode.REQUIRED, tableTypeField.getMode()); + assertNotNull(tableTypeField, "TABLE_TYPE field should exist"); + assertEquals("TABLE_TYPE", tableTypeField.getName(), "Field name should be TABLE_TYPE"); + assertEquals(StandardSQLTypeName.STRING, tableTypeField.getType().getStandardType(), "Field type should be STRING"); + assertEquals(Field.Mode.REQUIRED, tableTypeField.getMode(), "Field mode should be REQUIRED"); } @Test @@ -1636,39 +1633,33 @@ public void testPrepareGetTableTypesRows() { Schema schema = BigQueryDatabaseMetaData.defineGetTableTypesSchema(); List rows = BigQueryDatabaseMetaData.prepareGetTableTypesRows(schema); - assertNotNull("Rows list should not be null", rows); + assertNotNull(rows, "Rows list should not be null"); String[] expectedTableTypes = {"EXTERNAL", "MATERIALIZED VIEW", "SNAPSHOT", "TABLE", "VIEW"}; - assertEquals( - "Should have " + expectedTableTypes.length + " rows", - expectedTableTypes.length, - rows.size()); + assertEquals(expectedTableTypes.length, rows.size(), "Should have " + expectedTableTypes.length + " rows"); Set foundTypes = new HashSet<>(); for (int i = 0; i < rows.size(); i++) { FieldValueList row = rows.get(i); - assertEquals("Row " + i + " should have 1 field value", 1, row.size()); - assertFalse("FieldValue in row " + i + " should not be SQL NULL", row.get(0).isNull()); + assertEquals(1, row.size(), "Row " + i + " should have 1 field value"); + assertFalse(row.get(0).isNull(), "FieldValue in row " + i + " should not be SQL NULL"); String tableType = row.get(0).getStringValue(); foundTypes.add(tableType); } - assertEquals( - "All expected table types should be present and correctly mapped", - new HashSet<>(Arrays.asList(expectedTableTypes)), - foundTypes); + assertEquals(new HashSet<>(Arrays.asList(expectedTableTypes)), foundTypes, "All expected table types should be present and correctly mapped"); } @Test public void testGetTableTypes() throws SQLException { try (ResultSet rs = dbMetadata.getTableTypes()) { - assertNotNull("ResultSet from getTableTypes() should not be null", rs); + assertNotNull(rs, "ResultSet from getTableTypes() should not be null"); ResultSetMetaData rsmd = rs.getMetaData(); - assertNotNull("ResultSetMetaData should not be null", rsmd); - assertEquals("Should have one column", 1, rsmd.getColumnCount()); - assertEquals("Column name should be TABLE_TYPE", "TABLE_TYPE", rsmd.getColumnName(1)); - assertEquals("Column type should be NVARCHAR", Types.NVARCHAR, rsmd.getColumnType(1)); + assertNotNull(rsmd, "ResultSetMetaData should not be null"); + assertEquals(1, rsmd.getColumnCount(), "Should have one column"); + assertEquals("TABLE_TYPE", rsmd.getColumnName(1), "Column name should be TABLE_TYPE"); + assertEquals(Types.NVARCHAR, rsmd.getColumnType(1), "Column type should be NVARCHAR"); List actualTableTypes = new ArrayList<>(); while (rs.next()) { @@ -1676,22 +1667,20 @@ public void testGetTableTypes() throws SQLException { } String[] expectedTableTypes = {"EXTERNAL", "MATERIALIZED VIEW", "SNAPSHOT", "TABLE", "VIEW"}; - assertEquals( - "Number of table types should match", expectedTableTypes.length, actualTableTypes.size()); + assertEquals(expectedTableTypes.length, actualTableTypes.size(), "Number of table types should match"); Set expectedSet = new HashSet<>(Arrays.asList(expectedTableTypes)); Set actualSet = new HashSet<>(actualTableTypes); - assertEquals( - "All expected table types should be present in the ResultSet", expectedSet, actualSet); + assertEquals(expectedSet, actualSet, "All expected table types should be present in the ResultSet"); } } @Test public void testDefineGetSuperTablesSchema() { Schema schema = dbMetadata.defineGetSuperTablesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 4 fields", 4, fields.size()); + assertEquals(4, fields.size(), "Schema should have 4 fields"); Field tableCat = fields.get("TABLE_CAT"); assertNotNull(tableCat); @@ -1722,12 +1711,12 @@ public void testDefineGetSuperTablesSchema() { public void testGetSuperTables_ReturnsEmptyResultSetWithCorrectMetadata() throws SQLException { try (ResultSet rs = dbMetadata.getSuperTables("testCatalog", "testSchemaPattern", "testTableNamePattern")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty (next() should return false)", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty (next() should return false)"); ResultSetMetaData metaData = rs.getMetaData(); - assertNotNull("ResultSetMetaData should not be null", metaData); - assertEquals("ResultSetMetaData should have 4 columns", 4, metaData.getColumnCount()); + assertNotNull(metaData, "ResultSetMetaData should not be null"); + assertEquals(4, metaData.getColumnCount(), "ResultSetMetaData should have 4 columns"); // Column 1: TABLE_CAT assertEquals("TABLE_CAT", metaData.getColumnName(1)); @@ -1754,9 +1743,9 @@ public void testGetSuperTables_ReturnsEmptyResultSetWithCorrectMetadata() throws @Test public void testDefineGetSuperTypesSchema() { Schema schema = dbMetadata.defineGetSuperTypesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 6 fields", 6, fields.size()); + assertEquals(6, fields.size(), "Schema should have 6 fields"); Field typeCat = fields.get("TYPE_CAT"); assertNotNull(typeCat); @@ -1799,12 +1788,12 @@ public void testDefineGetSuperTypesSchema() { public void testGetSuperTypes_ReturnsEmptyResultSetWithCorrectMetadata() throws SQLException { try (ResultSet rs = dbMetadata.getSuperTypes("testCatalog", "testSchemaPattern", "testTypeNamePattern")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty (next() should return false)", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty (next() should return false)"); ResultSetMetaData metaData = rs.getMetaData(); - assertNotNull("ResultSetMetaData should not be null", metaData); - assertEquals("ResultSetMetaData should have 6 columns", 6, metaData.getColumnCount()); + assertNotNull(metaData, "ResultSetMetaData should not be null"); + assertEquals(6, metaData.getColumnCount(), "ResultSetMetaData should have 6 columns"); // Column 1: TYPE_CAT assertEquals("TYPE_CAT", metaData.getColumnName(1)); @@ -1841,9 +1830,9 @@ public void testGetSuperTypes_ReturnsEmptyResultSetWithCorrectMetadata() throws @Test public void testDefineGetAttributesSchema() { Schema schema = dbMetadata.defineGetAttributesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 21 fields", 21, fields.size()); + assertEquals(21, fields.size(), "Schema should have 21 fields"); assertEquals("TYPE_CAT", fields.get(0).getName()); assertEquals(StandardSQLTypeName.STRING, fields.get(0).getType().getStandardType()); @@ -1874,11 +1863,11 @@ public void testDefineGetAttributesSchema() { public void testGetAttributes_ReturnsEmptyResultSet() throws SQLException { try (ResultSet rs = dbMetadata.getAttributes("testCat", "testSchema", "testType", "testAttr%")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 21 columns", 21, metaData.getColumnCount()); + assertEquals(21, metaData.getColumnCount(), "ResultSetMetaData should have 21 columns"); assertEquals("TYPE_CAT", metaData.getColumnName(1)); assertEquals(Types.NVARCHAR, metaData.getColumnType(1)); @@ -1909,9 +1898,9 @@ public void testGetAttributes_ReturnsEmptyResultSet() throws SQLException { @Test public void testDefineGetBestRowIdentifierSchema() { Schema schema = dbMetadata.defineGetBestRowIdentifierSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 8 fields", 8, fields.size()); + assertEquals(8, fields.size(), "Schema should have 8 fields"); assertEquals("SCOPE", fields.get(0).getName()); assertEquals(StandardSQLTypeName.INT64, fields.get(0).getType().getStandardType()); @@ -1947,11 +1936,11 @@ public void testGetBestRowIdentifier_ReturnsEmptyResultSetWithCorrectMetadata() try (ResultSet rs = dbMetadata.getBestRowIdentifier( "testCat", "testSchema", "testTable", testScope, testNullable)) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 8 columns", 8, metaData.getColumnCount()); + assertEquals(8, metaData.getColumnCount(), "ResultSetMetaData should have 8 columns"); assertEquals("SCOPE", metaData.getColumnName(1)); assertEquals(Types.BIGINT, metaData.getColumnType(1)); @@ -1978,9 +1967,9 @@ public void testGetBestRowIdentifier_ReturnsEmptyResultSetWithCorrectMetadata() @Test public void testDefineGetUDTsSchema() { Schema schema = dbMetadata.defineGetUDTsSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 7 fields", 7, fields.size()); + assertEquals(7, fields.size(), "Schema should have 7 fields"); assertEquals("TYPE_NAME", fields.get("TYPE_NAME").getName()); assertEquals(StandardSQLTypeName.STRING, fields.get("TYPE_NAME").getType().getStandardType()); @@ -2003,11 +1992,11 @@ public void testDefineGetUDTsSchema() { public void testGetUDTs_ReturnsEmptyResultSet() throws SQLException { int[] types = {Types.STRUCT, Types.DISTINCT}; try (ResultSet rs = dbMetadata.getUDTs("testCat", "testSchema%", "testType%", types)) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 7 columns", 7, metaData.getColumnCount()); + assertEquals(7, metaData.getColumnCount(), "ResultSetMetaData should have 7 columns"); assertEquals("TYPE_NAME", metaData.getColumnName(3)); assertEquals(Types.NVARCHAR, metaData.getColumnType(3)); @@ -2026,9 +2015,9 @@ public void testGetUDTs_ReturnsEmptyResultSet() throws SQLException { @Test public void testDefineGetIndexInfoSchema() { Schema schema = dbMetadata.defineGetIndexInfoSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 13 fields", 13, fields.size()); + assertEquals(13, fields.size(), "Schema should have 13 fields"); assertEquals("TABLE_NAME", fields.get(2).getName()); assertEquals(StandardSQLTypeName.STRING, fields.get(2).getType().getStandardType()); @@ -2050,11 +2039,11 @@ public void testDefineGetIndexInfoSchema() { @Test public void testGetIndexInfo_ReturnsEmptyResultSetWithCorrectMetadata() throws SQLException { try (ResultSet rs = dbMetadata.getIndexInfo("testCat", "testSchema", "testTable", true, true)) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 13 columns", 13, metaData.getColumnCount()); + assertEquals(13, metaData.getColumnCount(), "ResultSetMetaData should have 13 columns"); assertEquals("TABLE_NAME", metaData.getColumnName(3)); assertEquals(Types.NVARCHAR, metaData.getColumnType(3)); @@ -2077,9 +2066,9 @@ public void testGetIndexInfo_ReturnsEmptyResultSetWithCorrectMetadata() throws S @Test public void testDefineGetTablePrivilegesSchema() { Schema schema = dbMetadata.defineGetTablePrivilegesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 7 fields", 7, fields.size()); + assertEquals(7, fields.size(), "Schema should have 7 fields"); assertEquals("TABLE_CAT", fields.get(0).getName()); assertEquals(StandardSQLTypeName.STRING, fields.get(0).getType().getStandardType()); @@ -2106,11 +2095,11 @@ public void testDefineGetTablePrivilegesSchema() { public void testGetTablePrivileges_ReturnsEmptyResultSetWithCorrectMetadata() throws SQLException { try (ResultSet rs = dbMetadata.getTablePrivileges("testCat", "testSchema%", "testTable%")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 7 columns", 7, metaData.getColumnCount()); + assertEquals(7, metaData.getColumnCount(), "ResultSetMetaData should have 7 columns"); assertEquals("TABLE_CAT", metaData.getColumnName(1)); assertEquals(Types.NVARCHAR, metaData.getColumnType(1)); @@ -2137,9 +2126,9 @@ public void testGetTablePrivileges_ReturnsEmptyResultSetWithCorrectMetadata() @Test public void testDefineGetColumnPrivilegesSchema() { Schema schema = dbMetadata.defineGetColumnPrivilegesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 8 fields", 8, fields.size()); + assertEquals(8, fields.size(), "Schema should have 8 fields"); assertEquals("TABLE_SCHEM", fields.get(1).getName()); assertEquals(StandardSQLTypeName.STRING, fields.get(1).getType().getStandardType()); @@ -2167,11 +2156,11 @@ public void testGetColumnPrivileges_ReturnsEmptyResultSetWithCorrectMetadata() throws SQLException { try (ResultSet rs = dbMetadata.getColumnPrivileges("testCat", "testSchema", "testTable", "testCol%")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 8 columns", 8, metaData.getColumnCount()); + assertEquals(8, metaData.getColumnCount(), "ResultSetMetaData should have 8 columns"); assertEquals("TABLE_SCHEM", metaData.getColumnName(2)); assertEquals(Types.NVARCHAR, metaData.getColumnType(2)); @@ -2198,9 +2187,9 @@ public void testGetColumnPrivileges_ReturnsEmptyResultSetWithCorrectMetadata() @Test public void testDefineGetVersionColumnsSchema() { Schema schema = dbMetadata.defineGetVersionColumnsSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 8 fields", 8, fields.size()); + assertEquals(8, fields.size(), "Schema should have 8 fields"); assertEquals("SCOPE", fields.get(0).getName()); assertEquals(StandardSQLTypeName.INT64, fields.get(0).getType().getStandardType()); @@ -2226,11 +2215,11 @@ public void testDefineGetVersionColumnsSchema() { @Test public void testGetVersionColumns_ReturnsEmptyResultSetWithCorrectMetadata() throws SQLException { try (ResultSet rs = dbMetadata.getVersionColumns("testCat", "testSchema", "testTable")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 8 columns", 8, metaData.getColumnCount()); + assertEquals(8, metaData.getColumnCount(), "ResultSetMetaData should have 8 columns"); assertEquals("SCOPE", metaData.getColumnName(1)); assertEquals(Types.BIGINT, metaData.getColumnType(1)); @@ -2257,9 +2246,9 @@ public void testGetVersionColumns_ReturnsEmptyResultSetWithCorrectMetadata() thr @Test public void testDefineGetPseudoColumnsSchema() { Schema schema = dbMetadata.defineGetPseudoColumnsSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 12 fields", 12, fields.size()); + assertEquals(12, fields.size(), "Schema should have 12 fields"); assertEquals("TABLE_NAME", fields.get(2).getName()); assertEquals(StandardSQLTypeName.STRING, fields.get(2).getType().getStandardType()); @@ -2289,11 +2278,11 @@ public void testDefineGetPseudoColumnsSchema() { @Test public void testGetPseudoColumns_ReturnsEmptyResultSet() throws SQLException { try (ResultSet rs = dbMetadata.getPseudoColumns("testCat", "testSchema%", "testTable%", "%")) { - assertNotNull("ResultSet should not be null", rs); - assertFalse("ResultSet should be empty", rs.next()); + assertNotNull(rs, "ResultSet should not be null"); + assertFalse(rs.next(), "ResultSet should be empty"); ResultSetMetaData metaData = rs.getMetaData(); - assertEquals("ResultSetMetaData should have 12 columns", 12, metaData.getColumnCount()); + assertEquals(12, metaData.getColumnCount(), "ResultSetMetaData should have 12 columns"); assertEquals("TABLE_NAME", metaData.getColumnName(3)); assertEquals(Types.NVARCHAR, metaData.getColumnType(3)); @@ -2515,9 +2504,9 @@ public void testSortResults_Functions() { @Test public void testDefineGetTypeInfoSchema() { Schema schema = dbMetadata.defineGetTypeInfoSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 18 fields", 18, fields.size()); + assertEquals(18, fields.size(), "Schema should have 18 fields"); Field typeName = fields.get("TYPE_NAME"); assertNotNull(typeName); @@ -2556,15 +2545,15 @@ public void testPrepareGetTypeInfoRows() { FieldList schemaFields = typeInfoSchema.getFields(); List rows = dbMetadata.prepareGetTypeInfoRows(schemaFields); - assertNotNull("Rows list should not be null", rows); - assertEquals("Should have 17 rows for 17 types", 17, rows.size()); + assertNotNull(rows, "Rows list should not be null"); + assertEquals(17, rows.size(), "Should have 17 rows for 17 types"); // INT64 (should be BIGINT in JDBC) Optional int64RowOpt = rows.stream() .filter(row -> "INT64".equals(row.get("TYPE_NAME").getStringValue())) .findFirst(); - assertTrue("INT64 type info row should exist", int64RowOpt.isPresent()); + assertTrue(int64RowOpt.isPresent(), "INT64 type info row should exist"); FieldValueList int64Row = int64RowOpt.get(); assertEquals(String.valueOf(Types.BIGINT), int64Row.get("DATA_TYPE").getStringValue()); assertEquals("19", int64Row.get("PRECISION").getStringValue()); @@ -2578,7 +2567,7 @@ public void testPrepareGetTypeInfoRows() { rows.stream() .filter(row -> "BOOL".equals(row.get("TYPE_NAME").getStringValue())) .findFirst(); - assertTrue("BOOL type info row should exist", boolRowOpt.isPresent()); + assertTrue(boolRowOpt.isPresent(), "BOOL type info row should exist"); FieldValueList boolRow = boolRowOpt.get(); assertEquals(String.valueOf(Types.BOOLEAN), boolRow.get("DATA_TYPE").getStringValue()); assertEquals("1", boolRow.get("PRECISION").getStringValue()); @@ -2592,7 +2581,7 @@ public void testPrepareGetTypeInfoRows() { rows.stream() .filter(row -> "STRING".equals(row.get("TYPE_NAME").getStringValue())) .findFirst(); - assertTrue("STRING type info row should exist", stringRowOpt.isPresent()); + assertTrue(stringRowOpt.isPresent(), "STRING type info row should exist"); FieldValueList stringRow = stringRowOpt.get(); assertEquals(String.valueOf(Types.NVARCHAR), stringRow.get("DATA_TYPE").getStringValue()); assertTrue(stringRow.get("PRECISION").isNull()); // Precision is null for STRING @@ -2608,11 +2597,11 @@ public void testPrepareGetTypeInfoRows() { @Test public void testGetTypeInfo() throws SQLException { try (ResultSet rs = dbMetadata.getTypeInfo()) { - assertNotNull("ResultSet from getTypeInfo() should not be null", rs); + assertNotNull(rs, "ResultSet from getTypeInfo() should not be null"); ResultSetMetaData rsmd = rs.getMetaData(); - assertNotNull("ResultSetMetaData should not be null", rsmd); - assertEquals("Should have 18 columns", 18, rsmd.getColumnCount()); + assertNotNull(rsmd, "ResultSetMetaData should not be null"); + assertEquals(18, rsmd.getColumnCount(), "Should have 18 columns"); assertEquals("TYPE_NAME", rsmd.getColumnName(1)); assertEquals("DATA_TYPE", rsmd.getColumnName(2)); assertEquals("PRECISION", rsmd.getColumnName(3)); @@ -2627,12 +2616,12 @@ public void testGetTypeInfo() throws SQLException { assertEquals(19, rs.getInt("PRECISION")); } } - assertEquals("Should have 17 rows for 17 types", 17, rowCount); + assertEquals(17, rowCount, "Should have 17 rows for 17 types"); // Verify sorting by DATA_TYPE List sortedDataTypes = new ArrayList<>(dataTypes); Collections.sort(sortedDataTypes); - assertEquals("Results should be sorted by DATA_TYPE", sortedDataTypes, dataTypes); + assertEquals(sortedDataTypes, dataTypes, "Results should be sorted by DATA_TYPE"); } } @@ -2795,9 +2784,9 @@ public void testProcessFunctionParametersAndReturnValue_ColumnNameFilter() { @Test public void testDefineGetClientInfoPropertiesSchema() { Schema schema = dbMetadata.defineGetClientInfoPropertiesSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Schema should have 4 fields", 4, fields.size()); + assertEquals(4, fields.size(), "Schema should have 4 fields"); Field nameField = fields.get("NAME"); assertNotNull(nameField); @@ -2827,11 +2816,11 @@ public void testDefineGetClientInfoPropertiesSchema() { @Test public void testGetClientInfoProperties() throws SQLException { try (ResultSet rs = dbMetadata.getClientInfoProperties()) { - assertNotNull("ResultSet from getClientInfoProperties() should not be null", rs); + assertNotNull(rs, "ResultSet from getClientInfoProperties() should not be null"); ResultSetMetaData rsmd = rs.getMetaData(); - assertNotNull("ResultSetMetaData should not be null", rsmd); - assertEquals("Should have 4 columns", 4, rsmd.getColumnCount()); + assertNotNull(rsmd, "ResultSetMetaData should not be null"); + assertEquals(4, rsmd.getColumnCount(), "Should have 4 columns"); assertEquals("NAME", rsmd.getColumnName(1)); assertEquals(Types.NVARCHAR, rsmd.getColumnType(1)); assertEquals("MAX_LEN", rsmd.getColumnName(2)); @@ -2851,7 +2840,7 @@ public void testGetClientInfoProperties() throws SQLException { actualRows.add(row); } - assertEquals("Should return 3 client info properties", 3, actualRows.size()); + assertEquals(3, actualRows.size(), "Should return 3 client info properties"); Map appNameRow = actualRows.get(0); assertEquals("ApplicationName", appNameRow.get("NAME")); @@ -2872,18 +2861,15 @@ public void testGetClientInfoProperties() throws SQLException { @Test public void testDefineGetCatalogsSchema() { Schema schema = dbMetadata.defineGetCatalogsSchema(); - assertNotNull("Schema should not be null", schema); + assertNotNull(schema, "Schema should not be null"); FieldList fields = schema.getFields(); - assertEquals("Should have one column", 1, fields.size()); + assertEquals(1, fields.size(), "Should have one column"); Field tableCatField = fields.get("TABLE_CAT"); - assertNotNull("TABLE_CAT field should exist", tableCatField); - assertEquals("Field name should be TABLE_CAT", "TABLE_CAT", tableCatField.getName()); - assertEquals( - "Field type should be STRING", - StandardSQLTypeName.STRING, - tableCatField.getType().getStandardType()); - assertEquals("Field mode should be REQUIRED", Field.Mode.REQUIRED, tableCatField.getMode()); + assertNotNull(tableCatField, "TABLE_CAT field should exist"); + assertEquals("TABLE_CAT", tableCatField.getName(), "Field name should be TABLE_CAT"); + assertEquals(StandardSQLTypeName.STRING, tableCatField.getType().getStandardType(), "Field type should be STRING"); + assertEquals(Field.Mode.REQUIRED, tableCatField.getMode(), "Field mode should be REQUIRED"); } @Test @@ -2898,22 +2884,19 @@ public void testPrepareGetCatalogsRows() { List rowsWithCatalog = dbMetadata.prepareGetCatalogsRows(schemaFields, testCatalogName); - assertNotNull("Rows list should not be null when catalog name is provided", rowsWithCatalog); - assertEquals("Should have one row when a catalog name is provided", 1, rowsWithCatalog.size()); + assertNotNull(rowsWithCatalog, "Rows list should not be null when catalog name is provided"); + assertEquals(1, rowsWithCatalog.size(), "Should have one row when a catalog name is provided"); FieldValueList row = rowsWithCatalog.get(0); - assertEquals("Row should have 1 field value", 1, row.size()); - assertFalse("FieldValue in row should not be SQL NULL", row.get(0).isNull()); - assertEquals( - "TABLE_CAT should match the provided catalog name", - testCatalogName.get(0), - row.get(0).getStringValue()); + assertEquals(1, row.size(), "Row should have 1 field value"); + assertFalse(row.get(0).isNull(), "FieldValue in row should not be SQL NULL"); + assertEquals(testCatalogName.get(0), row.get(0).getStringValue(), "TABLE_CAT should match the provided catalog name"); // Test with empty catalog name list List testEmptyCatalogList = new ArrayList<>(); List rowsWithNullCatalog = dbMetadata.prepareGetCatalogsRows(schemaFields, testEmptyCatalogList); - assertNotNull("Rows list should not be null when catalog name is null", rowsWithNullCatalog); - assertTrue("Should have zero rows when catalog name is null", rowsWithNullCatalog.isEmpty()); + assertNotNull(rowsWithNullCatalog, "Rows list should not be null when catalog name is null"); + assertTrue(rowsWithNullCatalog.isEmpty(), "Should have zero rows when catalog name is null"); } @Test @@ -2924,8 +2907,7 @@ public void testGetSchemas_NoArgs_DelegatesCorrectly() { ResultSet rs = spiedDbMetadata.getSchemas(); - assertSame( - "The returned ResultSet should be the one from the two-argument method", mockResultSet, rs); + assertSame(mockResultSet, rs, "The returned ResultSet should be the one from the two-argument method"); verify(spiedDbMetadata, times(1)).getSchemas(null, null); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDefaultCoercionsTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDefaultCoercionsTest.java index d9cc0efb77..1b50ded79b 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDefaultCoercionsTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDefaultCoercionsTest.java @@ -23,21 +23,13 @@ import java.math.BigInteger; import java.util.Arrays; import java.util.Collection; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) -public class BigQueryDefaultCoercionsTest { - - private final BigQueryTypeCoercer bigQueryTypeCoercer; - public BigQueryDefaultCoercionsTest(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { - this.bigQueryTypeCoercer = bigQueryTypeCoercer; - } +public class BigQueryDefaultCoercionsTest { - @Parameters(name = "{index}: {0}") + // migrated public static Collection data() { return Arrays.asList( new Object[][] { @@ -46,176 +38,206 @@ public static Collection data() { }); } - @Test - public void stringToBoolean() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void stringToBoolean(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Boolean.class, "true")).isTrue(); assertThat(bigQueryTypeCoercer.coerceTo(Boolean.class, "false")).isFalse(); } - @Test - public void stringToInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void stringToInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, "3452148")).isEqualTo(3452148); } - @Test - public void stringToBigInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void stringToBigInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(BigInteger.class, "2147483647456")) .isEqualTo(new BigInteger("2147483647456")); } - @Test - public void stringToLong() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void stringToLong(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Long.class, "2147483647456")) .isEqualTo(Long.valueOf("2147483647456")); } - @Test - public void stringToDouble() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void stringToDouble(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Double.class, "2147483647456.56684593495")) .isEqualTo(Double.valueOf("2147483647456.56684593495")); } - @Test - public void stringToBigDecimal() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void stringToBigDecimal(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(BigDecimal.class, "2147483647456.56684593495")) .isEqualTo(new BigDecimal("2147483647456.56684593495")); } - @Test - public void booleanToString() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void booleanToString(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(String.class, true)).isEqualTo("true"); assertThat(bigQueryTypeCoercer.coerceTo(String.class, false)).isEqualTo("false"); } - @Test - public void booleanToInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void booleanToInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, true)).isEqualTo(1); assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, false)).isEqualTo(0); } - @Test - public void longToInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void longToInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, 2147483647L)).isEqualTo(2147483647); } - @Test - public void longToShort() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void longToShort(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Short.class, 32000L)).isEqualTo((short) 32000); } - @Test - public void longToByte() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void longToByte(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Byte.class, 127L)).isEqualTo((byte) 127); } - @Test - public void longToDouble() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void longToDouble(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Double.class, 2147483647456L)) .isEqualTo(Double.valueOf("2147483647456")); } - @Test - public void longToString() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void longToString(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(String.class, 2147483647456L)) .isEqualTo("2147483647456"); } - @Test - public void doubleToFloat() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void doubleToFloat(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Float.class, Double.valueOf("4567.213245"))) .isEqualTo(Float.valueOf("4567.213245")); } - @Test - public void doubleToLong() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void doubleToLong(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Long.class, Double.valueOf("2147483647456.213245"))) .isEqualTo(2147483647456L); } - @Test - public void doubleToInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void doubleToInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, Double.valueOf("21474836.213245"))) .isEqualTo(21474836); } - @Test - public void doubleToBigDecimal() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void doubleToBigDecimal(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(BigDecimal.class, Double.valueOf("21474836.213245"))) .isEqualTo(new BigDecimal("21474836.213245")); } - @Test - public void doubleToString() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void doubleToString(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(String.class, Double.valueOf("21474836.213245"))) .isEqualTo("2.1474836213245E7"); } - @Test - public void floatToInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void floatToInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, 62356.45f)).isEqualTo(62356); } - @Test - public void floatToDouble() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void floatToDouble(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Double.class, 62356.45f)) .isEqualTo(Double.valueOf(62356.45f)); } - @Test - public void floatToString() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void floatToString(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(String.class, 62356.45f)).isEqualTo("62356.45"); } - @Test - public void bigIntegerToLong() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigIntegerToLong(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Long.class, new BigInteger("2147483647"))) .isEqualTo(2147483647L); } - @Test - public void bigIntegerToBigDecimal() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigIntegerToBigDecimal(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(BigDecimal.class, new BigInteger("2147483647"))) .isEqualTo(new BigDecimal("2147483647")); } - @Test - public void bigIntegerToString() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigIntegerToString(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(String.class, new BigInteger("2147483647"))) .isEqualTo("2147483647"); } - @Test - public void bigDecimalToDouble() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigDecimalToDouble(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Double.class, new BigDecimal("2147483647.74356"))) .isEqualTo(2147483647.74356); } - @Test - public void bigDecimalToBigInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigDecimalToBigInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(BigInteger.class, new BigDecimal("2147483647.74356"))) .isEqualTo(new BigInteger("2147483647")); } - @Test - public void bigDecimalToInteger() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigDecimalToInteger(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Integer.class, new BigDecimal("2147483647.74356"))) .isEqualTo(2147483647); } - @Test - public void bigDecimalToLong() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigDecimalToLong(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Long.class, new BigDecimal("2147483647.74356"))) .isEqualTo(2147483647L); } - @Test - public void bigDecimalToString() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void bigDecimalToString(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(String.class, new BigDecimal("2147483647.74356"))) .isEqualTo("2147483647.74356"); } - @Test - public void nullToBoolean() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void nullToBoolean(String label, BigQueryTypeCoercer bigQueryTypeCoercer) { assertThat(bigQueryTypeCoercer.coerceTo(Boolean.class, null)).isFalse(); } } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDriverTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDriverTest.java index 2d7664f5a0..03e4ea3fb6 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDriverTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDriverTest.java @@ -16,7 +16,7 @@ package com.google.cloud.bigquery.jdbc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import com.google.cloud.bigquery.exception.BigQueryJdbcException; import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException; @@ -25,14 +25,14 @@ import java.sql.SQLException; import java.util.Properties; import java.util.logging.Logger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryDriverTest { static BigQueryDriver bigQueryDriver; - @Before + @BeforeEach public void setUp() { bigQueryDriver = BigQueryDriver.getRegisteredDriver(); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtilityTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtilityTest.java index 958a5e99ea..ac2a7a8661 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtilityTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtilityTest.java @@ -17,11 +17,11 @@ package com.google.cloud.bigquery.jdbc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.auth.oauth2.GoogleCredentials; import com.google.auth.oauth2.ImpersonatedCredentials; @@ -38,9 +38,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class BigQueryJdbcOAuthUtilityTest extends BigQueryJdbcBaseTest { @@ -110,7 +110,7 @@ public void testInvalidTokenUriForAuthType0() { try { BigQueryJdbcOAuthUtility.getCredentials(oauthProperties, overrideProperties, null); - Assert.fail(); + Assertions.fail(); } catch (BigQueryJdbcRuntimeException e) { assertThat(e.getMessage()).contains("java.net.URISyntaxException"); } @@ -190,7 +190,7 @@ public void testGetCredentialsForPreGeneratedTokenTPC() throws IOException { } @Test - @Ignore // For running locally only similar to our other JDBC tests. + @Disabled // For running locally only similar to our other JDBC tests. public void testGetCredentialsForApplicationDefault() { Map authProperties = BigQueryJdbcOAuthUtility.parseOAuthProperties( diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcParameterTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcParameterTest.java index 815759892b..5af6077a73 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcParameterTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcParameterTest.java @@ -16,11 +16,11 @@ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.cloud.bigquery.StandardSQLTypeName; import com.google.cloud.bigquery.jdbc.BigQueryParameterHandler.BigQueryStatementParameterType; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BigQueryJdbcParameterTest { diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcProxyUtilityTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcProxyUtilityTest.java index a69cf68e0b..ea62166e01 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcProxyUtilityTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcProxyUtilityTest.java @@ -17,9 +17,9 @@ package com.google.cloud.bigquery.jdbc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException; @@ -32,7 +32,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BigQueryJdbcProxyUtilityTest { @Test diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java index 9b65719cbc..99a013ddd7 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java @@ -17,15 +17,15 @@ package com.google.cloud.bigquery.jdbc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException; import java.util.Collections; import java.util.Map; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BigQueryJdbcUrlUtilityTest { diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfPrimitivesTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfPrimitivesTest.java index 6f10ae79a0..2b79ade009 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfPrimitivesTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfPrimitivesTest.java @@ -36,7 +36,7 @@ import static java.time.Month.MARCH; import static java.util.Arrays.copyOfRange; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.Tuple; import com.google.cloud.bigquery.Field; @@ -61,44 +61,21 @@ import java.util.Collection; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.api.function.Executable; -@RunWith(Parameterized.class) -public class BigQueryJsonArrayOfPrimitivesTest { - private final Field schema; - private final FieldValue arrayValues; - private final Object[] expected; - private final int javaSqlTypeCode; - private Array array; - private final StandardSQLTypeName currentType; +public class BigQueryJsonArrayOfPrimitivesTest { - @ClassRule public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); + @RegisterExtension + public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); - public BigQueryJsonArrayOfPrimitivesTest( - StandardSQLTypeName currentType, - Tuple schemaAndValue, - Object[] expected, - int javaSqlTypeCode) { - this.currentType = currentType; - this.schema = schemaAndValue.x(); - this.arrayValues = schemaAndValue.y(); - this.expected = expected; - this.javaSqlTypeCode = javaSqlTypeCode; - } - @Before - public void setUp() { - array = new BigQueryJsonArray(this.schema, this.arrayValues); - } - @Parameters(name = "{index}: primitive array of {0}") + public static Collection data() { timeZoneRule.enforce(); LocalDateTime aTimeStamp = LocalDateTime.of(2023, MARCH, 30, 11, 14, 19, 820227000); @@ -229,48 +206,58 @@ public static Collection data() { }); } - @Test - public void getArray() throws SQLException { - assertThat(array.getArray()).isEqualTo(this.expected); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getArray(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); + assertThat(array.getArray()).isEqualTo(expected); } - @Test - public void getSlicedArray() throws SQLException { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedArray(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); int fromIndex = 1; int toIndexExclusive = 3; Object[] expectedSlicedArray = - copyOfRange(this.expected, fromIndex, toIndexExclusive); // copying index(1,2) + copyOfRange(expected, fromIndex, toIndexExclusive); // copying index(1,2) // the first element is at index 1 assertThat(array.getArray(fromIndex + 1, 2)).isEqualTo(expectedSlicedArray); } - @Test - public void getSlicedArrayWhenCountIsGreaterThanOriginalArrayLength() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedArrayWhenCountIsGreaterThanOriginalArrayLength(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class, () -> array.getArray(2, 10)); assertThat(illegalArgumentException.getMessage()) .isEqualTo("The array index is out of range: 12, number of elements: 4."); } - @Test - public void getResultSet() throws SQLException { - ResultSet resultSet = this.array.getResultSet(); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getResultSet(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); + ResultSet resultSet = array.getResultSet(); Tuple, ArrayList> indexAndValues = nestedResultSetToColumnLists(resultSet); ArrayList indexList = indexAndValues.x(); ArrayList columnValues = indexAndValues.y(); assertThat(indexList.toArray()).isEqualTo(new Object[] {1, 2, 3, 4}); - assertThat(columnValues.toArray()).isEqualTo(this.expected); + assertThat(columnValues.toArray()).isEqualTo(expected); } - @Test - public void getSlicedResultSet() throws SQLException { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedResultSet(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); int fromIndex = 1; int toIndexExclusive = 3; Object[] expectedSlicedArray = - copyOfRange(this.expected, fromIndex, toIndexExclusive); // copying index(1,2) + copyOfRange(expected, fromIndex, toIndexExclusive); // copying index(1,2) // the first element is at index 1 ResultSet resultSet = array.getResultSet(fromIndex + 1, 2); @@ -284,27 +271,35 @@ public void getSlicedResultSet() throws SQLException { assertThat(columnValues.toArray()).isEqualTo(expectedSlicedArray); } - @Test - public void getSlicedResultSetWhenCountIsGreaterThanOriginalArrayLength() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getSlicedResultSetWhenCountIsGreaterThanOriginalArrayLength(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class, () -> array.getResultSet(2, 10)); assertThat(illegalArgumentException.getMessage()) .isEqualTo("The array index is out of range: 12, number of elements: 4."); } - @Test - public void getBaseTypeName() throws SQLException { - assertThat(array.getBaseTypeName()).isEqualTo(this.currentType.name()); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getBaseTypeName(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); + assertThat(array.getBaseTypeName()).isEqualTo(currentType.name()); } - @Test - public void getBaseType() throws SQLException { - assertThat(array.getBaseType()).isEqualTo(this.javaSqlTypeCode); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getBaseType(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); + assertThat(array.getBaseType()).isEqualTo(javaSqlTypeCode); } - @Test - public void free() throws SQLException { - this.array.free(); + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void free(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) throws SQLException { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); + array.free(); ensureArrayIsInvalid(() -> array.getArray()); ensureArrayIsInvalid(() -> array.getArray(1, 2)); @@ -314,8 +309,10 @@ public void free() throws SQLException { ensureArrayIsInvalid(() -> array.getBaseType()); } - @Test - public void getArrayWithCustomTypeMappingsIsNotSupported() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getArrayWithCustomTypeMappingsIsNotSupported(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); Exception exception1 = assertThrows(SQLFeatureNotSupportedException.class, () -> array.getArray(emptyMap())); Exception exception2 = @@ -324,8 +321,10 @@ public void getArrayWithCustomTypeMappingsIsNotSupported() { assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED); } - @Test - public void getResultSetWithCustomTypeMappingsIsNotSupported() { + @ParameterizedTest(name = "{index}: primitive array of {0}") + @MethodSource("data") + public void getResultSetWithCustomTypeMappingsIsNotSupported(StandardSQLTypeName currentType, Tuple schemaAndValue, Object[] expected, int javaSqlTypeCode) { + Array array = new BigQueryJsonArray(schemaAndValue.x(), schemaAndValue.y()); Exception exception1 = assertThrows(SQLFeatureNotSupportedException.class, () -> array.getResultSet(emptyMap())); Exception exception2 = @@ -335,7 +334,7 @@ public void getResultSetWithCustomTypeMappingsIsNotSupported() { assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED); } - private void ensureArrayIsInvalid(ThrowingRunnable block) { + private void ensureArrayIsInvalid(Executable block) { Exception exception = assertThrows(IllegalStateException.class, block); assertThat(exception.getMessage()).isEqualTo(INVALID_ARRAY); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfStructTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfStructTest.java index b390d642e4..ea385aa071 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfStructTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonArrayOfStructTest.java @@ -24,7 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.Tuple; import com.google.cloud.bigquery.Field; @@ -42,16 +42,16 @@ import java.sql.Struct; import java.sql.Types; import java.util.ArrayList; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; public class BigQueryJsonArrayOfStructTest { private Array array; - @Before + @BeforeEach public void setUp() { FieldList profileSchema = FieldList.of( @@ -197,8 +197,8 @@ public void getArrayWithCustomTypeMappingsIsNotSupported() { assertThat(exception2.getMessage()).isEqualTo(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED); } - private void ensureArrayIsInvalid(ThrowingRunnable block) { - Exception exception = Assert.assertThrows(IllegalStateException.class, block); + private void ensureArrayIsInvalid(Executable block) { + Exception exception = Assertions.assertThrows(IllegalStateException.class, block); assertThat(exception.getMessage()).isEqualTo(INVALID_ARRAY); } } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonResultSetTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonResultSetTest.java index 4c715833ff..99dd042693 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonResultSetTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonResultSetTest.java @@ -54,13 +54,13 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.Test; public class BigQueryJsonResultSetTest { - @Rule public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); + @RegisterExtension public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); private static final FieldList fieldList = FieldList.of( @@ -151,7 +151,7 @@ public class BigQueryJsonResultSetTest { private BlockingQueue buffer; private BlockingQueue bufferWithTwoRows; - @Before + @BeforeEach public void setUp() { // Buffer with one row buffer = new LinkedBlockingDeque<>(2); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonStructTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonStructTest.java index f07d8cad27..815496786e 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonStructTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJsonStructTest.java @@ -38,7 +38,7 @@ import static java.time.Month.MARCH; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.Tuple; import com.google.cloud.bigquery.Field; @@ -65,18 +65,18 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.Test; public class BigQueryJsonStructTest { - @Rule public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); + @RegisterExtension public final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC"); private Struct structWithPrimitiveValues; private Struct structWithNullValue; - @Before + @BeforeEach public void setUp() { List> schemaAndValues = Arrays.asList( diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryParameterHandlerTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryParameterHandlerTest.java index 0dc085b602..961c59ecf7 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryParameterHandlerTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryParameterHandlerTest.java @@ -16,12 +16,12 @@ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import com.google.cloud.bigquery.StandardSQLTypeName; import com.google.cloud.bigquery.jdbc.BigQueryParameterHandler.BigQueryStatementParameterType; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BigQueryParameterHandlerTest { diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPooledConnectionTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPooledConnectionTest.java index a394e53d0d..f21dbcb5ef 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPooledConnectionTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPooledConnectionTest.java @@ -17,23 +17,23 @@ package com.google.cloud.bigquery.jdbc; import static com.google.cloud.bigquery.jdbc.utils.TestUtilities.TestConnectionListener; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import java.io.IOException; import java.sql.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryPooledConnectionTest { private BigQueryConnection bigQueryConnection; private static final Long LISTENER_POOL_SIZE = 10L; - @Before + @BeforeEach public void setUp() throws IOException, SQLException { bigQueryConnection = mock(BigQueryConnection.class); doReturn(LISTENER_POOL_SIZE).when(bigQueryConnection).getListenerPoolSize(); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetFinalizersTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetFinalizersTest.java index 7332dce936..ee4d6047b9 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetFinalizersTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetFinalizersTest.java @@ -18,14 +18,14 @@ import static com.google.common.truth.Truth.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryResultSetFinalizersTest { Thread arrowWorker; Thread[] jsonWorkers; - @Before + @BeforeEach public void setUp() { // create and start the demon threads arrowWorker = diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetMetadataTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetMetadataTest.java index b4d14296d1..ad8aef211c 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetMetadataTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryResultSetMetadataTest.java @@ -30,12 +30,13 @@ import java.sql.SQLException; import java.sql.Types; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -@RunWith(MockitoJUnitRunner.class) +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) public class BigQueryResultSetMetadataTest { private BigQueryStatement statement; @@ -106,7 +107,7 @@ public class BigQueryResultSetMetadataTest { private ResultSetMetaData resultSetMetaDataNested; - @Before + @BeforeEach public void setUp() throws SQLException { statement = mock(BigQueryStatement.class); Thread[] workerThreads = {new Thread()}; diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java index 22dc072192..f3971bd711 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java @@ -18,8 +18,8 @@ import static com.google.cloud.bigquery.jdbc.utils.ArrowUtilities.serializeSchema; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; @@ -65,9 +65,9 @@ import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.IntVector; import org.apache.arrow.vector.VectorSchemaRoot; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -124,7 +124,7 @@ private Job getJobMock( return job; } - @Before + @BeforeEach public void setUp() throws IOException, SQLException { bigQueryConnection = mock(BigQueryConnection.class); rpcFactoryMock = mock(BigQueryRpcFactory.class); @@ -181,7 +181,7 @@ public void testStatementNonNull() { assertThat(bigQueryStatement).isNotNull(); } - @Ignore + @Disabled public void testExecFastQueryPath() throws SQLException, InterruptedException { JobIdWrapper jobIdWrapper = new JobIdWrapper(jobId, null, null); BigQueryStatement bigQueryStatementSpy = Mockito.spy(bigQueryStatement); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryThreadFactoryTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryThreadFactoryTest.java index d271df0e26..db26cfd030 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryThreadFactoryTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryThreadFactoryTest.java @@ -19,14 +19,14 @@ import static com.google.common.truth.Truth.assertThat; import java.util.concurrent.ThreadFactory; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BigQueryThreadFactoryTest { private static ThreadFactory JDBC_THREAD_FACTORY; - @Before + @BeforeEach public void setUp() { JDBC_THREAD_FACTORY = new BigQueryThreadFactory("BigQuery-Thread-"); } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercerTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercerTest.java index a758cf15c0..9f92e19963 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercerTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercerTest.java @@ -17,7 +17,7 @@ package com.google.cloud.bigquery.jdbc; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.bigquery.exception.BigQueryJdbcCoercionException; import com.google.cloud.bigquery.exception.BigQueryJdbcCoercionNotFoundException; @@ -25,7 +25,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BigQueryTypeCoercerTest { diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/FieldValueTypeBigQueryCoercionUtilityTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/FieldValueTypeBigQueryCoercionUtilityTest.java index 456b750ca5..b5df1e1fc5 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/FieldValueTypeBigQueryCoercionUtilityTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/FieldValueTypeBigQueryCoercionUtilityTest.java @@ -22,7 +22,7 @@ import static com.google.cloud.bigquery.FieldValue.Attribute.REPEATED; import static com.google.cloud.bigquery.jdbc.BigQueryTypeCoercionUtility.INSTANCE; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.bigquery.FieldElementType; import com.google.cloud.bigquery.FieldValue; @@ -41,7 +41,7 @@ import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FieldValueTypeBigQueryCoercionUtilityTest { private static final FieldValue STRING_VALUE = FieldValue.of(PRIMITIVE, "sample-string"); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/NullHandlingTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/NullHandlingTest.java index ab274c8797..2bff0e17e2 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/NullHandlingTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/NullHandlingTest.java @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NullHandlingTest { diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionDataSourceTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionDataSourceTest.java index e3ef8a27f6..26e618ac86 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionDataSourceTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionDataSourceTest.java @@ -16,15 +16,15 @@ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import java.sql.SQLException; import javax.sql.PooledConnection; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PooledConnectionDataSourceTest { private static final Long LISTENER_POOL_SIZE = 20L; diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionListenerTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionListenerTest.java index 2d1553f655..8e88844359 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionListenerTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PooledConnectionListenerTest.java @@ -16,26 +16,26 @@ package com.google.cloud.bigquery.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class PooledConnectionListenerTest { private BigQueryConnection bigQueryConnection; private static final Long LISTENER_POOL_SIZE = 10L; private static final Long CONNECTION_POOL_SIZE = 10L; - @Before + @BeforeEach public void setUp() throws IOException, SQLException { bigQueryConnection = mock(BigQueryConnection.class); // Stub the listener pool size diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java index 22f5c1c763..e8e2d4853c 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java @@ -17,12 +17,12 @@ package com.google.cloud.bigquery.jdbc.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.BigQuery; @@ -78,11 +78,11 @@ import java.util.concurrent.Executors; import java.util.function.BiFunction; import javax.sql.PooledConnection; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class ITBigQueryJDBCTest extends ITBase { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); @@ -126,9 +126,7 @@ public class ITBigQueryJDBCTest extends ITBase { private static String requireEnvVar(String varName) { String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); + assertNotNull(System.getenv(varName), "Environment variable " + varName + " is required to perform these tests."); return value; } @@ -167,7 +165,7 @@ private void validateConnection(String connection_uri) throws SQLException { connection.close(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws SQLException { bigQueryConnection = DriverManager.getConnection(connection_uri, new Properties()); bigQueryStatement = bigQueryConnection.createStatement(); @@ -179,7 +177,7 @@ public static void beforeClass() throws SQLException { bigQuery = BigQueryOptions.newBuilder().build().getService(); } - @AfterClass + @AfterAll public static void afterClass() throws SQLException { bigQueryStatement.close(); bigQueryConnection.close(); @@ -216,7 +214,7 @@ public void testServiceAccountAuthenticationMissingOAuthPvtKeyPath() throws SQLE try { DriverManager.getConnection(connection_uri); - Assert.fail(); + Assertions.fail(); } catch (BigQueryJdbcRuntimeException ex) { assertTrue(ex.getMessage().contains("No valid credentials provided.")); } @@ -279,7 +277,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsJson() // TODO(kirl): Enable this test when pipeline has p12 secret available. @Test - @Ignore + @Disabled public void testValidServiceAccountAuthenticationP12() throws SQLException, IOException { final JsonObject authJson = getAuthJson(); final String p12_file = requireEnvVar("SA_SECRET_P12"); @@ -293,7 +291,7 @@ public void testValidServiceAccountAuthenticationP12() throws SQLException, IOEx } @Test - @Ignore + @Disabled public void testValidGoogleUserAccountAuthentication() throws SQLException { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" @@ -317,7 +315,7 @@ public void testValidGoogleUserAccountAuthentication() throws SQLException { } @Test - @Ignore + @Disabled public void testValidExternalAccountAuthentication() throws SQLException { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" @@ -344,7 +342,7 @@ public void testValidExternalAccountAuthentication() throws SQLException { } @Test - @Ignore + @Disabled public void testValidExternalAccountAuthenticationFromFile() throws SQLException { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" @@ -369,7 +367,7 @@ public void testValidExternalAccountAuthenticationFromFile() throws SQLException } @Test - @Ignore + @Disabled public void testValidExternalAccountAuthenticationRawJson() throws SQLException { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" @@ -405,7 +403,7 @@ public void testValidExternalAccountAuthenticationRawJson() throws SQLException // TODO(farhan): figure out how to programmatically generate an access token and test @Test - @Ignore + @Disabled public void testValidPreGeneratedAccessTokenAuthentication() throws SQLException { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" @@ -430,7 +428,7 @@ public void testValidPreGeneratedAccessTokenAuthentication() throws SQLException // TODO(obada): figure out how to programmatically generate a refresh token and test @Test - @Ignore + @Disabled public void testValidRefreshTokenAuthentication() throws SQLException { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" @@ -550,7 +548,7 @@ public void testInvalidQuery() throws SQLException { try { bigQueryStatement.executeQuery(query); - Assert.fail(); + Assertions.fail(); } catch (BigQueryJdbcException e) { assertTrue(e.getMessage().contains("SELECT * must have a FROM clause")); } @@ -1901,16 +1899,16 @@ public void testTableConstraints() throws SQLException { public void testDatabaseMetadataGetCatalogs() throws SQLException { DatabaseMetaData databaseMetaData = bigQueryConnection.getMetaData(); try (ResultSet rs = databaseMetaData.getCatalogs()) { - assertNotNull("ResultSet from getCatalogs() should not be null", rs); + assertNotNull(rs, "ResultSet from getCatalogs() should not be null"); ResultSetMetaData rsmd = rs.getMetaData(); - assertNotNull("ResultSetMetaData should not be null", rsmd); - assertEquals("Should have one column", 1, rsmd.getColumnCount()); - assertEquals("Column name should be TABLE_CAT", "TABLE_CAT", rsmd.getColumnName(1)); + assertNotNull(rsmd, "ResultSetMetaData should not be null"); + assertEquals(1, rsmd.getColumnCount(), "Should have one column"); + assertEquals("TABLE_CAT", rsmd.getColumnName(1), "Column name should be TABLE_CAT"); - assertTrue("ResultSet should have one row", rs.next()); - assertEquals("Catalog name should match Project ID", PROJECT_ID, rs.getString("TABLE_CAT")); - assertFalse("ResultSet should have no more rows", rs.next()); + assertTrue(rs.next(), "ResultSet should have one row"); + assertEquals(PROJECT_ID, rs.getString("TABLE_CAT"), "Catalog name should match Project ID"); + assertFalse(rs.next(), "ResultSet should have no more rows"); } } @@ -1956,9 +1954,9 @@ public void testDatabaseMetadataGetProcedureColumns() throws SQLException { assertEquals(2, resultSet.getInt("ORDINAL_POSITION")); } } - assertEquals("Should find 2 parameters for " + specificProcedure, 2, specificProcRows); - assertTrue("Parameter 'name' should be found", foundNameParam); - assertTrue("Parameter 'id' should be found", foundIdParam); + assertEquals(2, specificProcRows, "Should find 2 parameters for " + specificProcedure); + assertTrue(foundNameParam, "Parameter 'name' should be found"); + assertTrue(foundIdParam, "Parameter 'id' should be found"); resultSet.close(); // --- Test Case 2: Specific schema, procedure, and column name pattern --- @@ -1966,7 +1964,7 @@ public void testDatabaseMetadataGetProcedureColumns() throws SQLException { resultSet = databaseMetaData.getProcedureColumns( PROJECT_ID, specificSchema, specificProcedure, specificColumn); - assertTrue("Should find the specific column 'name'", resultSet.next()); + assertTrue(resultSet.next(), "Should find the specific column 'name'"); assertEquals(PROJECT_ID, resultSet.getString("PROCEDURE_CAT")); assertEquals(specificSchema, resultSet.getString("PROCEDURE_SCHEM")); assertEquals(specificProcedure, resultSet.getString("PROCEDURE_NAME")); @@ -1976,14 +1974,14 @@ public void testDatabaseMetadataGetProcedureColumns() throws SQLException { (short) DatabaseMetaData.procedureColumnUnknown, resultSet.getShort("COLUMN_TYPE")); assertEquals(java.sql.Types.NVARCHAR, resultSet.getInt("DATA_TYPE")); assertEquals("NVARCHAR", resultSet.getString("TYPE_NAME")); - assertFalse("Should only find one row for exact column match", resultSet.next()); + assertFalse(resultSet.next(), "Should only find one row for exact column match"); resultSet.close(); // --- Test Case 3: Non-existent procedure --- resultSet = databaseMetaData.getProcedureColumns( PROJECT_ID, specificSchema, "non_existent_procedure_xyz", null); - assertFalse("Should not find columns for a non-existent procedure", resultSet.next()); + assertFalse(resultSet.next(), "Should not find columns for a non-existent procedure"); resultSet.close(); } @@ -2311,21 +2309,18 @@ public void testDatabaseMetadataGetSchemas() throws SQLException { public void testDatabaseMetadataGetSchemasNoArgs() throws SQLException { DatabaseMetaData databaseMetaData = bigQueryConnection.getMetaData(); String expectedCatalog = bigQueryConnection.getCatalog(); - assertNotNull("Project ID (catalog) from connection should not be null", expectedCatalog); + assertNotNull(expectedCatalog, "Project ID (catalog) from connection should not be null"); // Test case: Get all schemas (datasets) for the current project try (ResultSet rsAll = databaseMetaData.getSchemas()) { - assertNotNull("ResultSet from getSchemas() should not be null", rsAll); + assertNotNull(rsAll, "ResultSet from getSchemas() should not be null"); boolean foundTestDataset = false; int rowCount = 0; while (rsAll.next()) { rowCount++; - assertEquals( - "TABLE_CATALOG should match the connection's project ID", - expectedCatalog, - rsAll.getString("TABLE_CATALOG")); + assertEquals(expectedCatalog, rsAll.getString("TABLE_CATALOG"), "TABLE_CATALOG should match the connection's project ID"); String schemaName = rsAll.getString("TABLE_SCHEM"); - assertNotNull("TABLE_SCHEM should not be null", schemaName); + assertNotNull(schemaName, "TABLE_SCHEM should not be null"); if (DATASET.equals(schemaName) || DATASET2.equals(schemaName) || CONSTRAINTS_DATASET.equals(schemaName) @@ -2334,8 +2329,8 @@ public void testDatabaseMetadataGetSchemasNoArgs() throws SQLException { foundTestDataset = true; } } - assertTrue("At least one of the known test datasets should be found", foundTestDataset); - assertTrue("Should retrieve at least one schema/dataset", rowCount > 0); + assertTrue(foundTestDataset, "At least one of the known test datasets should be found"); + assertTrue(rowCount > 0, "Should retrieve at least one schema/dataset"); } } @@ -2368,9 +2363,9 @@ public void testDatabaseMetaDataGetFunctions() throws SQLException { assertEquals(funcName, rsAll.getString("SPECIFIC_NAME")); } assertEquals( - "Should find all " + expectedFunctionNames.size() + " functions in " + testSchema, expectedFunctionNames.size(), - countAll); + countAll, + "Should find all " + expectedFunctionNames.size() + " functions in " + testSchema); assertEquals(expectedFunctionNames, foundFunctionNames); rsAll.close(); @@ -2378,65 +2373,63 @@ public void testDatabaseMetaDataGetFunctions() throws SQLException { String specificFunctionName = "scalar_sql_udf"; ResultSet rsSpecific = databaseMetaData.getFunctions(testCatalog, testSchema, specificFunctionName); - assertTrue("Should find the specific function " + specificFunctionName, rsSpecific.next()); + assertTrue(rsSpecific.next(), "Should find the specific function " + specificFunctionName); assertEquals(testCatalog, rsSpecific.getString("FUNCTION_CAT")); assertEquals(testSchema, rsSpecific.getString("FUNCTION_SCHEM")); assertEquals(specificFunctionName, rsSpecific.getString("FUNCTION_NAME")); assertNull(rsSpecific.getString("REMARKS")); assertEquals(DatabaseMetaData.functionResultUnknown, rsSpecific.getShort("FUNCTION_TYPE")); assertEquals(specificFunctionName, rsSpecific.getString("SPECIFIC_NAME")); - assertFalse("Should only find one row for exact function match", rsSpecific.next()); + assertFalse(rsSpecific.next(), "Should only find one row for exact function match"); rsSpecific.close(); // Test 3: Get functions using a wildcard functionNamePattern "scalar%" // Expected order due to sorting: scalar_js_udf, scalar_sql_udf ResultSet rsWildcard = databaseMetaData.getFunctions(testCatalog, testSchema, "scalar%"); - assertTrue("Should find functions matching 'scalar%'", rsWildcard.next()); + assertTrue(rsWildcard.next(), "Should find functions matching 'scalar%'"); assertEquals("scalar_js_udf", rsWildcard.getString("FUNCTION_NAME")); assertEquals(DatabaseMetaData.functionResultUnknown, rsWildcard.getShort("FUNCTION_TYPE")); - assertTrue("Should find the second function matching 'scalar%'", rsWildcard.next()); + assertTrue(rsWildcard.next(), "Should find the second function matching 'scalar%'"); assertEquals("scalar_sql_udf", rsWildcard.getString("FUNCTION_NAME")); assertEquals(DatabaseMetaData.functionResultUnknown, rsWildcard.getShort("FUNCTION_TYPE")); - assertFalse("Should be no more functions matching 'scalar%'", rsWildcard.next()); + assertFalse(rsWildcard.next(), "Should be no more functions matching 'scalar%'"); rsWildcard.close(); // Test 4: Schema pattern with wildcard ResultSet rsSchemaWildcard = databaseMetaData.getFunctions(testCatalog, "JDBC_TABLE_TYPES_T%", "complex_scalar_sql_udf"); - assertTrue("Should find function with schema wildcard", rsSchemaWildcard.next()); + assertTrue(rsSchemaWildcard.next(), "Should find function with schema wildcard"); assertEquals(testSchema, rsSchemaWildcard.getString("FUNCTION_SCHEM")); assertEquals("complex_scalar_sql_udf", rsSchemaWildcard.getString("FUNCTION_NAME")); - assertFalse( - "Should only find one row for this schema wildcard and specific function", - rsSchemaWildcard.next()); + assertFalse(rsSchemaWildcard.next(), "Should only find one row for this schema wildcard and specific function"); rsSchemaWildcard.close(); // Test 5: Non-existent function ResultSet rsNonExistentFunc = databaseMetaData.getFunctions(testCatalog, testSchema, "non_existent_function_xyz123"); - assertFalse("Should not find a non-existent function", rsNonExistentFunc.next()); + assertFalse(rsNonExistentFunc.next(), "Should not find a non-existent function"); rsNonExistentFunc.close(); // Test 6: Non-existent schema ResultSet rsNonExistentSchema = databaseMetaData.getFunctions(testCatalog, "NON_EXISTENT_SCHEMA_XYZ123", null); - assertFalse("Should not find functions in a non-existent schema", rsNonExistentSchema.next()); + assertFalse(rsNonExistentSchema.next(), "Should not find functions in a non-existent schema"); rsNonExistentSchema.close(); // Test 7: Empty schema pattern ResultSet rsEmptySchema = databaseMetaData.getFunctions(testCatalog, "", null); - assertFalse("Empty schema pattern should return no results", rsEmptySchema.next()); + assertFalse(rsEmptySchema.next(), "Empty schema pattern should return no results"); rsEmptySchema.close(); // Test 8: Empty function name pattern ResultSet rsEmptyFunction = databaseMetaData.getFunctions(testCatalog, testSchema, ""); - assertFalse("Empty function name pattern should return no results", rsEmptyFunction.next()); + assertFalse(rsEmptyFunction.next(), "Empty function name pattern should return no results"); rsEmptyFunction.close(); // Test 9: Null catalog ResultSet rsNullCatalog = databaseMetaData.getFunctions(null, testSchema, null); - assertFalse("Null catalog should return no results", rsNullCatalog.next()); + assertFalse(rsNullCatalog.next(), "Null catalog should return no results"); rsNullCatalog.close(); } @@ -2453,7 +2446,7 @@ public void testDatabaseMetadataGetFunctionColumns() throws SQLException { databaseMetaData.getFunctionColumns( testCatalog, testSchema, specificFunction1, specificColumn1); - assertTrue("Should find column 'x' for function 'scalar_sql_udf'", rs.next()); + assertTrue(rs.next(), "Should find column 'x' for function 'scalar_sql_udf'"); assertEquals(testCatalog, rs.getString("FUNCTION_CAT")); assertEquals(testSchema, rs.getString("FUNCTION_SCHEM")); assertEquals(specificFunction1, rs.getString("FUNCTION_NAME")); @@ -2473,7 +2466,7 @@ public void testDatabaseMetadataGetFunctionColumns() throws SQLException { assertEquals(1, rs.getInt("ORDINAL_POSITION")); assertEquals("", rs.getString("IS_NULLABLE")); assertEquals(specificFunction1, rs.getString("SPECIFIC_NAME")); - assertFalse("Should only find one row for exact column match", rs.next()); + assertFalse(rs.next(), "Should only find one row for exact column match"); rs.close(); // Test Case 2: Specific function 'complex_scalar_sql_udf', specific column 'arr' @@ -2482,7 +2475,7 @@ public void testDatabaseMetadataGetFunctionColumns() throws SQLException { rs = databaseMetaData.getFunctionColumns( testCatalog, testSchema, specificFunction2, specificColumn2); - assertTrue("Should find column 'arr' for function 'complex_scalar_sql_udf'", rs.next()); + assertTrue(rs.next(), "Should find column 'arr' for function 'complex_scalar_sql_udf'"); assertEquals(testCatalog, rs.getString("FUNCTION_CAT")); assertEquals(testSchema, rs.getString("FUNCTION_SCHEM")); assertEquals(specificFunction2, rs.getString("FUNCTION_NAME")); @@ -2505,13 +2498,13 @@ public void testDatabaseMetadataGetFunctionColumns() throws SQLException { assertEquals(1, rs.getInt("ORDINAL_POSITION")); assertEquals("", rs.getString("IS_NULLABLE")); assertEquals(specificFunction2, rs.getString("SPECIFIC_NAME")); - assertFalse("Should only find one row for exact column match", rs.next()); + assertFalse(rs.next(), "Should only find one row for exact column match"); rs.close(); // Test Case 3: All columns for 'persistent_sql_udf_named_params' (sorted by ordinal position) String specificFunction3 = "persistent_sql_udf_named_params"; rs = databaseMetaData.getFunctionColumns(testCatalog, testSchema, specificFunction3, null); - assertTrue("Should find columns for " + specificFunction3, rs.next()); + assertTrue(rs.next(), "Should find columns for " + specificFunction3); assertEquals(specificFunction3, rs.getString("FUNCTION_NAME")); assertEquals("value1", rs.getString("COLUMN_NAME")); // Ordinal Position 1 assertEquals(DatabaseMetaData.functionColumnUnknown, rs.getShort("COLUMN_TYPE")); @@ -2519,45 +2512,45 @@ public void testDatabaseMetadataGetFunctionColumns() throws SQLException { assertEquals("BIGINT", rs.getString("TYPE_NAME")); assertEquals(1, rs.getInt("ORDINAL_POSITION")); - assertTrue("Should find second column for " + specificFunction3, rs.next()); + assertTrue(rs.next(), "Should find second column for " + specificFunction3); assertEquals(specificFunction3, rs.getString("FUNCTION_NAME")); assertEquals("value-two", rs.getString("COLUMN_NAME")); // Ordinal Position 2 assertEquals(DatabaseMetaData.functionColumnUnknown, rs.getShort("COLUMN_TYPE")); assertEquals(Types.NVARCHAR, rs.getInt("DATA_TYPE")); assertEquals("NVARCHAR", rs.getString("TYPE_NAME")); assertEquals(2, rs.getInt("ORDINAL_POSITION")); - assertFalse("Should be no more columns for " + specificFunction3, rs.next()); + assertFalse(rs.next(), "Should be no more columns for " + specificFunction3); rs.close(); // Test Case 4: Wildcard for function name "scalar%", specific column name "x" rs = databaseMetaData.getFunctionColumns(testCatalog, testSchema, "scalar%", "x"); - assertTrue("Should find column 'x' for functions matching 'scalar%'", rs.next()); + assertTrue(rs.next(), "Should find column 'x' for functions matching 'scalar%'"); assertEquals("scalar_sql_udf", rs.getString("FUNCTION_NAME")); assertEquals("x", rs.getString("COLUMN_NAME")); assertEquals(1, rs.getInt("ORDINAL_POSITION")); - assertFalse("Should be no more columns named 'x' for functions matching 'scalar%'", rs.next()); + assertFalse(rs.next(), "Should be no more columns named 'x' for functions matching 'scalar%'"); rs.close(); // Test Case 5: Wildcard for column name "%" for 'scalar_js_udf' String specificFunction4 = "scalar_js_udf"; rs = databaseMetaData.getFunctionColumns(testCatalog, testSchema, specificFunction4, "%"); - assertTrue("Should find columns for " + specificFunction4 + " with wildcard", rs.next()); + assertTrue(rs.next(), "Should find columns for " + specificFunction4 + " with wildcard"); assertEquals(specificFunction4, rs.getString("FUNCTION_NAME")); assertEquals("name", rs.getString("COLUMN_NAME")); // Ordinal Position 1 assertEquals(1, rs.getInt("ORDINAL_POSITION")); - assertTrue("Should find second column for " + specificFunction4 + " with wildcard", rs.next()); + assertTrue(rs.next(), "Should find second column for " + specificFunction4 + " with wildcard"); assertEquals(specificFunction4, rs.getString("FUNCTION_NAME")); assertEquals("age", rs.getString("COLUMN_NAME")); // Ordinal Position 2 assertEquals(2, rs.getInt("ORDINAL_POSITION")); - assertFalse("Should be no more columns for " + specificFunction4 + " with wildcard", rs.next()); + assertFalse(rs.next(), "Should be no more columns for " + specificFunction4 + " with wildcard"); rs.close(); // Test Case 6: Non-existent function rs = databaseMetaData.getFunctionColumns( testCatalog, testSchema, "non_existent_function_xyz", null); - assertFalse("Should not find columns for a non-existent function", rs.next()); + assertFalse(rs.next(), "Should not find columns for a non-existent function"); rs.close(); } @@ -3354,12 +3347,8 @@ public void testAdditionalProjectsInMetadata() throws SQLException { foundCatalogs.add(catalogsRs.getString("TABLE_CAT")); } } - assertTrue( - "getCatalogs() should contain the primary project ID", - foundCatalogs.contains(PROJECT_ID)); - assertTrue( - "getCatalogs() should contain the additional project ID", - foundCatalogs.contains(additionalProjectsValue)); + assertTrue(foundCatalogs.contains(PROJECT_ID), "getCatalogs() should contain the primary project ID"); + assertTrue(foundCatalogs.contains(additionalProjectsValue), "getCatalogs() should contain the additional project ID"); // 2. Test getSchemas() Set catalogsForSchemasFromAll = new HashSet<>(); @@ -3375,15 +3364,9 @@ public void testAdditionalProjectsInMetadata() throws SQLException { } } } - assertTrue( - "getSchemas() should list datasets from the primary project", - catalogsForSchemasFromAll.contains(PROJECT_ID)); - assertTrue( - "getSchemas() should list datasets from the additional project", - catalogsForSchemasFromAll.contains(additionalProjectsValue)); - assertTrue( - "Known dataset from additional project not found in getSchemas()", - foundAdditionalDataset); + assertTrue(catalogsForSchemasFromAll.contains(PROJECT_ID), "getSchemas() should list datasets from the primary project"); + assertTrue(catalogsForSchemasFromAll.contains(additionalProjectsValue), "getSchemas() should list datasets from the additional project"); + assertTrue(foundAdditionalDataset, "Known dataset from additional project not found in getSchemas()"); } catch (SQLException e) { System.err.println("SQL Error during AdditionalProjects test: " + e.getMessage()); @@ -4136,15 +4119,15 @@ private void validate( if (expectedResult.containsKey(columnName)) { Object expectedValue = expectedResult.get(columnName); - assertEquals(regularApiLabel, expectedValue, getter.apply(resultSetRegular, i)); - assertEquals(htapiApiLabel, expectedValue, getter.apply(resultSetArrow, i)); + assertEquals(expectedValue, getter.apply(resultSetRegular, i), regularApiLabel); + assertEquals(expectedValue, getter.apply(resultSetArrow, i), htapiApiLabel); } else { String regularMsg = "Expected exception but got a value. " + regularApiLabel; - assertEquals(regularMsg, EXCEPTION_REPLACEMENT, getter.apply(resultSetRegular, i)); + assertEquals(EXCEPTION_REPLACEMENT, getter.apply(resultSetRegular, i), regularMsg); String htapiMsg = "Expected exception but got a value. " + htapiApiLabel; - assertEquals(htapiMsg, EXCEPTION_REPLACEMENT, getter.apply(resultSetArrow, i)); + assertEquals(EXCEPTION_REPLACEMENT, getter.apply(resultSetArrow, i), htapiMsg); } } } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java index 30124b4a04..32239c21f8 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java @@ -18,12 +18,12 @@ import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.BigQuery; @@ -52,9 +52,9 @@ import java.util.Properties; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class ITNightlyBigQueryTest { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); @@ -91,14 +91,14 @@ public class ITNightlyBigQueryTest { + PROJECT_ID + ";OAUTHTYPE=3"; - @BeforeClass + @BeforeAll public static void beforeClass() throws SQLException { bigQueryConnection = DriverManager.getConnection(connection_uri, new Properties()); bigQueryStatement = bigQueryConnection.createStatement(); bigQuery = BigQueryOptions.newBuilder().build().getService(); } - @AfterClass + @AfterAll public static void afterClass() throws SQLException { bigQueryStatement.close(); bigQueryConnection.close(); @@ -793,9 +793,7 @@ public void testMultiStatementTransactionRollbackByUser() throws SQLException { status = statement.execute(selectQuery); assertTrue(status); connection.rollback(); - assertTrue( - "After rollback() in manual commit mode, a new transaction should be started.", - connection.isTransactionStarted()); + assertTrue(connection.isTransactionStarted(), "After rollback() in manual commit mode, a new transaction should be started."); // Separate query to check if transaction rollback worked ResultSet resultSet = bigQueryStatement.executeQuery(selectQuery); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java index 1b73f84b66..b6c73b3256 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITPSCBigQueryTest.java @@ -18,12 +18,12 @@ import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.BigQueryException; @@ -41,7 +41,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ITPSCBigQueryTest { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); @@ -49,9 +49,7 @@ public class ITPSCBigQueryTest { private static String requireEnvVar(String varName) { String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); + assertNotNull(System.getenv(varName), "Environment variable " + varName + " is required to perform these tests."); return value; } diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java index fbde5ecc67..2167bdbaaf 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITProxyBigQueryTest.java @@ -16,10 +16,10 @@ package com.google.cloud.bigquery.jdbc.it; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.exception.BigQueryJdbcException; @@ -29,13 +29,12 @@ import java.sql.Statement; import java.util.Arrays; import java.util.List; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Enclosed.class) +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class ITProxyBigQueryTest { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); static final String PROXY_HOST = "34.94.167.18"; @@ -43,7 +42,8 @@ public class ITProxyBigQueryTest { static final String PROXY_UID = "fahmz"; static final String PROXY_PWD = "fahmz"; - public static class NonParameterizedProxyTests { + @Nested + public class NonParameterizedProxyTests { @Test public void testValidAuthenticatedProxy() throws SQLException { String connection_uri = @@ -111,7 +111,7 @@ public void testNonExistingProxyTimesOut() throws SQLException { } @Test - @Ignore // Run this when Proxy server has no authentication otherwise you'll get a "407 Proxy + @Disabled // Run this when Proxy server has no authentication otherwise you'll get a "407 Proxy // Authentication Required". public void testNonAuthenticatedProxy() throws SQLException { String connection_uri = @@ -185,23 +185,11 @@ public void testReadAPIEnabledWithProxySettings() throws SQLException { } } - @RunWith(Parameterized.class) - public static class ParametrizedMissingPropertiesTest { - private final String ProxyHost; - private final String ProxyPort; - private final String ProxyUid; - private final String ProxyPwd; - - public ParametrizedMissingPropertiesTest( - String ProxyHost, String ProxyPort, String ProxyUid, String ProxyPwd) { - this.ProxyHost = ProxyHost; - this.ProxyPort = ProxyPort; - this.ProxyUid = ProxyUid; - this.ProxyPwd = ProxyPwd; - } + @Nested + @TestInstance(TestInstance.Lifecycle.PER_CLASS) + public class ParametrizedMissingPropertiesTest { - @Parameterized.Parameters - public static List ProxyParameters() { + public List ProxyParameters() { String proxyHost = "ProxyHost=" + PROXY_HOST + ";"; String proxyPort = "ProxyPort=" + PROXY_PORT + ";"; String proxyUid = "ProxyUid=" + PROXY_UID + ";"; @@ -216,8 +204,9 @@ public static List ProxyParameters() { }); } - @Test - public void testMissingProxyParameterThrowsIllegalArgument() { + @ParameterizedTest + @MethodSource("ProxyParameters") + public void testMissingProxyParameterThrowsIllegalArgument(String ProxyHost, String ProxyPort, String ProxyUid, String ProxyPwd) { String connection_uri = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + "ProjectId=" diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITTPCBigQueryTest.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITTPCBigQueryTest.java index 3fa2d7d7e4..32bddb0019 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITTPCBigQueryTest.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITTPCBigQueryTest.java @@ -16,10 +16,10 @@ package com.google.cloud.bigquery.jdbc.it; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.bigquery.jdbc.BigQueryConnection; import java.sql.Connection; @@ -27,7 +27,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ITTPCBigQueryTest { private static final String ENDPOINT_URL = System.getenv("ENDPOINT_URL"); diff --git a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/rules/TimeZoneRule.java b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/rules/TimeZoneRule.java index ff5db108e8..92b8fb1ea3 100644 --- a/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/rules/TimeZoneRule.java +++ b/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/rules/TimeZoneRule.java @@ -17,39 +17,49 @@ package com.google.cloud.bigquery.jdbc.rules; import java.util.TimeZone; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; -public class TimeZoneRule implements TestRule { +public class TimeZoneRule implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback { private final String timeZoneId; - private final TimeZone defaultTimeZone; + private TimeZone defaultTimeZone; public TimeZoneRule(String timeZoneId) { this.timeZoneId = timeZoneId; + } + + @Override + public void beforeAll(ExtensionContext context) { defaultTimeZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId)); + } + + @Override + public void afterAll(ExtensionContext context) { + TimeZone.setDefault(defaultTimeZone); + } + + @Override + public void beforeEach(ExtensionContext context) { + if (defaultTimeZone == null) { + defaultTimeZone = TimeZone.getDefault(); + } + TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId)); } @Override - public Statement apply(Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - try { - TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId)); - base.evaluate(); - } finally { - TimeZone.setDefault(defaultTimeZone); - } - } - }; + public void afterEach(ExtensionContext context) { + if (defaultTimeZone != null) { + TimeZone.setDefault(defaultTimeZone); + } } /** - * Public method to enforce the rule from places like methods annotated with {@link - * org.junit.runners.Parameterized.Parameters} annotation which gets executed before this rule is - * applied. + * Public method to enforce the rule manually */ public void enforce() { TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId));