### Question:
BindMapToHeadersWithPrefix implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof Map<?, ?>, "this binder is only valid for Maps!"); checkNotNull(request, "request"); Map<String, String> userMetadata = Maps2.transformKeys((Map<String, String>) input, fn); return (R) request.toBuilder().replaceHeaders(Multimaps.forMap(userMetadata)).build(); } @Inject  BindMapToHeadersWithPrefix(@Named(PROPERTY_USER_METADATA_PREFIX) final String metadataPrefix); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }### Answer:
@Test public void testCorrect() throws SecurityException, NoSuchMethodException { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: BindMapToHeadersWithPrefix binder = new BindMapToHeadersWithPrefix("prefix:"); assertEquals( binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")), HttpRequest.builder().method("GET").endpoint("http: .addHeader("prefix:imagename", "foo") .addHeader("prefix:serverid", "2").build()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeMap() { BindMapToHeadersWithPrefix binder = new BindMapToHeadersWithPrefix("prefix:"); HttpRequest request = HttpRequest.builder().method("POST").endpoint("http: binder.bindToRequest(request, new File("foo")); }
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) public void testNullIsBad() { BindMapToHeadersWithPrefix binder = new BindMapToHeadersWithPrefix("prefix:"); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, null); }