### Question:
ValidateUtil { public static void validate(Object obj) throws ValidationException { if (disableValidation) { return; } Errors errors = new BindException(obj, ""); Context.getAdministrationService().validate(obj, errors); if (errors.hasErrors()) { Set<String> uniqueErrorMessages = new LinkedHashSet<>(); for (Object objerr : errors.getAllErrors()) { ObjectError error = (ObjectError) objerr; String message = Context.getMessageSourceService().getMessage(error.getCode()); if (error instanceof FieldError) { message = ((FieldError) error).getField() + ": " + message; } uniqueErrorMessages.add(message); } String exceptionMessage = "'" + obj + "' failed to validate with reason: "; exceptionMessage += StringUtils.join(uniqueErrorMessages, ", "); throw new ValidationException(exceptionMessage, errors); } } private  ValidateUtil(); static void validate(Object obj); static void validate(Object obj, Errors errors); static void validateFieldLengths(Errors errors, Class<?> aClass, String... fields); static Boolean getDisableValidation(); static void setDisableValidation(Boolean disableValidation);  }### Answer:
@Test(expected = ValidationException.class) public void validate_shouldThrowValidationExceptionIfErrorsOccurDuringValidation() { Location loc = new Location(); ValidateUtil.validate(loc); }
@Test public void validate_shouldThrowAPIExceptionIfErrorsOccurDuringValidation() { Location loc = new Location(); try { ValidateUtil.validate(loc); } catch (ValidationException validationException) { assertNotNull(validationException.getErrors()); assertTrue(validationException.getErrors().hasErrors()); } }
@Test public void validate_shouldPopulateErrorsIfObjectInvalid() { Location loc = new Location(); Errors errors = new BindException(loc, ""); ValidateUtil.validate(loc, errors); assertTrue(errors.hasErrors()); }