@Override
  public Optional<BlobDescriptor> handleHttpResponseException(ResponseException responseException)
      throws ResponseException {
    if (responseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
      throw responseException;
    }

    if (responseException.getContent() == null) {
      // TODO: The Google HTTP client gives null content for HEAD requests. Make the content never
      // be null, even for HEAD requests.
      return Optional.empty();
    }

    // Find a BLOB_UNKNOWN error response code.
    ErrorCodes errorCode = ErrorResponseUtil.getErrorCode(responseException);
    if (errorCode == ErrorCodes.BLOB_UNKNOWN) {
      return Optional.empty();
    }

    // BLOB_UNKNOWN was not found as a error response code.
    throw responseException;
  }
@Test
  public void testHandleHttpResponseException() throws IOException {
    ResponseException mockResponseException = Mockito.mock(ResponseException.class);
    Mockito.when(mockResponseException.getStatusCode())
        .thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);

    ErrorResponseTemplate emptyErrorResponseTemplate =
        new ErrorResponseTemplate()
            .addError(new ErrorEntryTemplate(ErrorCodes.BLOB_UNKNOWN.name(), "some message"));
    Mockito.when(mockResponseException.getContent())
        .thenReturn(JsonTemplateMapper.toUtf8String(emptyErrorResponseTemplate));

    Assert.assertFalse(
        testBlobChecker.handleHttpResponseException(mockResponseException).isPresent());
  }