### Question:
ByteArrayRequestBody implements AnyRequestModifier { @Override public void applyTo(ServerDriverHttpUriRequest request) { HttpUriRequest internalRequest = request.getHttpUriRequest(); if (!(internalRequest instanceof HttpEntityEnclosingRequest)) { return; } HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) internalRequest; entityRequest.setHeader("Content-type", contentType); ByteArrayEntity entity = new ByteArrayEntity(content); entity.setContentType(contentType); entityRequest.setEntity(entity); } ByteArrayRequestBody(byte[] content, String contentType); @Override void applyTo(ServerDriverHttpUriRequest request);  }### Answer:
@Test public void bodyAppliesItselfToRequest() throws Exception { byte[] bytes = "MY STRING OF DOOM!".getBytes(); HttpPost request = new HttpPost(); ByteArrayRequestBody body = new ByteArrayRequestBody(bytes, "contentType"); body.applyTo(new ServerDriverHttpUriRequest(request)); assertThat(IOUtils.toString(request.getEntity().getContent()), is("MY STRING OF DOOM!")); assertThat(request.getEntity().getContentType().getValue(), is("contentType")); assertThat(request.getFirstHeader("Content-type").getValue(), is("contentType")); }
@Test public void applyToHandlesRequestWhichCannotHaveBody() { byte[] bytes = "MY STRING OF DOOM!".getBytes(); HttpUriRequest request = new HttpGet(); ByteArrayRequestBody body = new ByteArrayRequestBody(bytes, "contentType"); body.applyTo(new ServerDriverHttpUriRequest(request)); }