Path getImageDirectory(ImageReference imageReference) {
    // Replace ':' and '@' with '!' to avoid directory-naming restrictions
    String replacedReference =
        imageReference.toStringWithQualifier().replace(':', '!').replace('@', '!');

    // Split image reference on '/' to build directory structure
    Iterable<String> directories = Splitter.on('/').split(replacedReference);
    Path destination = getImagesDirectory();
    for (String dir : directories) {
      destination = destination.resolve(dir);
    }
    return destination;
  }
@Test
  public void testGetImageDirectory() throws InvalidImageReferenceException {
    Path imagesDirectory = Paths.get("cache", "directory", "images");
    Assert.assertEquals(imagesDirectory, TEST_CACHE_STORAGE_FILES.getImagesDirectory());

    Assert.assertEquals(
        imagesDirectory.resolve("reg.istry/repo/sitory!tag"),
        TEST_CACHE_STORAGE_FILES.getImageDirectory(
            ImageReference.parse("reg.istry/repo/sitory:tag")));
    Assert.assertEquals(
        imagesDirectory.resolve(
            "reg.istry/repo!sha256!aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
        TEST_CACHE_STORAGE_FILES.getImageDirectory(
            ImageReference.parse(
                "reg.istry/repo@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
    Assert.assertEquals(
        imagesDirectory.resolve("reg.istry!5000/repo/sitory!tag"),
        TEST_CACHE_STORAGE_FILES.getImageDirectory(
            ImageReference.parse("reg.istry:5000/repo/sitory:tag")));
  }