### Question:
RangerServiceDefValidator extends RangerValidator { boolean isValid(final Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceDefValidator.isValid(" + id + ")"); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(action)) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("id")) .build()); valid = false; } else if (getServiceDef(id) == null) { if (LOG.isDebugEnabled()) { LOG.debug("No service found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceDefValidator.isValid(" + id + "): " + valid); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action);  }### Answer:
@Test public final void testIsValid_Long_failures() throws Exception { Long id = null; boolean result = _validator.isValid((Long)null, Action.CREATE, _failures); assertFalse(result); _utils.checkFailureForInternalError(_failures); _failures.clear(); assertFalse(_validator.isValid((Long)null, Action.DELETE, _failures)); _utils.checkFailureForMissingValue(_failures, "id"); id = 3L; when(_store.getServiceDef(id)).thenReturn(null); _failures.clear(); assertTrue(_validator.isValid(id, Action.DELETE, _failures)); assertTrue(_failures.isEmpty()); when(_store.getServiceDef(id)).thenReturn(_serviceDef); _failures.clear(); assertTrue(_validator.isValid(id, Action.DELETE, _failures)); assertTrue(_failures.isEmpty()); }
@Test public final void testIsValid_failures() throws Exception { for (Action action : cu) { assertFalse(_validator.isValid((RangerServiceDef)null, action, _failures)); _utils.checkFailureForMissingValue(_failures, "service def"); } }