BindUserMetadataToHeaders implements Binder, Function<UserMetadata, Map<String, String>> { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof UserMetadata, "this binder is only valid for UserMetadatas!"); checkNotNull(request, "request"); return (R) request.toBuilder().replaceHeaders(Multimaps.forMap(apply(UserMetadata.class.cast(input)))).build(); }  @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input); @Override Map<String, String> apply(UserMetadata md);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeUserMetadata() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http: binder.bindToRequest(request, new File("foo")); }
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) public void testNullIsBad() { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, null); }