Repository: GoogleContainerTools/jib
File: jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/JibBuildRunnerTest.java (Java)

Code before:
  @Test
  public void testBuildImage_writesImageJson() throws Exception {
    final ImageReference targetImageReference = ImageReference.parse("gcr.io/distroless/java:11");
    final String imageId =
        "sha256:61bb3ec31a47cb730eb58a38bbfa813761a51dca69d10e39c24c3d00a7b2c7a9";
    final String digest = "sha256:3f1be7e19129edb202c071a659a4db35280ab2bb1a16f223bfd5d1948657b6fc";
    final Set<String> tags = ImmutableSet.of("latest", "0.1.41-69d10e-20200116T101403");

    final Path outputPath = temporaryFolder.newFile("jib-image.json").toPath();

    Mockito.when(mockJibContainer.getTargetImage()).thenReturn(targetImageReference);
    Mockito.when(mockJibContainer.getImageId()).thenReturn(DescriptorDigest.fromDigest(imageId));
    Mockito.when(mockJibContainer.getDigest()).thenReturn(DescriptorDigest.fromDigest(digest));
    Mockito.when(mockJibContainer.getTags()).thenReturn(tags);
    Mockito.when(mockJibContainerBuilder.containerize(mockContainerizer))
        .thenReturn(mockJibContainer);
    testJibBuildRunner.writeImageJson(outputPath).runBuild();

    final String outputJson = new String(Files.readAllBytes(outputPath), StandardCharsets.UTF_8);
    final ImageMetadataOutput metadataOutput = ImageMetadataOutput.fromJson(outputJson);
    Assert.assertEquals(targetImageReference.toString(), metadataOutput.getImage());
    Assert.assertEquals(imageId, metadataOutput.getImageId());
    Assert.assertEquals(digest, metadataOutput.getImageDigest());
    Assert.assertEquals(tags, ImmutableSet.copyOf(metadataOutput.getTags()));
    Assert.assertTrue(metadataOutput.isImagePushed());
  }
}


Review comment (suggestion):
Looks like we're missing a mockito setup above. How about we add this in line 246: `Mockito.when(mockJibContainer.isImagePushed()).thenReturn(true);`

Code after:
  @Test
  public void testBuildImage_writesImageJson() throws Exception {
    final ImageReference targetImageReference = ImageReference.parse("gcr.io/distroless/java:11");
    final String imageId =
        "sha256:61bb3ec31a47cb730eb58a38bbfa813761a51dca69d10e39c24c3d00a7b2c7a9";
    final String digest = "sha256:3f1be7e19129edb202c071a659a4db35280ab2bb1a16f223bfd5d1948657b6fc";
    final Set<String> tags = ImmutableSet.of("latest", "0.1.41-69d10e-20200116T101403");

    final Path outputPath = temporaryFolder.newFile("jib-image.json").toPath();

    Mockito.when(mockJibContainer.getTargetImage()).thenReturn(targetImageReference);
    Mockito.when(mockJibContainer.getImageId()).thenReturn(DescriptorDigest.fromDigest(imageId));
    Mockito.when(mockJibContainer.getDigest()).thenReturn(DescriptorDigest.fromDigest(digest));
    Mockito.when(mockJibContainer.getTags()).thenReturn(tags);
    Mockito.when(mockJibContainerBuilder.containerize(mockContainerizer))
        .thenReturn(mockJibContainer);
    Mockito.when(mockJibContainer.isImagePushed()).thenReturn(true);
    testJibBuildRunner.writeImageJson(outputPath).runBuild();

    final String outputJson = new String(Files.readAllBytes(outputPath), StandardCharsets.UTF_8);
    final ImageMetadataOutput metadataOutput = ImageMetadataOutput.fromJson(outputJson);
    Assert.assertEquals(targetImageReference.toString(), metadataOutput.getImage());
    Assert.assertEquals(imageId, metadataOutput.getImageId());
    Assert.assertEquals(digest, metadataOutput.getImageDigest());
    Assert.assertEquals(tags, ImmutableSet.copyOf(metadataOutput.getTags()));
    Assert.assertTrue(metadataOutput.isImagePushed());
  }
}