### Question:
TokenAuthenticator implements RequestInterceptor { @Override public Response execute(Client client, Request request) throws IdobataError { List<Header> requestHeaders = new ArrayList<Header>(request.getHeaders()); requestHeaders.add(new Header("X-API-Token", mTokenProvider.get())); try { Response response = client.execute(new Request(request.getMethod(), request.getUrl(), requestHeaders, request.getBody())); int status = response.getStatus(); if (status >= 400) { throw new HttpError(request.getUrl(), status, response.getReason()); } return response; } catch (IOException e) { throw new IdobataError(e); } } TokenAuthenticator(TokenProvider tokenProvider);  TokenAuthenticator(String token); @Override Response execute(Client client, Request request);  }### Answer:
@Test public void constantTokenString() throws Exception { ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class); given(mClient.execute(requestCaptor.capture())).willReturn(mock(Response.class)); TokenAuthenticator underTest = new TokenAuthenticator("abc"); Request request = new Request(null, null, Collections.<Header> emptyList(), null); underTest.execute(mClient, request); Request actualRequest = requestCaptor.getValue(); Header header = actualRequest.getHeaders() .get(0); assertThat(header.getName()).isEqualTo("X-API-Token"); assertThat(header.getValue()).isEqualTo("abc"); }
@Test public void tokenProvider() throws Exception { ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class); given(mClient.execute(requestCaptor.capture())).willReturn(mock(Response.class)); TokenAuthenticator.TokenProvider tokenProvider = mock(TokenAuthenticator.TokenProvider.class); given(tokenProvider.get()).willReturn("abc"); TokenAuthenticator underTest = new TokenAuthenticator(tokenProvider); Request request = new Request(null, null, Collections.<Header> emptyList(), null); underTest.execute(mClient, request); Request actualRequest = requestCaptor.getValue(); Header header = actualRequest.getHeaders() .get(0); assertThat(header.getName()).isEqualTo("X-API-Token"); assertThat(header.getValue()).isEqualTo("abc"); }