### Question:
DockerConfig { @Nullable DockerCredentialHelper getCredentialHelperFor(String registry) { List<Predicate<String>> registryMatchers = getRegistryMatchersFor(registry); Map.Entry<String, String> firstCredHelperMatch = findFirstInMapByKey(dockerConfigTemplate.getCredHelpers(), registryMatchers); if (firstCredHelperMatch != null) { return new DockerCredentialHelper( firstCredHelperMatch.getKey(), Paths.get("docker-credential-" + firstCredHelperMatch.getValue())); } if (dockerConfigTemplate.getCredsStore() != null) { return new DockerCredentialHelper( registry, Paths.get("docker-credential-" + dockerConfigTemplate.getCredsStore())); } return null; } DockerConfig(DockerConfigTemplate dockerConfigTemplate);   }### Answer:
@Test public void testGetCredentialHelperFor_exactMatchInCredHelpers() throws URISyntaxException, IOException { Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI()); DockerConfig dockerConfig = new DockerConfig(JsonTemplateMapper.readJsonFromFile(json, DockerConfigTemplate.class)); Assert.assertEquals( Paths.get("docker-credential-credHelper for just.registry.in.helpers"), dockerConfig.getCredentialHelperFor("just.registry.in.helpers").getCredentialHelper()); }
@Test public void testGetCredentialHelperFor_withHttps() throws URISyntaxException, IOException { Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI()); DockerConfig dockerConfig = new DockerConfig(JsonTemplateMapper.readJsonFromFile(json, DockerConfigTemplate.class)); Assert.assertEquals( Paths.get("docker-credential-credHelper for https__with.protocol.in.helpers"), dockerConfig.getCredentialHelperFor("with.protocol.in.helpers").getCredentialHelper()); }
@Test public void testGetCredentialHelperFor_withSuffix() throws URISyntaxException, IOException { Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI()); DockerConfig dockerConfig = new DockerConfig(JsonTemplateMapper.readJsonFromFile(json, DockerConfigTemplate.class)); Assert.assertEquals( Paths.get("docker-credential-credHelper for with.suffix.in.helpers/v2/"), dockerConfig.getCredentialHelperFor("with.suffix.in.helpers").getCredentialHelper()); }
@Test public void testGetCredentialHelperFor_withProtocolAndSuffix() throws URISyntaxException, IOException { Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI()); DockerConfig dockerConfig = new DockerConfig(JsonTemplateMapper.readJsonFromFile(json, DockerConfigTemplate.class)); Assert.assertEquals( Paths.get( "docker-credential-credHelper for https__with.protocol.and.suffix.in.helpers/suffix"), dockerConfig .getCredentialHelperFor("with.protocol.and.suffix.in.helpers") .getCredentialHelper()); }
@Test public void testGetCredentialHelperFor_correctSuffixMatching() throws URISyntaxException, IOException { Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI()); DockerConfig dockerConfig = new DockerConfig(JsonTemplateMapper.readJsonFromFile(json, DockerConfigTemplate.class)); Assert.assertEquals( Paths.get("docker-credential-some credential store"), dockerConfig.getCredentialHelperFor("example").getCredentialHelper()); Assert.assertEquals( Paths.get("docker-credential-some credential store"), dockerConfig.getCredentialHelperFor("another.example").getCredentialHelper()); }