BasicAuthRequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { template.header("Authorization", headerValue); } BasicAuthRequestInterceptor(String username, String password);  BasicAuthRequestInterceptor(String username, String password, Charset charset); @Override void apply(RequestTemplate template);  }
@Test public void addsAuthorizationHeader() { RequestTemplate template = new RequestTemplate(); BasicAuthRequestInterceptor interceptor = new BasicAuthRequestInterceptor("Aladdin", "open sesame"); interceptor.apply(template); assertThat(template) .hasHeaders( entry("Authorization", asList("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="))); }
@Test public void addsAuthorizationHeader_longUserAndPassword() { RequestTemplate template = new RequestTemplate(); BasicAuthRequestInterceptor interceptor = new BasicAuthRequestInterceptor("IOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIO", "101010101010101010101010101010101010101010"); interceptor.apply(template); assertThat(template) .hasHeaders( entry("Authorization", asList( "Basic SU9JT0lPSU9JT0lPSU9JT0lPSU9JT0lPSU9JT0lPSU9JT0lPSU86MTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEw"))); }