### Question:
RegistryEndpointCaller { @VisibleForTesting RegistryErrorException newRegistryErrorException(ResponseException responseException) { RegistryErrorExceptionBuilder registryErrorExceptionBuilder = new RegistryErrorExceptionBuilder( registryEndpointProvider.getActionDescription(), responseException); if (responseException.getContent() != null) { try { ErrorResponseTemplate errorResponse = JsonTemplateMapper.readJson( responseException.getContent(), ErrorResponseTemplate.class); for (ErrorEntryTemplate errorEntry : errorResponse.getErrors()) { registryErrorExceptionBuilder.addReason(errorEntry); } } catch (IOException ex) { registryErrorExceptionBuilder.addReason( "registry returned error code " + responseException.getStatusCode() + "; possible causes include invalid or wrong reference. Actual error output follows:\n" + responseException.getContent() + "\n"); } } else { registryErrorExceptionBuilder.addReason( "registry returned error code " + responseException.getStatusCode() + " but did not return any details; possible causes include invalid or wrong reference, or proxy/firewall/VPN interfering \n"); } return registryErrorExceptionBuilder.build(); } @VisibleForTesting  RegistryEndpointCaller(
      EventHandlers eventHandlers,
      @Nullable String userAgent,
      RegistryEndpointProvider<T> registryEndpointProvider,
      @Nullable Authorization authorization,
      RegistryEndpointRequestProperties registryEndpointRequestProperties,
      FailoverHttpClient httpClient);   }### Answer:
@Test public void testNewRegistryErrorException_jsonErrorOutput() { ResponseException httpException = Mockito.mock(ResponseException.class); Mockito.when(httpException.getContent()) .thenReturn( "{\"errors\": [{\"code\": \"MANIFEST_UNKNOWN\", \"message\": \"manifest unknown\"}]}"); RegistryErrorException registryException = endpointCaller.newRegistryErrorException(httpException); Assert.assertSame(httpException, registryException.getCause()); Assert.assertEquals( "Tried to actionDescription but failed because: manifest unknown | If this is a bug, " + "please file an issue at https: registryException.getMessage()); }
@Test public void testNewRegistryErrorException_nonJsonErrorOutput() { ResponseException httpException = Mockito.mock(ResponseException.class); Mockito.when(httpException.getContent()).thenReturn(">>>>> (404) page not found <<<<<"); Mockito.when(httpException.getStatusCode()).thenReturn(404); RegistryErrorException registryException = endpointCaller.newRegistryErrorException(httpException); Assert.assertSame(httpException, registryException.getCause()); Assert.assertEquals( "Tried to actionDescription but failed because: registry returned error code 404; " + "possible causes include invalid or wrong reference. Actual error output follows:\n" + ">>>>> (404) page not found <<<<<\n" + " | If this is a bug, please file an issue at " + "https: registryException.getMessage()); }
@Test public void testNewRegistryErrorException_noOutputFromRegistry() { ResponseException httpException = Mockito.mock(ResponseException.class); Mockito.when(httpException.getContent()).thenReturn(null); Mockito.when(httpException.getStatusCode()).thenReturn(404); RegistryErrorException registryException = endpointCaller.newRegistryErrorException(httpException); Assert.assertSame(httpException, registryException.getCause()); Assert.assertEquals( "Tried to actionDescription but failed because: registry returned error code 404 " + "but did not return any details; possible causes include invalid or wrong reference, or proxy/firewall/VPN interfering \n" + " | If this is a bug, please file an issue at " + "https: registryException.getMessage()); }