From a03b29522b685dafa7860c4cb11f19b4cf2c0ac7 Mon Sep 17 00:00:00 2001 From: Jin Seop Kim Date: Fri, 3 Apr 2026 17:11:05 -0400 Subject: [PATCH] test(bigquery): Fix flaky ITBigQueryTest#testProjectIDFastSQLQueryWithJobId This PR fixes a flaky integration test by replacing a strict string assertion on a backend error message with a more robust assertion on the HTTP status code (400 Bad Request). It also refactors the test to use JUnit's \`assertThrows\` for cleaner and more idiomatic exception testing, automatically preventing false positives if the exception isn't thrown. Fixes https://github.com/googleapis/google-cloud-java/issues/12135 --- .../com/google/cloud/bigquery/it/ITBigQueryTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 439e401d374b..25b90dc942ee 100644 --- a/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -4698,13 +4698,10 @@ void testProjectIDFastSQLQueryWithJobId() { JobId jobIdWithProjectId = JobId.newBuilder().setProject(invalidProjectId).build(); QueryJobConfiguration configSelect = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); - try { - bigquery.query(configSelect, jobIdWithProjectId); - } catch (Exception exception) { - // error message for non-existent project - assertEquals("Cannot parse as CloudRegion.", exception.getMessage()); - assertEquals(BigQueryException.class, exception.getClass()); - } + BigQueryException bqException = + assertThrows( + BigQueryException.class, () -> bigquery.query(configSelect, jobIdWithProjectId)); + assertEquals(400, bqException.getCode()); } @Test