public void testProcessDir() throws IOException {
    RestClient restClient = new RestClient();
    final AtomicInteger ok = new AtomicInteger();

    restClient.setListener(
        (File src, String error, Query q) -> {
          if (q.getState() == State.SUCCESS) ok.incrementAndGet();
        });

    File google = new File("google.query");
    File yandex = new File("yandex.query");
    File googleResponse = new File("google.response");
    File yandexResponse = new File("yandex.response");
    prepareQueries(google, yandex);

    googleResponse.delete();
    yandexResponse.delete();

    boolean result = !googleResponse.exists() && !yandexResponse.exists();

    assertTrue(result);
    restClient.start();
    restClient.processDir(null);
    restClient.awaitFinishAndStop();
    result = googleResponse.exists() && yandexResponse.exists();

    assertTrue(ok.get() == 2);
    assertTrue(result);

    google.delete();
    yandex.delete();
    googleResponse.delete();
    yandexResponse.delete();
  }
  public void testProcessOrderedFileList() throws IOException {
    RestClient httpTestTool = new RestClient();

    final AtomicInteger ok = new AtomicInteger();

    httpTestTool.setListener(getListener(ok));

    File google = new File("google.query");
    File yandex = new File("yandex.query");
    File googleResponse = new File("google.response");
    File yandexResponse = new File("yandex.response");
    File queryList = new File("query.lst");
    IOUtil.saveString("google.query\nyandex.query\n", queryList);

    prepareQueries(google, yandex);
    googleResponse.delete();
    yandexResponse.delete();

    boolean result =
        google.exists()
            && yandex.exists()
            && queryList.exists()
            && !googleResponse.exists()
            && !yandexResponse.exists();
    assertTrue(result);

    httpTestTool.start();

    httpTestTool.processOrderedFileList(queryList, null);
    result =
        googleResponse.exists()
            && yandexResponse.exists()
            && googleResponse.lastModified() < yandexResponse.lastModified();
    assertTrue(result);
    googleResponse.delete();
    yandexResponse.delete();

    IOUtil.saveString("yandex.query\ngoogle.query\n", queryList);
    httpTestTool.processOrderedFileList(queryList, null);
    result =
        googleResponse.exists()
            && yandexResponse.exists()
            && googleResponse.lastModified() > yandexResponse.lastModified();
    assertTrue(result);

    httpTestTool.stop();

    google.delete();
    yandex.delete();
    googleResponse.delete();
    yandexResponse.delete();
    queryList.delete();
  }
  public void testProcessFileListIn() throws IOException {
    RestClient httpTestTool = new RestClient();

    final AtomicInteger ok = new AtomicInteger();

    httpTestTool.setListener(getListener(ok));

    File parent = new File("Tmp");
    parent.mkdirs();

    File google = new File(parent, "google.query");
    File yandex = new File(parent, "yandex.query");
    File googleResponse = new File(parent, "google.response");
    File yandexResponse = new File(parent, "yandex.response");
    File queryList = new File("query.lst");
    IOUtil.saveString("Tmp/google.query\nTmp/yandex.query\n", queryList);

    prepareQueries(google, yandex);

    googleResponse.delete();
    yandexResponse.delete();

    boolean result =
        google.exists()
            && yandex.exists()
            && queryList.exists()
            && !googleResponse.exists()
            && !yandexResponse.exists();
    assertTrue(result);

    httpTestTool.start();
    httpTestTool.processFileList(queryList, null);
    httpTestTool.awaitFinishAndStop();
    result = googleResponse.exists() && yandexResponse.exists();
    assertTrue(result);
    google.delete();
    yandex.delete();
    googleResponse.delete();
    yandexResponse.delete();
    queryList.delete();
    parent.delete();
  }