### Question:
AlertValidator { public void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType) { Set<String> supportedHostGroups = Optional.ofNullable( recommendationService.getAutoscaleRecommendations(cluster.getStackCrn())).map( recommendation -> { if (AlertType.LOAD.equals(alertType)) { return Optional.ofNullable(recommendation.getLoadBasedHostGroups()).orElse(Set.of()); } if (AlertType.TIME.equals(alertType)) { return Optional.ofNullable(recommendation.getTimeBasedHostGroups()).orElse(Set.of()); } return Set.of(""); }).orElse(Set.of("")); if (!supportedHostGroups.containsAll(requestHostGroups)) { throw new BadRequestException(messagesService.getMessage(MessageCode.UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, alertType, cluster.getStackName(), supportedHostGroups))); } }  void validateEntitlementAndDisableIfNotEntitled(Cluster cluster); void validateSupportedHostGroup(Cluster cluster, Set<String> requestHostGroups, AlertType alertType); void validateDistroXAutoscaleClusterRequest(Cluster cluster,
            DistroXAutoscaleClusterRequest distroXAutoscaleClusterRequest); void validateSchedule(TimeAlertRequest json);  }### Answer:
@Test public void testLoadAlertCreateWhenHostGroupNotSupported() { Set requestHostGroups = Set.of("compute", "compute1"); Set supportedHostGroups = Set.of("compute1"); when(recommendationService.getAutoscaleRecommendations(anyString())) .thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups)); when(messagesService.getMessage(UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, AlertType.LOAD, aCluster.getStackName(), supportedHostGroups))) .thenReturn("unsupported.hostgroup"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("unsupported.hostgroup"); underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.LOAD); }
@Test public void testTimeAlertCreateWhenHostGroupNotSupported() { Set requestHostGroups = Set.of("compute", "compute1"); Set supportedHostGroups = Set.of("compute1"); when(recommendationService.getAutoscaleRecommendations(anyString())) .thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups)); when(messagesService.getMessage(UNSUPPORTED_AUTOSCALING_HOSTGROUP, List.of(requestHostGroups, AlertType.TIME, aCluster.getStackName(), supportedHostGroups))) .thenReturn("unsupported.hostgroup"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("unsupported.hostgroup"); underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.TIME); }
@Test public void testLoadAlertCreateWhenHostGroupSupported() { Set requestHostGroups = Set.of("compute", "compute1"); Set supportedHostGroups = Set.of("compute", "compute1", "compute3"); when(recommendationService.getAutoscaleRecommendations(anyString())) .thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups)); underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.LOAD); }
@Test public void testTimeAlertCreateWhenHostGroupSupported() { Set requestHostGroups = Set.of("compute", "compute1"); Set supportedHostGroups = Set.of("compute", "compute1"); when(recommendationService.getAutoscaleRecommendations(anyString())) .thenReturn(new AutoscaleRecommendationV4Response(supportedHostGroups, supportedHostGroups)); underTest.validateSupportedHostGroup(aCluster, requestHostGroups, AlertType.TIME); }