### Question:
AwsLaunchConfigurationImageUpdateService { public void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource) { AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential()); String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName(); AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName); AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName); Map<String, String> encryptedImages = getEncryptedImagesMappedByAutoscalingGroupName(authenticatedContext, stack); Map<AutoScalingGroup, String> scalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource); List<LaunchConfiguration> oldLaunchConfigurations = launchConfigurationHandler.getLaunchConfigurations(autoScalingClient, scalingGroups.keySet()); for (LaunchConfiguration oldLaunchConfiguration : oldLaunchConfigurations) { changeImageInAutoscalingGroup(authenticatedContext, stack, autoScalingClient, scalingGroups, encryptedImages, oldLaunchConfiguration); } }  void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource);  }### Answer:
@Test public void shouldUpdateImage() { String lcName = "lcName"; CloudResource cfResource = CloudResource.builder() .type(ResourceType.CLOUDFORMATION_STACK) .name("cf") .build(); String autoScalingGroupName = "autoScalingGroupName"; Map<AutoScalingGroup, String> scalingGroupStringMap = Collections.singletonMap(new AutoScalingGroup().withLaunchConfigurationName(lcName) .withAutoScalingGroupName(autoScalingGroupName), autoScalingGroupName); when(cloudFormationClient.getTemplate(any())).thenReturn(new GetTemplateResult().withTemplateBody("AWS::AutoScaling::LaunchConfiguration")); when(autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource)) .thenReturn(scalingGroupStringMap); List<LaunchConfiguration> oldLaunchConfigs = Collections.singletonList(new LaunchConfiguration().withLaunchConfigurationName(lcName)); when(launchConfigurationHandler.getLaunchConfigurations(autoScalingClient, scalingGroupStringMap.keySet())) .thenReturn(oldLaunchConfigs); String newLCName = "newLCName"; when(launchConfigurationHandler.createNewLaunchConfiguration(eq("imageName"), eq(autoScalingClient), eq(oldLaunchConfigs.get(0)), eq(ac.getCloudContext()), eq(null))).thenReturn(newLCName); underTest.updateImage(ac, stack, cfResource); verify(autoScalingGroupHandler, times(1)).getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource); verify(launchConfigurationHandler, times(1)).getLaunchConfigurations(autoScalingClient, scalingGroupStringMap.keySet()); verify(launchConfigurationHandler, times(1)).createNewLaunchConfiguration(anyString(), eq(autoScalingClient), eq(oldLaunchConfigs.get(0)), eq(ac.getCloudContext()), eq(null)); verify(autoScalingGroupHandler, times(1)).updateAutoScalingGroupWithLaunchConfiguration(autoScalingClient, autoScalingGroupName, oldLaunchConfigs.get(0), newLCName); verify(launchConfigurationHandler, times(1)).removeOldLaunchConfiguration(oldLaunchConfigs.get(0), autoScalingClient, ac.getCloudContext()); }