static void writeImageJson(Optional<Path> imageJsonOutputPath, JibContainer jibContainer)
      throws IOException {
    if (imageJsonOutputPath.isPresent()) {
      ImageMetadataOutput metadataOutput = ImageMetadataOutput.fromJibContainer(jibContainer);
      Files.write(
          imageJsonOutputPath.get(), metadataOutput.toJson().getBytes(StandardCharsets.UTF_8));
    }
  }
@Test
  public void testWriteImageJson()
      throws InvalidImageReferenceException, IOException, DigestException {
    String imageId = "sha256:61bb3ec31a47cb730eb58a38bbfa813761a51dca69d10e39c24c3d00a7b2c7a9";
    String digest = "sha256:3f1be7e19129edb202c071a659a4db35280ab2bb1a16f223bfd5d1948657b6fc";
    when(mockJibContainer.getTargetImage())
        .thenReturn(ImageReference.parse("eclipse-temurin:8-jre"));
    when(mockJibContainer.getImageId()).thenReturn(DescriptorDigest.fromDigest(imageId));
    when(mockJibContainer.getDigest()).thenReturn(DescriptorDigest.fromDigest(digest));
    when(mockJibContainer.getTags()).thenReturn(ImmutableSet.of("latest", "tag-2"));

    Path outputPath = temporaryFolder.getRoot().toPath().resolve("jib-image.json");
    JibCli.writeImageJson(Optional.of(outputPath), mockJibContainer);

    String outputJson = new String(Files.readAllBytes(outputPath), StandardCharsets.UTF_8);
    ImageMetadataOutput metadataOutput =
        JsonTemplateMapper.readJson(outputJson, ImageMetadataOutput.class);
    assertThat(metadataOutput.getImage()).isEqualTo("eclipse-temurin:8-jre");
    assertThat(metadataOutput.getImageId()).isEqualTo(imageId);
    assertThat(metadataOutput.getImageDigest()).isEqualTo(digest);
    assertThat(metadataOutput.getTags()).containsExactly("latest", "tag-2");
  }