Skip to content

chore(bq jdbc): migrate to junit5#12079

Merged
logachev merged 1 commit intomainfrom
kirl/junit5-migration2
Mar 17, 2026
Merged

chore(bq jdbc): migrate to junit5#12079
logachev merged 1 commit intomainfrom
kirl/junit5-migration2

Conversation

@logachev
Copy link
Copy Markdown
Contributor

No description provided.

@logachev logachev requested review from a team as code owners March 13, 2026 18:56
@logachev logachev merged commit b1c6fad into main Mar 17, 2026
54 checks passed
@logachev logachev deleted the kirl/junit5-migration2 branch March 17, 2026 03:08
@logachev
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request migrates the google-cloud-bigquery-jdbc module's test suite from JUnit 4 to JUnit 5. This involves updating pom.xml to replace JUnit 4 dependencies with JUnit 5 Jupiter dependencies and Mockito's JUnit 5 extension. Test classes were refactored to use JUnit 5 annotations such as @Test, @BeforeEach, @AfterAll, @BeforeAll, @ParameterizedTest, @MethodSource, @RegisterExtension, @ExtendWith, @Nested, @TestInstance, and Assertions for assertions, replacing their JUnit 4 counterparts. Additionally, the TimeZoneRule was adapted to implement JUnit 5 extension interfaces.

Comment on lines +65 to +68
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The migration from JUnit 4's @RunWith(Parameterized.class) and @Parameters to JUnit 5's @ParameterizedTest and @MethodSource is correctly implemented. This improves test flexibility and readability.

Comment on lines +228 to +237
@ParameterizedTest(name = "{index}: primitive array of {0}")
@MethodSource("data")
public void getArray(
StandardSQLTypeName currentType,
Tuple<Field, JsonStringArrayList<?>> schemaAndValue,
Object[] expected,
int javaSqlTypeCode)
throws SQLException {
Array array = new BigQueryArrowArray(schemaAndValue.x(), schemaAndValue.y());
assertThat(array.getArray()).isEqualTo(expected);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test method getArray has been correctly refactored to use @ParameterizedTest and receive its data from the data() method. Instantiating Array array inside the test method ensures proper test isolation for each parameter set.

Comment on lines +40 to 44
@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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test method stringToBoolean has been correctly refactored to use @ParameterizedTest and receive its data from the data() method. This ensures proper test isolation for each parameter set.

import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class BigQueryArrowArrayOfPrimitivesTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Removing the @RunWith(Parameterized.class) annotation is a necessary step for JUnit 5 migration.

private final int javaSqlTypeCode;
private Array array;
private final StandardSQLTypeName currentType;
@RegisterExtension public static final TimeZoneRule timeZoneRule = new TimeZoneRule("UTC");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Migrating from @ClassRule to @RegisterExtension for static rules is the correct approach in JUnit 5.

import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class BigQueryDefaultCoercionsTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Removing the @RunWith(Parameterized.class) annotation is a necessary step for JUnit 5 migration.

Comment on lines +37 to +40
public void beforeAll(ExtensionContext context) {
defaultTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The beforeAll method correctly sets the default time zone for all tests in the class, storing the original time zone to restore it later.

}

@Override
public void afterAll(ExtensionContext context) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The afterAll method correctly restores the original default time zone after all tests in the class have run.

Comment on lines +48 to +52
public void beforeEach(ExtensionContext context) {
if (defaultTimeZone == null) {
defaultTimeZone = TimeZone.getDefault();
}
TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The beforeEach method correctly sets the default time zone before each test method, ensuring test isolation regarding time zone settings.

Comment on lines 55 to +59
@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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The afterEach method correctly restores the original default time zone after each test method, ensuring test isolation regarding time zone settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants