BindIterableToHeadersWithPurgeCDNObjectEmail implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof Iterable<?>, "this binder is only valid for Iterable!"); checkNotNull(request, "request"); Iterable<String> emails = (Iterable<String>) input; String emailCSV = Joiner.on(", ").join((List<String>) emails); ImmutableMultimap<String, String> headers = ImmutableMultimap.<String, String> of(CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL, emailCSV); return (R) request.toBuilder().replaceHeaders(headers).build(); }  @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }
@Test public void testEmailBind() { List<String> emails = ImmutableList.of("foo@bar.com", "bar@foo.com"); HttpRequest request = HttpRequest.builder().method("DELETE").endpoint("http: BindIterableToHeadersWithPurgeCDNObjectEmail binder = injector.getInstance(BindIterableToHeadersWithPurgeCDNObjectEmail.class); HttpRequest actualRequest = binder.bindToRequest(request, emails); HttpRequest expectedRequest = HttpRequest.builder() .method("DELETE") .endpoint("http: .addHeader(CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL, "foo@bar.com, bar@foo.com") .build(); assertEquals(actualRequest, expectedRequest); }
@Test(expectedExceptions = NullPointerException.class) public void testNullListIsBad() { HttpRequest request = HttpRequest.builder().method("DELETE").endpoint("http: BindIterableToHeadersWithPurgeCDNObjectEmail binder = injector.getInstance(BindIterableToHeadersWithPurgeCDNObjectEmail.class); binder.bindToRequest(request, null); }
@Test(expectedExceptions = NullPointerException.class) public void testNullRequestIsBad() { List<String> emails = ImmutableList.of("foo@bar.com", "bar@foo.com"); BindIterableToHeadersWithPurgeCDNObjectEmail binder = injector.getInstance(BindIterableToHeadersWithPurgeCDNObjectEmail.class); binder.bindToRequest(null, emails); }