use of org.springframework.validation.FieldError in project spring-boot by spring-projects.
the class ValidationErrorsTests method getErrorsShouldAdaptFieldErrorsToBeOriginProviders.
@Test
void getErrorsShouldAdaptFieldErrorsToBeOriginProviders() {
Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
ConfigurationPropertyName name1 = ConfigurationPropertyName.of("foo.bar");
Origin origin1 = MockOrigin.of("line1");
boundProperties.add(new ConfigurationProperty(name1, "boot", origin1));
ConfigurationPropertyName name2 = ConfigurationPropertyName.of("foo.baz.bar");
Origin origin2 = MockOrigin.of("line2");
boundProperties.add(new ConfigurationProperty(name2, "boot", origin2));
List<ObjectError> allErrors = new ArrayList<>();
allErrors.add(new FieldError("objectname", "bar", "message"));
ValidationErrors errors = new ValidationErrors(ConfigurationPropertyName.of("foo.baz"), boundProperties, allErrors);
assertThat(Origin.from(errors.getAllErrors().get(0))).isEqualTo(origin2);
}
use of org.springframework.validation.FieldError in project spring-boot by spring-projects.
the class BindValidationFailureAnalyzerTests method otherBindExceptionShouldReturnAnalysis.
@Test
void otherBindExceptionShouldReturnAnalysis() {
BindException cause = new BindException(new FieldValidationFailureProperties(), "fieldValidationFailureProperties");
cause.addError(new FieldError("test", "value", "must not be null"));
BeanCreationException rootFailure = new BeanCreationException("bean creation failure", cause);
FailureAnalysis analysis = new BindValidationFailureAnalyzer().analyze(rootFailure, rootFailure);
assertThat(analysis.getDescription()).contains(failure("test.value", "null", "must not be null"));
}
Aggregations