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

Code before:
    OciIndexTemplate manifestList =
        JsonTemplateMapper.readJson(manifestListJson, OciIndexTemplate.class);

    String manifestDigest =
        pullBaseImageStep.lookUpPlatformSpecificImageManifest(
            manifestList, new Platform("targetArchitecture", "targetOS"));

    Assert.assertEquals(
        "sha256:2222222222222222222222222222222222222222222222222222222222222222", manifestDigest);
  }

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

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

  @Test
  public void testGetCachedBaseImages_cachedWithoutAllLayers()
      throws InvalidImageReferenceException, CacheCorruptedException, IOException,
          LayerCountMismatchException, PlatformNotFoundInBaseImageException,
          BadContainerConfigurationFormatException, UnlistedPlatformInManifestListException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration())
        .thenReturn(ImageConfiguration.builder(imageReference).build());
    ManifestTemplate manifest = Mockito.mock(ManifestTemplate.class);
    ImageMetadataTemplate imageMetadata =
        new ImageMetadataTemplate(
            null, Arrays.asList(new ManifestAndConfigTemplate(manifest, null)));

    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(cache.allLayersCached(manifest)).thenReturn(false);

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

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

Review comment (performance):
What do you think of this? 

```suggestion
  public void testGetCachedBaseImages_partiallyCached_emptyListReturned()
```


Code after:

    OciIndexTemplate manifestList =
        JsonTemplateMapper.readJson(manifestListJson, OciIndexTemplate.class);

    String manifestDigest =
        pullBaseImageStep.lookUpPlatformSpecificImageManifest(
            manifestList, new Platform("targetArchitecture", "targetOS"));

    Assert.assertEquals(
        "sha256:2222222222222222222222222222222222222222222222222222222222222222", manifestDigest);
  }

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

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

  @Test
  public void testGetCachedBaseImages_partiallyCached_emptyListReturned()
      throws InvalidImageReferenceException, CacheCorruptedException, IOException,
          LayerCountMismatchException, PlatformNotFoundInBaseImageException,
          BadContainerConfigurationFormatException, UnlistedPlatformInManifestListException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration())
        .thenReturn(ImageConfiguration.builder(imageReference).build());
    ManifestTemplate manifest = Mockito.mock(ManifestTemplate.class);
    ImageMetadataTemplate imageMetadata =
        new ImageMetadataTemplate(
            null, Arrays.asList(new ManifestAndConfigTemplate(manifest, null)));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(cache.areAllLayersCached(manifest)).thenReturn(false);

    assertThat(pullBaseImageStep.getCachedBaseImages()).isEmpty();
  }

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