### Question:
ImageBasedDefaultCDHEntries { public Map<String, ImageBasedDefaultCDHInfo> getEntries(Long workspaceId, String platform, String imageCatalogName) throws CloudbreakImageCatalogException { String catalogName = Optional.ofNullable(imageCatalogName).orElse(ImageCatalogService.CDP_DEFAULT_CATALOG_NAME); StatedImages images = imageCatalogService.getImages(workspaceId, catalogName, platform); if (images.getImages().getCdhImages().isEmpty()) { LOGGER.warn("Missing CDH images for cloud platform: {}. Falling back to AWS.", platform); images = imageCatalogService.getImages(workspaceId, catalogName, CloudPlatform.AWS.name()); } return getEntries(images.getImages()); }  Map<String, ImageBasedDefaultCDHInfo> getEntries(Long workspaceId, String platform, String imageCatalogName); Map<String, ImageBasedDefaultCDHInfo> getEntries(Images images); static final Comparator<Map.Entry<String, ImageBasedDefaultCDHInfo>> IMAGE_BASED_CDH_ENTRY_COMPARATOR; }### Answer:
@Test public void shouldReturnImageBasedDefaultCDHInfoMapByDefaultCdhImages() { List<Image> imageList = getImages(); when(images.getCdhImages()).thenReturn(imageList); Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(images); Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get(); verify(image, actual.get(IMAGE_VERSION)); }
@Test public void shouldReturnImageBasedDefaultCDHInfoMapByPlatformAndImageCatalog() throws CloudbreakImageCatalogException { List<Image> imageList = getImages(); when(images.getCdhImages()).thenReturn(imageList); StatedImages statedImages = StatedImages.statedImages(images, null, null); when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, PLATFORM)).thenReturn(statedImages); Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(0L, PLATFORM, IMAGE_CATALOG_NAME); Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get(); verify(image, actual.get(IMAGE_VERSION)); }
@Test public void shouldFallBackToAwsInCaseOfMissingCdhImages() throws CloudbreakImageCatalogException { List<Image> imageList = getImages(); when(images.getCdhImages()).thenReturn(imageList); when(emptyImages.getCdhImages()).thenReturn(Collections.emptyList()); StatedImages statedImages = StatedImages.statedImages(images, null, null); StatedImages emptyStatedImages = StatedImages.statedImages(emptyImages, null, null); when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, CloudPlatform.YARN.name())).thenReturn(emptyStatedImages); when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, PLATFORM)).thenReturn(statedImages); Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(0L, CloudPlatform.YARN.name(), IMAGE_CATALOG_NAME); Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get(); verify(image, actual.get(IMAGE_VERSION)); }