### Question:
ManifestPusher implements RegistryEndpointProvider<DescriptorDigest> { @Override public DescriptorDigest handleResponse(Response response) throws IOException { 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) { } } eventHandlers.dispatch( LogEvent.warn(makeUnexpectedImageDigestWarning(expectedDigest, receivedDigests))); return expectedDigest; } ManifestPusher(
      RegistryEndpointRequestProperties registryEndpointRequestProperties,
      ManifestTemplate manifestTemplate,
      String imageTag,
      EventHandlers eventHandlers); @Override BlobHttpContent getContent(); @Override List<String> getAccept(); @Override DescriptorDigest handleHttpResponseException(ResponseException responseException); @Override DescriptorDigest handleResponse(Response response); @Override URL getApiRoute(String apiRouteBase); @Override String getHttpMethod(); @Override String getActionDescription();  }### Answer:
@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)); }
@Test public void testHandleResponse_noDigest() throws IOException { DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate); Mockito.when(mockResponse.getHeader("Docker-Content-Digest")) .thenReturn(Collections.emptyList()); Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse)); Mockito.verify(mockEventHandlers) .dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received none")); }
@Test public void testHandleResponse_multipleDigests() throws IOException { DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate); Mockito.when(mockResponse.getHeader("Docker-Content-Digest")) .thenReturn(Arrays.asList("too", "many")); Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse)); Mockito.verify(mockEventHandlers) .dispatch( LogEvent.warn("Expected image digest " + expectedDigest + ", but received: too, many")); }
@Test public void testHandleResponse_invalidDigest() throws IOException { DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate); Mockito.when(mockResponse.getHeader("Docker-Content-Digest")) .thenReturn(Collections.singletonList("not valid")); Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse)); Mockito.verify(mockEventHandlers) .dispatch( LogEvent.warn("Expected image digest " + expectedDigest + ", but received: not valid")); }