### Question:
AzureManagedImageService { public Optional<VirtualMachineCustomImage> findVirtualMachineCustomImage(String resourceGroup, String imageName, AzureClient client) { VirtualMachineCustomImage image = findImage(resourceGroup, imageName, client); if (image != null) { LOGGER.debug("Custom image {} is present in resource group {}", imageName, resourceGroup); return Optional.of(image); } else { LOGGER.debug("Custom image {} is not present in resource group {}", imageName, resourceGroup); return Optional.empty(); } }  Optional<VirtualMachineCustomImage> findVirtualMachineCustomImage(String resourceGroup, String imageName, AzureClient client);  }### Answer:
@Test public void testGetVirtualMachineCustomImageShouldReturnTheImageWhenExistsOnProviderSide() { VirtualMachineCustomImage image = Mockito.mock(VirtualMachineCustomImage.class); Azure azure = PowerMockito.mock(Azure.class); when(azureClient.getAzure()).thenReturn(azure); when(azure.virtualMachineCustomImages()).thenReturn(virtualMachineCustomImages); when(virtualMachineCustomImages.getByResourceGroup(RESOURCE_GROUP, IMAGE_NAME)).thenReturn(image); Optional<VirtualMachineCustomImage> actual = underTest.findVirtualMachineCustomImage(RESOURCE_GROUP, IMAGE_NAME, azureClient); assertTrue(actual.isPresent()); assertEquals(image, actual.get()); verify(azureClient).getAzure(); verify(azure).virtualMachineCustomImages(); verify(virtualMachineCustomImages).getByResourceGroup(RESOURCE_GROUP, IMAGE_NAME); }
@Test public void testGetVirtualMachineCustomImageShouldReturnTheImageWhenDoesNotExistsOnProviderSide() { Azure azure = PowerMockito.mock(Azure.class); when(azureClient.getAzure()).thenReturn(azure); when(azure.virtualMachineCustomImages()).thenReturn(virtualMachineCustomImages); when(virtualMachineCustomImages.getByResourceGroup(RESOURCE_GROUP, IMAGE_NAME)).thenReturn(null); Optional<VirtualMachineCustomImage> actual = underTest.findVirtualMachineCustomImage(RESOURCE_GROUP, IMAGE_NAME, azureClient); assertTrue(actual.isEmpty()); verify(azureClient).getAzure(); verify(azure).virtualMachineCustomImages(); verify(virtualMachineCustomImages).getByResourceGroup(RESOURCE_GROUP, IMAGE_NAME); }