### Question:
ImageService { public Image getImage(ImageSettingsRequest imageSettings, String region, String platform) { String imageId = imageSettings.getId(); String catalogUrl = Objects.nonNull(imageSettings.getCatalog()) ? imageSettings.getCatalog() : defaultCatalogUrl; String imageOs = Objects.nonNull(imageSettings.getOs()) ? imageSettings.getOs() : defaultOs; ImageCatalog cachedImageCatalog = imageCatalogProvider.getImageCatalog(catalogUrl); return findImageForAppVersion(region, platform, imageId, imageOs, cachedImageCatalog) .or(() -> retryAfterEvictingCache(region, platform, imageId, catalogUrl, imageOs)) .orElseThrow(() -> throwImageNotFoundException(region, imageId, imageOs)); }  ImageEntity create(Stack stack, ImageSettingsRequest imageRequest); ImageEntity getByStack(Stack stack); ImageEntity getByStackId(Long stackId); ImageEntity decorateImageWithUserDataForStack(Stack stack, String userdata); Image getImage(ImageSettingsRequest imageSettings, String region, String platform); String determineImageName(String platformString, String region, Image imgFromCatalog);  }### Answer:
@Test public void testGetImageGivenNoInputWithInvalidAppVersion() { ReflectionTestUtils.setField(underTest, ImageService.class, "freeIpaVersion", "2.21.0-dcv.1", null); ImageSettingsRequest is = setupImageSettingsRequest(null, null, "centos7"); Image image = underTest.getImage(is, DEFAULT_REGION, DEFAULT_PLATFORM); assertEquals("centos7", image.getOs()); assertEquals("Assuming the latest image to be selected", "2019-05-09", image.getDate()); assertEquals("91851893-8340-411d-afb7-e1b55107fb10", image.getUuid()); }
@Test public void testGetImageGivenAllInput() { ImageSettingsRequest is = setupImageSettingsRequest(EXISTING_ID, CUSTOM_IMAGE_CATALOG_URL, DEFAULT_OS); Image image = underTest.getImage(is, DEFAULT_REGION, DEFAULT_PLATFORM); assertEquals(DEFAULT_OS, image.getOs()); assertEquals("Assuming the latest image to be selected", LATEST_DATE, image.getDate()); assertEquals("61851893-8340-411d-afb7-e1b55107fb10", image.getUuid()); }
@Test public void testGetImageGivenAllInputNonExistentOS() { ImageSettingsRequest is = setupImageSettingsRequest(EXISTING_ID, CUSTOM_IMAGE_CATALOG_URL, NON_EXISTING_OS); Image image = underTest.getImage(is, DEFAULT_REGION, DEFAULT_PLATFORM); assertEquals(DEFAULT_OS, image.getOs()); assertEquals("Assuming the latest image to be selected", LATEST_DATE, image.getDate()); assertEquals("61851893-8340-411d-afb7-e1b55107fb10", image.getUuid()); }
@Test public void testGetImageGivenIdInputFound() { ImageSettingsRequest is = setupImageSettingsRequest(EXISTING_ID, null, null); Image image = underTest.getImage(is, DEFAULT_REGION, DEFAULT_PLATFORM); assertEquals(DEFAULT_OS, image.getOs()); assertEquals("Assuming the latest image to be selected", LATEST_DATE, image.getDate()); assertEquals("61851893-8340-411d-afb7-e1b55107fb10", image.getUuid()); }
@Test public void testGetImageGivenIdInputNotFound() { ImageSettingsRequest is = setupImageSettingsRequest(NON_EXISTING_ID, null, null); Exception exception = assertThrows(RuntimeException.class, () -> underTest.getImage(is, DEFAULT_REGION, DEFAULT_PLATFORM)); String exceptionMessage = "Could not find any image with id: 'fake-ami-0a6931aea1415eb0e' in region 'eu-west-1' with OS 'redhat7'."; assertEquals(exceptionMessage, exception.getMessage()); }