// random test (simulates random network errors for comprehensive test coverage of scenarios)
  @Test
  public void continuesOnRandomNetworkErrorsIfConfigured() throws Exception {
    printTestHeader("continuesOnExceptions");

    ConfigHolder.getInstance().setContinueOnError(true);
    ProgressWatcher.getInstance().setLogErrorsToFile(true);

    SmartsheetBackupService backupService =
        new SmartsheetBackupService(
            new ErrorContextualizingSmartsheetService(new StubBadConnectionSmartsheetService()),
            parallelDownloadService);

    backupToTempDir(backupService);

    if (ProgressWatcher.getInstance().getErrorCount() > 0) {
      String errorLogFile = ProgressWatcher.getInstance().getErrorLogFile();
      assertNotNull(errorLogFile);
      printErrorLogFilePathWhenDone(errorLogFile);
    }
  }
  @Test
  public void continuesOnSpecificRequestErrorIfConfigured() throws Exception {
    printTestHeader("continuesOnSpecificRequestErrorIfConfigured");

    setContinueOnError(true);

    StubSpecificRequestFailureSmartsheetService stubSmartsheetService =
        new StubSpecificRequestFailureSmartsheetService();
    stubSmartsheetService.setMakeGetSheetRequestFail(true);

    SmartsheetBackupService backupService =
        new SmartsheetBackupService(
            new ErrorContextualizingSmartsheetService(stubSmartsheetService),
            parallelDownloadService);

    backupToTempDir(backupService);

    assertTrue(ProgressWatcher.getInstance().getErrorCount() > 0);
    String errorLogFile = ProgressWatcher.getInstance().getErrorLogFile();
    assertNotNull(errorLogFile);
    printErrorLogFilePathWhenDone(errorLogFile);
  }
  @Test
  public void doesNotContinueOnSpecificRequestErrorIfNotConfigured() {
    printTestHeader("doesNotContinueOnSpecificRequestErrorIfNotConfigured");

    // setContinueOnError(false); - not needed because default value is already false

    StubSpecificRequestFailureSmartsheetService stubSmartsheetService =
        new StubSpecificRequestFailureSmartsheetService();
    stubSmartsheetService.setMakeGetSheetRequestFail(true);

    SmartsheetBackupService backupService =
        new SmartsheetBackupService(
            new ErrorContextualizingSmartsheetService(stubSmartsheetService),
            parallelDownloadService);

    try {
      backupToTempDir(backupService);
      fail("Did not get exception even though continueOnError false");

    } catch (Exception e) {
      assertTrue(e.getClass().equals(SmartsheetGetSheetDetailsException.class));
      assertTrue(ProgressWatcher.getInstance().getErrorCount() > 0);
    }
  }
 private static void setContinueOnError(boolean continueOnError) {
   ConfigHolder.getInstance().setContinueOnError(continueOnError);
   // the backup tool does setLogErrorsToFile true if continueOnError is true,
   // so simulate that behaviour by having the test do the same here:
   ProgressWatcher.getInstance().setLogErrorsToFile(continueOnError);
 }