BindBlobToMultipartForm implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof Blob, "this binder is only valid for Blobs!"); checkNotNull(request, "request"); Blob blob = Blob.class.cast(input); Part part = Part.create(blob.getMetadata().getName(), blob.getPayload(), new PartOptions().contentType(blob.getMetadata().getContentMetadata().getContentType())); request.setPayload(new MultipartForm(part)); return request; }  @Override R bindToRequest(R request, Object input);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeBlob() { BindBlobToMultipartForm binder = new BindBlobToMultipartForm(); HttpRequest request = HttpRequest.builder().method("POST").endpoint("http: binder.bindToRequest(request, new File("foo")); }
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) public void testNullIsBad() { BindBlobToMultipartForm binder = new BindBlobToMultipartForm(); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, null); }