Repository: GoogleContainerTools/jib
File: jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/PullBaseImageStepTest.java (Java)

Code before:
    Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1"))
        .thenReturn(Arrays.asList("sha256:digest1"));
    Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2"))
        .thenReturn(Arrays.asList("sha256:digest2"));

    ImageMetadataTemplate imageMetadata =
        new ImageMetadataTemplate(
            manifestList,
            Arrays.asList(
                new ManifestAndConfigTemplate(
                    Mockito.mock(BuildableManifestTemplate.class),
                    new ContainerConfigurationTemplate(),
                    "sha256:digest1")));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(
            cache.areAllLayersCached(imageMetadata.getManifestsAndConfigs().get(0).getManifest()))
        .thenReturn(true);

    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));

    Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
  }

  @Test
  public void testGetCachedBaseImages_nanifestListCached_onlyPlatforms()
      throws InvalidImageReferenceException, IOException, CacheCorruptedException,
          UnlistedPlatformInManifestListException, PlatformNotFoundInBaseImageException,
          BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration())
        .thenReturn(ImageConfiguration.builder(imageReference).build());

    ManifestListTemplate manifestList = Mockito.mock(ManifestListTemplate.class);
    Mockito.when(manifestList.getDigestsForPlatform("target-arch", "target-os"))
        .thenReturn(Arrays.asList("sha256:target-digest"));

    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setContainerUser("target-user");

    ManifestAndConfigTemplate targetManifestAndConfig =
        new ManifestAndConfigTemplate(
            Mockito.mock(BuildableManifestTemplate.class),
            containerConfigJson,
            "sha256:target-digest");
    ManifestAndConfigTemplate unrelatedManifestAndConfig =
        new ManifestAndConfigTemplate(
            Mockito.mock(BuildableManifestTemplate.class),
            new ContainerConfigurationTemplate(),
            "sha256:unrelated-digest");


Review comment (performance):
```suggestion
  public void testGetCachedBaseImages_manifestListCached_onlyPlatforms()
```

Code after:
    Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1"))
        .thenReturn(Arrays.asList("sha256:digest1"));
    Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2"))
        .thenReturn(Arrays.asList("sha256:digest2"));

    ImageMetadataTemplate imageMetadata =
        new ImageMetadataTemplate(
            manifestList,
            Arrays.asList(
                new ManifestAndConfigTemplate(
                    Mockito.mock(BuildableManifestTemplate.class),
                    new ContainerConfigurationTemplate(),
                    "sha256:digest1")));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(
            cache.areAllLayersCached(imageMetadata.getManifestsAndConfigs().get(0).getManifest()))
        .thenReturn(true);

    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));

    Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
  }

  @Test
  public void testGetCachedBaseImages_manifestListCached_onlyPlatforms()
      throws InvalidImageReferenceException, IOException, CacheCorruptedException,
          UnlistedPlatformInManifestListException, PlatformNotFoundInBaseImageException,
          BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration())
        .thenReturn(ImageConfiguration.builder(imageReference).build());

    ManifestListTemplate manifestList = Mockito.mock(ManifestListTemplate.class);
    Mockito.when(manifestList.getDigestsForPlatform("target-arch", "target-os"))
        .thenReturn(Arrays.asList("sha256:target-digest"));

    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setContainerUser("target-user");

    ManifestAndConfigTemplate targetManifestAndConfig =
        new ManifestAndConfigTemplate(
            Mockito.mock(BuildableManifestTemplate.class),
            containerConfigJson,
            "sha256:target-digest");
    ManifestAndConfigTemplate unrelatedManifestAndConfig =
        new ManifestAndConfigTemplate(
            Mockito.mock(BuildableManifestTemplate.class),
            new ContainerConfigurationTemplate(),
            "sha256:unrelated-digest");