### Question:
BlobChecker implements RegistryEndpointProvider<Optional<BlobDescriptor>> { @Override public Optional<BlobDescriptor> handleResponse(Response response) throws RegistryErrorException { long contentLength = response.getContentLength(); if (contentLength < 0) { throw new RegistryErrorExceptionBuilder(getActionDescription()) .addReason("Did not receive Content-Length header") .build(); } return Optional.of(new BlobDescriptor(contentLength, blobDigest)); } BlobChecker(
      RegistryEndpointRequestProperties registryEndpointRequestProperties,
      DescriptorDigest blobDigest); @Override Optional<BlobDescriptor> handleResponse(Response response); @Override Optional<BlobDescriptor> handleHttpResponseException(ResponseException responseException); @Override URL getApiRoute(String apiRouteBase); @Nullable @Override BlobHttpContent getContent(); @Override List<String> getAccept(); @Override String getHttpMethod(); @Override String getActionDescription();  }### Answer:
@Test public void testHandleResponse() throws RegistryErrorException { Mockito.when(mockResponse.getContentLength()).thenReturn(0L); BlobDescriptor expectedBlobDescriptor = new BlobDescriptor(0, fakeDigest); BlobDescriptor blobDescriptor = testBlobChecker.handleResponse(mockResponse).get(); Assert.assertEquals(expectedBlobDescriptor, blobDescriptor); }
@Test public void testHandleResponse_noContentLength() { Mockito.when(mockResponse.getContentLength()).thenReturn(-1L); try { testBlobChecker.handleResponse(mockResponse); Assert.fail("Should throw exception if Content-Length header is not present"); } catch (RegistryErrorException ex) { MatcherAssert.assertThat( ex.getMessage(), CoreMatchers.containsString("Did not receive Content-Length header")); } }