BootstrapConfigFormValidator implements Validator { @Override public void validate(Object target, Errors errors) { if (target instanceof PlatformStatus) { return; } String dbUrlField = "sqlUrl"; String dbDriverField = "sqlDriver"; validateEmptyOrWhitespace(errors, ERROR_REQUIRED, dbUrlField); validateEmptyOrWhitespace(errors, ERROR_REQUIRED, dbDriverField); String configSource = ((BootstrapConfigForm) target).getConfigSource(); if (!ConfigSource.isValid(configSource)) { errors.rejectValue(configSource, "server.error.invalid.configSource"); } }  @Override boolean supports(Class<?> clazz); @Override void validate(Object target, Errors errors);  }
@Test public void shouldValidateOnlyForEmptyFields() { bootstrapConfigFormValidator.validate(new BootstrapConfigForm(), errors); verifyStatic(); ValidationUtils.validateEmptyOrWhitespace(errors, ERROR_REQUIRED, "sqlUrl"); }
@Test public void shouldValidateForConfigSource(){ when(errors.hasFieldErrors("sqlUrl")).thenReturn(false); when(errors.getFieldValue("sqlbUrl")).thenReturn("jdbc: BootstrapConfigForm bootstrapConfigForm = new BootstrapConfigForm(); bootstrapConfigForm.setConfigSource("invalid"); bootstrapConfigFormValidator.validate(bootstrapConfigForm, errors); verify(errors).rejectValue("invalid", "server.error.invalid.configSource"); }