@Test
public void testInsertJobOrFetchDuplicateUnhandledException() throws IOException {

  IOException unhandledException = new IOException("unhandled exception");
  when(mockBigqueryJobsInsert.execute()).thenThrow(unhandledException);
  when(mockErrorExtractor.itemAlreadyExists(any(IOException.class))).thenReturn(false);
  IOException thrown =
      assertThrows(
          IOException.class, () -> helper.insertJobOrFetchDuplicate(jobProjectId, jobHandle));
  assertThat(thrown).hasMessageThat().contains(jobHandle.toString());
  assertThat(thrown).hasCauseThat().isEqualTo(unhandledException);
  verify(mockBigquery, times(1)).jobs();
  ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class);
  verify(mockBigqueryJobs, times(1)).insert(eq(jobProjectId), jobCaptor.capture());
  Job job = jobCaptor.getValue();
  assertThat(job).isEqualTo(jobHandle);
  verify(mockBigqueryJobsInsert, times(1)).execute();
  verify(mockErrorExtractor).itemAlreadyExists(eq(unhandledException));
}