コード例 #1
0
 // 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);
 }
コード例 #2
0
    @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);
    }