public Credential retrieve()
      throws IOException, CredentialHelperUnhandledServerUrlException,
          CredentialHelperNotFoundException {
    boolean isWindows =
        systemProperties.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows");
    String lowerCaseHelper = credentialHelper.toString().toLowerCase(Locale.ENGLISH);
    if (!isWindows || lowerCaseHelper.endsWith(".cmd") || lowerCaseHelper.endsWith(".exe")) {
      return retrieve(Arrays.asList(credentialHelper.toString(), "get"));
    }

    // We are on Windows with undefined/unknown file extension.
    for (String suffix : Arrays.asList(".cmd", ".exe")) {
      try {
        return retrieve(Arrays.asList(credentialHelper.toString() + suffix, "get"));
      } catch (CredentialHelperNotFoundException ignored) {
        // ignored
      }
    }
    // On Windows, launching a process from Java without a file extension should normally fail
    // (https://github.com/GoogleContainerTools/jib/issues/2399#issuecomment-612972912), but
    // running Jib on Linux-like environment (e.g., Cygwin) might succeed?
    return retrieve(Arrays.asList(credentialHelper.toString(), "get"));
  }
@Test
  public void testRetrieve()
      throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
          IOException {
    List<String> command = Arrays.asList(Paths.get("/foo/bar").toString(), "get");
    Mockito.when(processBuilderFactory.apply(command)).thenReturn(processBuilder);

    DockerCredentialHelper credentialHelper =
        dockerCredentialHelper(
            "serverUrl", Paths.get("/foo/bar"), systemProperties, processBuilderFactory);
    Credential credential = credentialHelper.retrieve();
    Assert.assertEquals("myusername", credential.getUsername());
    Assert.assertEquals("mysecret", credential.getPassword());

    Mockito.verify(processBuilderFactory).apply(command);
  }