public static CacheDirectories from(CommonCliOptions commonCliOptions, Path contextRoot) {
    Preconditions.checkArgument(
        Files.isDirectory(contextRoot),
        "contextRoot must be a directory, but " + contextRoot.toString() + " is not.");
    return new CacheDirectories(
        commonCliOptions.getBaseImageCache().orElse(null),
        commonCliOptions
            .getProjectCache()
            .orElse(
                Paths.get(System.getProperty("java.io.tmpdir"))
                    .resolve("jib-cli-cache")
                    .resolve("projects")
                    .resolve(getProjectCacheDirectoryFromProject(contextRoot))));
  }
@Test
  public void testCacheDirectories_failIfContextIsNotDirectory() throws IOException {
    Path badContext = temporaryFolder.newFile().toPath();
    CommonCliOptions commonCliOptions =
        CommandLine.populateCommand(new CommonCliOptions(), "-t", "ignored");

    IllegalArgumentException exception =
        Assert.assertThrows(
            IllegalArgumentException.class,
            () -> CacheDirectories.from(commonCliOptions, badContext));
    assertThat(exception)
        .hasMessageThat()
        .isEqualTo("contextRoot must be a directory, but " + badContext.toString() + " is not.");
  }