### Question:
PushBlobStep implements Callable<BlobDescriptor> { @Override public BlobDescriptor call() throws IOException, RegistryException { EventHandlers eventHandlers = buildContext.getEventHandlers(); DescriptorDigest blobDigest = blobDescriptor.getDigest(); try (ProgressEventDispatcher progressEventDispatcher = progressEventDispatcherFactory.create( "pushing blob " + blobDigest, blobDescriptor.getSize()); TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, DESCRIPTION + blobDescriptor); ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(progressEventDispatcher::dispatchProgress)) { if (!forcePush && registryClient.checkBlob(blobDigest).isPresent()) { eventHandlers.dispatch( LogEvent.info( "Skipping push; BLOB already exists on target registry : " + blobDescriptor)); return blobDescriptor; } String baseRegistry = buildContext.getBaseImageConfiguration().getImageRegistry(); String baseRepository = buildContext.getBaseImageConfiguration().getImageRepository(); String targetRegistry = buildContext.getTargetImageConfiguration().getImageRegistry(); String sourceRepository = targetRegistry.equals(baseRegistry) ? baseRepository : null; registryClient.pushBlob(blobDigest, blob, sourceRepository, throttledProgressReporter); return blobDescriptor; } } PushBlobStep(
      BuildContext buildContext,
      ProgressEventDispatcher.Factory progressEventDispatcherFactory,
      RegistryClient registryClient,
      BlobDescriptor blobDescriptor,
      Blob blob,
      boolean forcePush); @Override BlobDescriptor call();  }### Answer:
@Test public void testCall_doBlobCheckAndBlobExists() throws IOException, RegistryException { Mockito.when(registryClient.checkBlob(Mockito.any())).thenReturn(Optional.of(blobDescriptor)); call(false); Mockito.verify(registryClient).checkBlob(Mockito.any()); Mockito.verify(registryClient, Mockito.never()) .pushBlob(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); }
@Test public void testCall_doBlobCheckAndBlobDoesNotExist() throws IOException, RegistryException { Mockito.when(registryClient.checkBlob(Mockito.any())).thenReturn(Optional.empty()); call(false); Mockito.verify(registryClient).checkBlob(Mockito.any()); Mockito.verify(registryClient) .pushBlob(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); }
@Test public void testCall_forcePushWithNoBlobCheck() throws IOException, RegistryException { call(true); Mockito.verify(registryClient, Mockito.never()).checkBlob(Mockito.any()); Mockito.verify(registryClient) .pushBlob(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); }