### Question:
StackImageUpdateService { public boolean isValidImage(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) { if (isCbVersionOk(stack)) { try { Image currentImage = getCurrentImage(stack); StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage); boolean cloudPlatformMatches = isCloudPlatformMatches(stack, newImage); boolean osVersionsMatch = isOsVersionsMatch(currentImage, newImage); boolean stackMatchIfPrewarmed = isStackMatchIfPrewarmed(newImage); CheckResult status = checkPackageVersions(stack, newImage); boolean aggregatedValidationResult = cloudPlatformMatches && osVersionsMatch && stackMatchIfPrewarmed && status.getStatus() == EventStatus.OK; if (!aggregatedValidationResult) { LOGGER.info("Image validation for {}:\n " + "Valid platform? {}\n " + "Valid os? {}\n " + "Valid stack (prewarmed only)? {}\n " + "Valid package versions? {}", newImageId, cloudPlatformMatches, osVersionsMatch, stackMatchIfPrewarmed, status); } return aggregatedValidationResult; } catch (CloudbreakImageNotFoundException e) { LOGGER.debug("Cloudbreak Image not found", e); return false; } catch (CloudbreakImageCatalogException e) { LOGGER.debug("Cloudbreak Image catalog error", e); return false; } } return false; }  void storeNewImageComponent(Stack stack, StatedImage image); StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl); boolean isCbVersionOk(Stack stack); boolean isStackMatchIfPrewarmed(StatedImage image); CheckResult checkPackageVersions(Stack stack, StatedImage newImage); boolean isValidImage(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl); static final String MIN_VERSION; }### Answer:
@Test public void testIsValidImage() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { com.sequenceiq.cloudbreak.cloud.model.Image imageInComponent = new com.sequenceiq.cloudbreak.cloud.model.Image("imageOldName", Collections.emptyMap(), "centos7", "centos", statedImage.getImageCatalogUrl(), statedImage.getImageCatalogName(), "uuid2", packageVersions); when(componentConfigProviderService.getImage(anyLong())).thenReturn(imageInComponent); when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(statedImage); CloudbreakDetails cloudbreakDetails = new CloudbreakDetails(); cloudbreakDetails.setVersion(StackImageUpdateService.MIN_VERSION); when(componentConfigProviderService.getCloudbreakDetails(stack.getId())).thenReturn(cloudbreakDetails); boolean validImage = underTest.isValidImage(stack, "imageId", "imageCatalogName", "imageCatalogUrl"); assertTrue(validImage); }
@Test public void testIsValidImageFalse() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { com.sequenceiq.cloudbreak.cloud.model.Image imageInComponent = new com.sequenceiq.cloudbreak.cloud.model.Image("imageOldName", Collections.emptyMap(), "centos6", "centos", statedImage.getImageCatalogUrl(), statedImage.getImageCatalogName(), "uuid2", packageVersions); when(componentConfigProviderService.getImage(anyLong())).thenReturn(imageInComponent); when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(statedImage); CloudbreakDetails cloudbreakDetails = new CloudbreakDetails(); cloudbreakDetails.setVersion("2.4.0"); when(componentConfigProviderService.getCloudbreakDetails(stack.getId())).thenReturn(cloudbreakDetails); boolean validImage = underTest.isValidImage(stack, "imageId", "imageCatalogName", "imageCatalogUrl"); assertFalse(validImage); }