@Override
  public DescriptorDigest handleResponse(Response response) throws IOException {
    // Checks if the image digest is as expected.
    DescriptorDigest expectedDigest = Digests.computeJsonDigest(manifestTemplate);

    List<String> receivedDigests = response.getHeader(RESPONSE_DIGEST_HEADER);
    if (receivedDigests.size() == 1) {
      try {
        DescriptorDigest receivedDigest = DescriptorDigest.fromDigest(receivedDigests.get(0));
        if (expectedDigest.equals(receivedDigest)) {
          return expectedDigest;
        }

      } catch (DigestException ex) {
        // Invalid digest.
      }
    }

    // The received digest is not as expected. Warns about this.
    eventHandlers.dispatch(
        LogEvent.warn(makeUnexpectedImageDigestWarning(expectedDigest, receivedDigests)));
    return expectedDigest;
  }
@Test
  public void testHandleResponse_valid() throws IOException {
    DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
    Mockito.when(mockResponse.getHeader("Docker-Content-Digest"))
        .thenReturn(Collections.singletonList(expectedDigest.toString()));
    Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
  }