Skip to content

Commit a03b295

Browse files
committed
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 #12135
1 parent 52e041a commit a03b295

File tree

1 file changed

+4
-7
lines changed
  • java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it

1 file changed

+4
-7
lines changed

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4698,13 +4698,10 @@ void testProjectIDFastSQLQueryWithJobId() {
46984698
JobId jobIdWithProjectId = JobId.newBuilder().setProject(invalidProjectId).build();
46994699
QueryJobConfiguration configSelect =
47004700
QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build();
4701-
try {
4702-
bigquery.query(configSelect, jobIdWithProjectId);
4703-
} catch (Exception exception) {
4704-
// error message for non-existent project
4705-
assertEquals("Cannot parse as CloudRegion.", exception.getMessage());
4706-
assertEquals(BigQueryException.class, exception.getClass());
4707-
}
4701+
BigQueryException bqException =
4702+
assertThrows(
4703+
BigQueryException.class, () -> bigquery.query(configSelect, jobIdWithProjectId));
4704+
assertEquals(400, bqException.getCode());
47084705
}
47094706

47104707
@Test

0 commit comments

Comments
 (0)