### Question:
CredentialRetrieverFactory { public CredentialRetriever wellKnownCredentialHelpers() { return () -> { for (Map.Entry<String, String> entry : WELL_KNOWN_CREDENTIAL_HELPERS.entrySet()) { try { String registrySuffix = entry.getKey(); if (imageReference.getRegistry().endsWith(registrySuffix)) { String credentialHelper = entry.getValue(); return Optional.of(retrieveFromDockerCredentialHelper(Paths.get(credentialHelper))); } } catch (CredentialHelperNotFoundException | CredentialHelperUnhandledServerUrlException ex) { if (ex.getMessage() != null) { logger.accept(LogEvent.info(ex.getMessage())); if (ex.getCause() != null && ex.getCause().getMessage() != null) { logger.accept(LogEvent.info(" Caused by: " + ex.getCause().getMessage())); } } } catch (IOException ex) { throw new CredentialRetrievalException(ex); } } return Optional.empty(); }; } @VisibleForTesting  CredentialRetrieverFactory(
      ImageReference imageReference,
      Consumer<LogEvent> logger,
      DockerCredentialHelperFactory dockerCredentialHelperFactory,
      GoogleCredentialsProvider googleCredentialsProvider); static CredentialRetrieverFactory forImage(
      ImageReference imageReference, Consumer<LogEvent> logger); CredentialRetriever known(Credential credential, String credentialSource); CredentialRetriever dockerCredentialHelper(String credentialHelper); CredentialRetriever dockerCredentialHelper(Path credentialHelper); CredentialRetriever wellKnownCredentialHelpers(); CredentialRetriever dockerConfig(); CredentialRetriever dockerConfig(Path dockerConfigFile); CredentialRetriever legacyDockerConfig(Path dockerConfigFile); CredentialRetriever googleApplicationDefaultCredentials();  }### Answer:
@Test public void testWellKnownCredentialHelpers() throws CredentialRetrievalException { CredentialRetrieverFactory credentialRetrieverFactory = createCredentialRetrieverFactory("something.gcr.io", "repo"); Assert.assertEquals( Optional.of(FAKE_CREDENTIALS), credentialRetrieverFactory.wellKnownCredentialHelpers().retrieve()); Mockito.verify(mockDockerCredentialHelperFactory) .create("something.gcr.io", Paths.get("docker-credential-gcr")); Mockito.verify(mockLogger) .accept( LogEvent.lifecycle( "Using credential helper docker-credential-gcr for something.gcr.io/repo")); }
@Test public void testWellKnownCredentialHelpers_info() throws CredentialRetrievalException, IOException { CredentialHelperNotFoundException notFoundException = Mockito.mock(CredentialHelperNotFoundException.class); Mockito.when(notFoundException.getMessage()).thenReturn("warning"); Mockito.when(notFoundException.getCause()).thenReturn(new IOException("the root cause")); Mockito.when(mockDockerCredentialHelper.retrieve()).thenThrow(notFoundException); CredentialRetrieverFactory credentialRetrieverFactory = createCredentialRetrieverFactory("something.amazonaws.com", "repo"); Assert.assertFalse( credentialRetrieverFactory.wellKnownCredentialHelpers().retrieve().isPresent()); Mockito.verify(mockDockerCredentialHelperFactory) .create("something.amazonaws.com", Paths.get("docker-credential-ecr-login")); Mockito.verify(mockLogger).accept(LogEvent.info("warning")); Mockito.verify(mockLogger).accept(LogEvent.info(" Caused by: the root cause")); }