@Test
public void testChallenges() throws IOException, HttpError {

  final URI uri = URI.create("https://host/file");
  final Map<String, Credentials> credentials = ImmutableMap.of("host", new Credentials("jdoe", "secret"));
  final MockOkHttpClient okHttpClient = new MockOkHttpClient();
  final HttpClient httpClient = new HttpClient(okHttpClient);
  final HttpTransferListener listener = mock(HttpTransferListener.class);
  // expect request without authorization header at first and then with
  okHttpClient.setNewCall(challengeSequence(uri, credentials));
  httpClient.get(uri, credentials, listener);
  // subsequent https calls to same host should auth right away without challenge
  okHttpClient.setNewCall(newAuthorizedRequestCall(uri, credentials));
  httpClient.get(uri, credentials, listener);
  // subsequent http calls should go not auth right away (to give a chance to redirect to https)
  final URI httpUri = URI.create("http://host/file");
  okHttpClient.setNewCall(challengeSequence(httpUri, credentials));
  httpClient.get(httpUri, credentials, listener);
}