### Question:
AlertValidator { public void validateEntitlementAndDisableIfNotEntitled(Cluster cluster) { if (!entitlementValidationService.autoscalingEntitlementEnabled( ThreadBasedUserCrnProvider.getUserCrn(), ThreadBasedUserCrnProvider.getAccountId(), cluster.getCloudPlatform())) { if (cluster.getAutoscalingEnabled()) { asClusterCommonService.setAutoscaleState(cluster.getId(), false); } throw new BadRequestException(messagesService.getMessage(MessageCode.AUTOSCALING_ENTITLEMENT_NOT_ENABLED, List.of(cluster.getCloudPlatform(), cluster.getStackName()))); } }  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 testValidateEntitlementAndDisableIfNotEntitledWhenAccountNotEntitledForPlatform() { aCluster.setCloudPlatform("Yarn"); aCluster.setAutoscalingEnabled(false); when(entitlementValidationService.autoscalingEntitlementEnabled(ThreadBasedUserCrnProvider.getUserCrn(), ThreadBasedUserCrnProvider.getAccountId(), "Yarn")).thenReturn(false); when(messagesService.getMessage(AUTOSCALING_ENTITLEMENT_NOT_ENABLED, List.of(aCluster.getCloudPlatform(), aCluster.getStackName()))).thenReturn("account.not.entitled.for.platform"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("account.not.entitled.for.platform"); underTest.validateEntitlementAndDisableIfNotEntitled(aCluster); verify(asClusterCommonService, never()).setAutoscaleState(aCluster.getId(), false); }
@Test public void testValidateEntitlementAndDisableIfNotEntitledWhenAccountNotEntitledThenDisableAutoscaling() { aCluster.setCloudPlatform("AWS"); when(entitlementValidationService.autoscalingEntitlementEnabled(ThreadBasedUserCrnProvider.getUserCrn(), ThreadBasedUserCrnProvider.getAccountId(), "AWS")).thenReturn(false); when(messagesService.getMessage(AUTOSCALING_ENTITLEMENT_NOT_ENABLED, List.of(aCluster.getCloudPlatform(), aCluster.getStackName()))).thenReturn("account.not.entitled.for.platform"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("account.not.entitled.for.platform"); underTest.validateEntitlementAndDisableIfNotEntitled(aCluster); verify(asClusterCommonService, times(1)).setAutoscaleState(aCluster.getId(), false); }
@Test public void testValidateEntitlementAndDisableIfNotEntitledWhenAccountEntitledThenValidationSuccess() { aCluster.setCloudPlatform("AWS"); when(entitlementValidationService.autoscalingEntitlementEnabled(ThreadBasedUserCrnProvider.getUserCrn(), ThreadBasedUserCrnProvider.getAccountId(), "AWS")).thenReturn(true); underTest.validateEntitlementAndDisableIfNotEntitled(aCluster); verify(asClusterCommonService, never()).setAutoscaleState(aCluster.getId(), false); }