DockerPullImage extends AbstractDescribableImpl<DockerPullImage> { protected boolean shouldPullImage(DockerClient client, String imageName) { NameParser.ReposTag repostag = NameParser.parseRepositoryTag(imageName); final String fullImageName = repostag.repos + ":" + (repostag.tag.isEmpty() ? "latest" : repostag.tag); if (getPullStrategy().pullIfExists(fullImageName) && getPullStrategy().pullIfNotExists(fullImageName)) { return true; } if (!getPullStrategy().pullIfExists(fullImageName) && !getPullStrategy().pullIfNotExists(fullImageName)) { return false; } List<Image> images = client.listImagesCmd().exec(); boolean hasImage = images.stream().anyMatch(image -> nonNull(image.getRepoTags()) && Arrays.stream(image.getRepoTags()) .anyMatch(repoTag -> repoTag.contains(fullImageName) || repoTag.contains("docker.io/" + fullImageName) ) ); return hasImage ? getPullStrategy().pullIfExists(imageName) : getPullStrategy().pullIfNotExists(imageName); } @DataBoundConstructor  DockerPullImage(); @Nonnull DockerImagePullStrategy getPullStrategy(); @DataBoundSetter void setPullStrategy(DockerImagePullStrategy pullStrategy); @Deprecated String getCredentialsId(); @Deprecated @DataBoundSetter void setCredentialsId(String credentialsId); @Nonnull List<DockerRegistryCredential> getRegistriesCreds(); @DataBoundSetter void setRegistriesCreds(List<DockerRegistryCredential> registriesCreds); YADockerConnector getConnector(); @DataBoundSetter void setConnector(YADockerConnector connector); void exec(@Nonnull final DockerClient client, @Nonnull final String imageName, TaskListener listener); void execInternal(@Nonnull final DockerClient client, @Nonnull final String imageName, TaskListener listener); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void shouldPullImageTest() { DockerPullImage dockerPullImage = new DockerPullImage(); dockerPullImage.setPullStrategy(pullStrategy); DockerClient client = mockDockerClient(); assertEquals(shouldPull, dockerPullImage.shouldPullImage(client, imageName)); }