### Question:
EntitlementValidationService { @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") public boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform) { boolean entitled; Optional<String> platformEntitlement = Optional.ofNullable(PLATFORM_ENTITLEMENTS.get(cloudPlatform)); if (!entitlementCheckEnabled || platformEntitlement.map(entitlement -> ALLOWED.equals(entitlement)).orElse(false)) { entitled = true; } else if (platformEntitlement.isEmpty()) { entitled = false; } else { entitled = entitlementService.getEntitlements(userCrn, accountId) .stream().anyMatch(e -> e.equalsIgnoreCase(platformEntitlement.get())); } return entitled; }  @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform);  }### Answer:
@Test public void testWhenEntitlementCheckDisabledThenEntitled() { Whitebox.setInternalState(underTest, "entitlementCheckEnabled", false); boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "AWS"); assertTrue("entitled should be true when entitlementCheckDisabled", entitled); }
@Test public void testWhenAWSAndEntitled() { when(entitlementService.getEntitlements(anyString(), anyString())).thenReturn(List.of("DATAHUB_AWS_AUTOSCALING")); boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "AWS"); assertTrue("isEntitled should be true when entitlement found", entitled); }
@Test public void testWhenAWSAndNotEntitled() { when(entitlementService.getEntitlements(anyString(), anyString())).thenReturn(List.of("DATAHUB_AZURE_AUTOSCALING")); boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "AWS"); assertFalse("isEntitled should be false when entitlement is not found", entitled); }
@Test public void testWhenAzureAndEntitled() { when(entitlementService.getEntitlements(anyString(), anyString())).thenReturn(List.of("DATAHUB_AWS_AUTOSCALING", "DATAHUB_AZURE_AUTOSCALING")); boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "AZURE"); assertTrue("isEntitled should be true when entitlement found", entitled); }
@Test public void testWhenAzureAndNotEntitled() { when(entitlementService.getEntitlements(anyString(), anyString())).thenReturn(List.of()); boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "AZURE"); assertFalse("isEntitled should be false when entitlement is not found", entitled); }
@Test public void testWhenYarnAndAlwaysAllowed() { boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "YARN"); assertTrue("isEntitled should be true when entitlement always allowed", entitled); }
@Test public void testWhenGCPAndNotEntitled() { boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "GCP"); assertFalse("isEntitled should be false when entitlement is not defined", entitled); }