### Question:
ParseBlobFromHeadersAndHttpContent implements Function<HttpResponse, Blob>,
      InvocationContext<ParseBlobFromHeadersAndHttpContent> { public Blob apply(HttpResponse from) { checkNotNull(from, "request"); MutableBlobMetadata metadata = metadataParser.apply(from); Blob blob = blobFactory.create(metadata); blob.getAllHeaders().putAll(from.getHeaders()); blob.setPayload(from.getPayload()); return blob; } @Inject  ParseBlobFromHeadersAndHttpContent(ParseSystemAndUserMetadataFromHeaders metadataParser,
         Blob.Factory blobFactory); Blob apply(HttpResponse from); @Override ParseBlobFromHeadersAndHttpContent setContext(HttpRequest request);  }### Answer:
@Test public void testParseContentLengthWhenContentRangeSet() throws HttpException { ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class); ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(metadataParser, blobProvider); HttpResponse response = HttpResponse.builder() .statusCode(200).message("ok") .payload("") .addHeader("Content-Range", "0-10485759/20232760").build(); response.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); response.getPayload().getContentMetadata().setContentLength(10485760L); MutableBlobMetadata meta = blobMetadataProvider.get(); expect(metadataParser.apply(response)).andReturn(meta); replay(metadataParser); Blob object = callable.apply(response); assertEquals(object.getPayload().getContentMetadata().getContentLength(), Long.valueOf(10485760)); assertEquals(object.getAllHeaders().get("Content-Range"), ImmutableList.of("0-10485759/20232760")); }
@Test(expectedExceptions = NullPointerException.class) public void testCall() throws HttpException { ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class); ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(metadataParser, blobProvider); HttpResponse response = HttpResponse.builder() .statusCode(200).message("ok") .addHeader("Content-Range", (String) null).build(); callable.apply(response); }
@Test public void testParseContentLengthWhenContentRangeSet() throws HttpException { ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class); ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(metadataParser, blobProvider); HttpResponse response = HttpResponse.builder() .statusCode(200).message("ok") .payload("") .addHeader("Content-Range", "0-10485759/20232760").build(); response.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); response.getPayload().getContentMetadata().setContentLength(10485760l); MutableBlobMetadata meta = blobMetadataProvider.get(); expect(metadataParser.apply(response)).andReturn(meta); replay(metadataParser); Blob object = callable.apply(response); assertEquals(object.getPayload().getContentMetadata().getContentLength(), Long.valueOf(10485760)); assertEquals(object.getAllHeaders().get("Content-Range"), ImmutableList.of("0-10485759/20232760")); }