@Test
public void testWaitForJobCompletionError()
    throws InterruptedException, IOException {

  // Return completed job.
  when(mockJobsGet.execute()).thenReturn(job);
  // Set error result to not null.
  jobStatus.setErrorResult(new ErrorProto());
  // Run waitForJobCompletion and assert failure.
  IOException e =
      assertThrows(
          IOException.class,
          () ->
              BigQueryUtils.waitForJobCompletion(
                  mockBigQuery, projectId, jobReference, mockProgressable));
  assertThat(e).hasMessageThat().contains(jobReference.getJobId());
}