### Question:
AwsUpdateService { public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { ArrayList<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>(); if (!resources.isEmpty() && resources.stream().anyMatch(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE)))) { List<CloudResource> launchConfigurationResources = resources.stream() .filter(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE))).collect(Collectors.toList()); CloudResource cfResource = resources.stream().filter(resource -> ResourceType.CLOUDFORMATION_STACK == resource.getType()).findFirst().orElseThrow(); awsImageUpdateService.updateImage(authenticatedContext, stack, cfResource); launchConfigurationResources.forEach(cloudResource -> cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, ResourceStatus.UPDATED))); } return cloudResourceStatuses; }  List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources);  }### Answer:
@Test public void updateCloudFormationTemplateResourceWithImageParameter() { CloudResource cloudResource = CloudResource.builder() .name("cf") .type(ResourceType.CLOUDFORMATION_STACK) .params(Collections.singletonMap(CloudResource.IMAGE, "dummy")) .build(); List<CloudResourceStatus> statuses = underTest.update(ac, stack, Collections.singletonList(cloudResource)); verify(awsImageUpdateService, times(1)).updateImage(ac, stack, cloudResource); assertEquals(1, statuses.size()); assertEquals(ResourceStatus.UPDATED, statuses.get(0).getStatus()); assertEquals(cloudResource, statuses.get(0).getCloudResource()); }
@Test public void updateCloudFormationTemplateResourceWithoutImageParameter() { CloudResource cloudResource = CloudResource.builder() .name("cf") .type(ResourceType.CLOUDFORMATION_STACK) .build(); List<CloudResourceStatus> statuses = underTest.update(ac, stack, Collections.singletonList(cloudResource)); verify(awsImageUpdateService, times(0)).updateImage(ac, stack, cloudResource); assertEquals(0, statuses.size()); }
@Test public void updateRandomResource() { CloudResource cloudResource = CloudResource.builder() .name("cf") .type(ResourceType.AWS_LAUNCHCONFIGURATION) .params(Collections.singletonMap(CloudResource.IMAGE, "dummy")) .build(); List<CloudResourceStatus> statuses = underTest.update(ac, stack, Collections.singletonList(cloudResource)); verify(awsImageUpdateService, times(0)).updateImage(ac, stack, cloudResource); assertEquals(0, statuses.size()); }