Commit ebde3bb
authored
test(bigquery-jdbc): add unit tests for constraint metadata methods (#13719)
b/532929906
This PR introduces unit testing for the 4 recently migrated constraint
metadata methods (`getPrimaryKeys`, `getImportedKeys`,
`getExportedKeys`, and `getCrossReference`) in
`BigQueryDatabaseMetaDataTest`, alongside some important test
infrastructure hardening.
**Key Changes:**
* **Exhaustive Constraint Unit Tests:** Added 8 granular test methods
covering both the "happy path" (`_hasKeys`) and empty state (`_noKeys`)
for every metadata endpoint, ensuring BigQuery's `TableConstraints`
structure is properly translated into JDBC standard formats
(`PKTABLE_NAME`, `KEY_SEQ`, etc.) without relying on slow integration
tests.
* **Mockito Helpers:** Extracted repetitive dataset pagination and
`TableDefinition` setup into clean helper methods
(`mockDatasetIteration`, `mockTableWithConstraints`).
* **Robust Varargs Mocking:** Fixed fragile Mockito setups across the
file by migrating 13 occurrences of `any(BigQuery.*ListOption.class)` to
array matchers (`any(BigQuery.*ListOption[].class)`). This prevents
spontaneous `NullPointerException`s if production code alters the number
of varargs it passes.
* **Resource Leak Prevention:** Identified and retrofitted 13 newer test
methods to properly manage `ResultSet` lifecycles using
`try-with-resources`, ensuring no `AutoCloseable` resources are leaked
during test execution.1 parent 11f26d3 commit ebde3bb
1 file changed
Lines changed: 330 additions & 60 deletions
File tree
- java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc
0 commit comments