### Question:
AwsImageUpdateService { public void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource) { String cfTemplate = stack.getTemplate(); if (cfTemplate.contains("AWS::AutoScaling::LaunchConfiguration")) { awsLaunchConfigurationImageUpdateService.updateImage(authenticatedContext, stack, cfResource); } else if (cfTemplate.contains("AWS::EC2::LaunchTemplate")) { awsLaunchTemplateImageUpdateService.updateImage(authenticatedContext, stack, cfResource); } else { throw new NotImplementedException("Image update for stack template is not implemented yet."); } }  void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource);  }### Answer:
@Test void shouldUpdateImageInLaunchConfiguration() { Mockito.when(stack.getTemplate()).thenReturn("AWS::AutoScaling::LaunchConfiguration"); underTest.updateImage(ac, stack, cfResource); verify(awsLaunchConfigurationImageUpdateService).updateImage(ac, stack, cfResource); verify(awsLaunchTemplateImageUpdateService, never()).updateImage(ac, stack, cfResource); }
@Test void shouldUpdateImageInLaunchTemplate() { Mockito.when(stack.getTemplate()).thenReturn("AWS::EC2::LaunchTemplate"); underTest.updateImage(ac, stack, cfResource); verify(awsLaunchTemplateImageUpdateService).updateImage(ac, stack, cfResource); verify(awsLaunchConfigurationImageUpdateService, never()).updateImage(ac, stack, cfResource); }
@Test void shouldThrowExceptionWhenTemplateDoesNotMatchNeither() { Mockito.when(stack.getTemplate()).thenReturn("gibberish"); Assertions.assertThrows(NotImplementedException.class, () -> underTest.updateImage(ac, stack, cfResource)); verify(awsLaunchTemplateImageUpdateService, never()).updateImage(ac, stack, cfResource); verify(awsLaunchConfigurationImageUpdateService, never()).updateImage(ac, stack, cfResource); }