// 1st time called: Mock a 401 (Unauthorized status) response
 @Override
 public Promise<Response, NeverThrowsException> answer(InvocationOnMock invocation)
     throws Throwable {
   Response response = new Response();
   response.setStatus(Status.UNAUTHORIZED);
   response.getHeaders().putSingle(AUTHENTICATE_HEADER, "Basic realm=\"Login\"");
   return Promises.newResultPromise(response);
 }
    @Override
    public Promise<Response, NeverThrowsException> answer(InvocationOnMock invocation)
        throws Throwable {
      Request request = (Request) invocation.getArguments()[1];

      // Verify the authorization header: base64(user:pass)
      assertThat(request.getHeaders().getFirst(AUTHORIZATION_HEADER))
          .isEqualTo("Basic " + credentials);

      // Produce a valid response, no special headers are required
      Response response = new Response();
      response.setStatus(Status.OK);
      return Promises.newResultPromise(response);
    }