### Question:
RangerPolicyValidator extends RangerValidator { boolean isValidResourceValues(Map<String, RangerPolicyResource> resourceMap, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValidResourceValues(%s, %s, %s)", resourceMap, failures, serviceDef)); } boolean valid = true; Map<String, String> validationRegExMap = getValidationRegExes(serviceDef); for (Map.Entry<String, RangerPolicyResource> entry : resourceMap.entrySet()) { String name = entry.getKey(); RangerPolicyResource policyResource = entry.getValue(); if(policyResource != null && CollectionUtils.isNotEmpty(policyResource.getValues())){ Set<String> resources = new HashSet<String>(policyResource.getValues()); for (String aValue : resources) { if (StringUtils.isBlank(aValue)) { policyResource.getValues().remove(aValue); } } } if(CollectionUtils.isEmpty(policyResource.getValues())){ ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_RESOURCE_LIST; if(LOG.isDebugEnabled()) { LOG.debug(String.format("Resource list was empty or contains null: value[%s], resource-name[%s], service-def-name[%s]", policyResource.getValues(), name, serviceDef.getName())); } failures.add(new ValidationFailureDetailsBuilder() .field("resource-values") .subField(name) .isMissing() .becauseOf(error.getMessage(name)) .errorCode(error.getErrorCode()) .build()); valid=false; } if (validationRegExMap.containsKey(name) && policyResource != null && CollectionUtils.isNotEmpty(policyResource.getValues())) { String regEx = validationRegExMap.get(name); for (String aValue : policyResource.getValues()) { if (StringUtils.isBlank(aValue)) { LOG.debug("resource value was blank"); } else if (!aValue.matches(regEx)) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Resource failed regex check: value[%s], resource-name[%s], regEx[%s], service-def-name[%s]", aValue, name, regEx, serviceDef.getName())); } ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_INVALID_RESOURCE_VALUE_REGEX; failures.add(new ValidationFailureDetailsBuilder() .field("resource-values") .subField(name) .isSemanticallyIncorrect() .becauseOf(error.getMessage(aValue, name)) .errorCode(error.getErrorCode()) .build()); valid = false; } } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValidResourceValues(%s, %s, %s): %s", resourceMap, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin);  }### Answer:
@Test public void test_isValidResourceValues() { List<RangerResourceDef> resourceDefs = _utils.createResourceDefs(resourceDefData); when(_serviceDef.getResources()).thenReturn(resourceDefs); Map<String, RangerPolicyResource> policyResources = _utils.createPolicyResourceMap(policyResourceMap_bad); assertFalse(_validator.isValidResourceValues(policyResources, _failures, _serviceDef)); _utils.checkFailureForSemanticError(_failures, "resource-values", "col"); policyResources = _utils.createPolicyResourceMap(policyResourceMap_good); assertTrue(_validator.isValidResourceValues(policyResources, _failures, _serviceDef)); }