### Question:
RangerServiceDefValidator extends RangerValidator { boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidResources(%s, %s)", serviceDef, failures)); } boolean valid = true; List<RangerResourceDef> resources = serviceDef.getResources(); if (CollectionUtils.isEmpty(resources)) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("resources") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("resources")) .build()); valid = false; } else { Set<String> names = new HashSet<String>(resources.size()); Set<Long> ids = new HashSet<Long>(resources.size()); for (RangerResourceDef resource : resources) { valid = isUnique(resource.getName(), names, "resource name", "resources", failures) && valid; valid = isUnique(resource.getItemId(), ids, "resource itemId", "resources", failures) && valid; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidResources(%s, %s): %s", serviceDef, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action);  }### Answer:
@Test public final void test_isValidResources() { when(_serviceDef.getResources()).thenReturn(null); _failures.clear(); assertFalse(_validator.isValidResources(_serviceDef, _failures)); _utils.checkFailureForMissingValue(_failures, "resources"); List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>(); when(_serviceDef.getResources()).thenReturn(resources); _failures.clear(); assertFalse(_validator.isValidResources(_serviceDef, _failures)); _utils.checkFailureForMissingValue(_failures, "resources"); resources.addAll(_utils.createResourceDefsWithIds(invalidResources)); _failures.clear(); assertFalse(_validator.isValidResources(_serviceDef, _failures)); _utils.checkFailureForMissingValue(_failures, "resource name"); _utils.checkFailureForMissingValue(_failures, "resource itemId"); _utils.checkFailureForSemanticError(_failures, "resource itemId", "1"); _utils.checkFailureForSemanticError(_failures, "resource name", "DataBase"); }
@Test public final void test_isValidResources_happyPath() { Object[][] data = new Object[][] { { 1L, -10, "database" }, { 3L, 0, "table" }, { 5L, 10, "column" }, }; List<RangerResourceDef> resources = _utils.createResourceDefsWithIds(data); when(_serviceDef.getResources()).thenReturn(resources); assertTrue(_validator.isValidResources(_serviceDef, _failures)); assertTrue(_failures.isEmpty()); }