public boolean fileExists(String path) throws IOException, InvalidTokenException {
    String url;
    try {
      url =
          getUriBuilder()
              .setPath(API_PATH_PREFIX + "/mounts/primary/files/info")
              .setParameter("path", path)
              .build()
              .toString();
    } catch (URISyntaxException e) {
      throw new IllegalStateException("Could not produce url.", e);
    }

    Request.Builder requestBuilder = getRequestBuilder(url);

    try (Response response = getResponse(requestBuilder)) {
      int code = response.code();
      if (code == 200) {
        return true;
      }
      if (code == 404) {
        return false;
      }
      throw new KoofrClientIOException(response);
    }
  }
@Test
  public void testFileExistsTokenExpired() throws Exception {
    when(credentialFactory.refreshCredential(credential))
        .then(
            (InvocationOnMock invocation) -> {
              final Credential cred = invocation.getArgument(0);
              cred.setAccessToken("acc1");
              return cred;
            });

    server.enqueue(new MockResponse().setResponseCode(401));
    server.enqueue(new MockResponse().setResponseCode(200));

    boolean exists = client.fileExists("/path/to/file");

    assertTrue(exists);
    assertEquals(2, server.getRequestCount());

    RecordedRequest recordedRequest = server.takeRequest();

    assertEquals("GET", recordedRequest.getMethod());
    assertEquals(
        "/api/v2/mounts/primary/files/info?path=%2Fpath%2Fto%2Ffile", recordedRequest.getPath());
    assertEquals("Bearer acc", recordedRequest.getHeader("Authorization"));
    assertEquals("2.1", recordedRequest.getHeader("X-Koofr-Version"));

    recordedRequest = server.takeRequest();

    assertEquals("GET", recordedRequest.getMethod());
    assertEquals(
        "/api/v2/mounts/primary/files/info?path=%2Fpath%2Fto%2Ffile", recordedRequest.getPath());
    assertEquals("Bearer acc1", recordedRequest.getHeader("Authorization"));
    assertEquals("2.1", recordedRequest.getHeader("X-Koofr-Version"));
  }