ApiInterceptor implements Interceptor { public static void setAuthorizationHeader(Request.Builder builder, String authorizationHeader) { builder.removeHeader(HEADER_ACCESS_TOKEN); builder.addHeader(HEADER_ACCESS_TOKEN, authorizationHeader); } ApiInterceptor(Authenticator authenticator); @Override Response intercept(Chain chain); static void setAuthorizationHeader(Request.Builder builder, String authorizationHeader); static String getAuthorizationHeader(Request request); final Authenticator authenticator; }
@Test public void testSetAuthorizationHeader_withExistingToken() { Request.Builder builder = new Request.Builder().url("http: builder.header(HEADER_ACCESS_TOKEN, "accessToken"); ApiInterceptor.setAuthorizationHeader(builder, "accessToken2"); Request request = builder.build(); assertEquals("accessToken2", request.header(HEADER_ACCESS_TOKEN)); }
@Test public void testSetAuthorizationHeader_withoutExistingToken() { Request.Builder builder = new Request.Builder().url("http: ApiInterceptor.setAuthorizationHeader(builder, "accessToken"); Request request = builder.build(); assertEquals("accessToken", request.header(HEADER_ACCESS_TOKEN)); }