BindIterableToHeadersWithContainerDeleteMetadataPrefix 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> metadataKeys = Iterables.transform((Iterable<String>) input, FN); HashMultimap<String, String> headers = HashMultimap.create(); for (String metadataKey: metadataKeys) { headers.put(metadataKey, ""); } return (R) request.toBuilder().replaceHeaders(headers).build(); } BindIterableToHeadersWithContainerDeleteMetadataPrefix(); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }
@Test public void testMetadataKeysBind() { List<String> metadataKeys = ImmutableList.of("foo", "bar"); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindIterableToHeadersWithContainerDeleteMetadataPrefix binder = injector.getInstance(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class); HttpRequest actualRequest = binder.bindToRequest(request, metadataKeys); HttpRequest expectedRequest = HttpRequest.builder() .method("PUT") .endpoint("http: .addHeader(SwiftHeaders.CONTAINER_DELETE_METADATA_PREFIX + "foo", "") .addHeader(SwiftHeaders.CONTAINER_DELETE_METADATA_PREFIX + "bar", "") .build(); assertEquals(actualRequest, expectedRequest); }
@Test(expectedExceptions = NullPointerException.class) public void testNullListIsBad() { HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindIterableToHeadersWithContainerDeleteMetadataPrefix binder = injector.getInstance(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class); binder.bindToRequest(request, null); }
@Test(expectedExceptions = NullPointerException.class) public void testNullRequestIsBad() { List<String> metadataKeys = ImmutableList.of("foo", "bar"); BindIterableToHeadersWithContainerDeleteMetadataPrefix binder = injector.getInstance(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class); binder.bindToRequest(null, metadataKeys); }