  @Test
  public void startUploading_DicomWebExceptionOnStowRs_secondTry_success() throws DicomWebException, IOException {

    doThrow(new DicomWebException("Reason", HttpStatus.INTERNAL_SERVER_ERROR_500, Status.ProcessingFailure))
        .doNothing().when(webClientMock).stowRs(any(InputStream.class));
    when(backupUploaderMock.doReadBackup(eq(UNIQUE_FILE_NAME))).thenReturn(backupInputStream);

    backupUploadService.startUploading(webClientMock, spyBackupState);

    ArgumentCaptor<InputStream> argumentCaptor = ArgumentCaptor.forClass(InputStream.class);

    verify(backupUploaderMock, times(2)).doReadBackup(eq(UNIQUE_FILE_NAME));
    verify(webClientMock, times(2)).stowRs(argumentCaptor.capture());
    byte [] actualBytes = argumentCaptor.getValue().readNBytes(5);
    assertThat(Arrays.equals(actualBytes, BACKUP_BYTES)).isTrue();

    verify(backupUploaderMock).doRemoveBackup(eq(UNIQUE_FILE_NAME));
  }