### Question:
BuildManifestListOrSingleManifestStep implements Callable<ManifestTemplate> { @Override public ManifestTemplate call() throws IOException { Preconditions.checkState(!builtImages.isEmpty(), "no images given"); EventHandlers eventHandlers = buildContext.getEventHandlers(); try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION); ProgressEventDispatcher ignored2 = progressEventDispatcherFactory.create( "building a manifest list or a single manifest", 1)) { if (builtImages.size() == 1) { eventHandlers.dispatch(LogEvent.info("Building a single manifest")); ImageToJsonTranslator imageTranslator = new ImageToJsonTranslator(builtImages.get(0)); BlobDescriptor configDescriptor = Digests.computeDigest(imageTranslator.getContainerConfiguration()); return imageTranslator.getManifestTemplate( buildContext.getTargetFormat(), configDescriptor); } eventHandlers.dispatch(LogEvent.info("Building a manifest list")); return new ManifestListGenerator(builtImages) .getManifestListTemplate(buildContext.getTargetFormat()); } } BuildManifestListOrSingleManifestStep(
      BuildContext buildContext,
      ProgressEventDispatcher.Factory progressEventDispatcherFactory,
      List<Image> builtImages); @Override ManifestTemplate call();  }### Answer:
@Test public void testCall_singleManifest() throws IOException { ManifestTemplate manifestTemplate = new BuildManifestListOrSingleManifestStep( buildContext, progressDispatcherFactory, Arrays.asList(image1)) .call(); Assert.assertTrue(manifestTemplate instanceof V22ManifestTemplate); V22ManifestTemplate manifest = (V22ManifestTemplate) manifestTemplate; Assert.assertEquals(2, manifest.getSchemaVersion()); Assert.assertEquals( "application/vnd.docker.distribution.manifest.v2+json", manifest.getManifestMediaType()); Assert.assertEquals( "sha256:1b2ff280940537177565443144a81319ad48528fd35d1cdc38cbde07f24f6912", manifest.getContainerConfiguration().getDigest().toString()); Assert.assertEquals(0, manifest.getLayers().get(0).getSize()); Assert.assertEquals(158, manifest.getContainerConfiguration().getSize()); }
@Test public void testCall_manifestList() throws IOException { ManifestTemplate manifestTemplate = new BuildManifestListOrSingleManifestStep( buildContext, progressDispatcherFactory, Arrays.asList(image1, image2)) .call(); Assert.assertTrue(manifestTemplate instanceof V22ManifestListTemplate); V22ManifestListTemplate manifestList = (V22ManifestListTemplate) manifestTemplate; Assert.assertEquals(2, manifestList.getSchemaVersion()); Assert.assertEquals( Arrays.asList("sha256:9467fc431ac5dd84dafdc13f75111fc467cd57aff4732edda8c9e0bbcabe0183"), manifestList.getDigestsForPlatform("amd64", "linux")); Assert.assertEquals( Arrays.asList("sha256:439351c848845c46a3952f28416992b66003361d00943b6cdb04b6d5533f02bf"), manifestList.getDigestsForPlatform("arm64", "windows")); }
@Test public void testCall_emptyImagesList() throws IOException { try { new BuildManifestListOrSingleManifestStep( buildContext, progressDispatcherFactory, Collections.emptyList()) .call(); Assert.fail(); } catch (IllegalStateException ex) { Assert.assertEquals("no images given", ex.getMessage()); } }