DynamicResourceBundleConstraintDescriptionResolver implements ConstraintDescriptionResolver { @Override public String resolveDescription(Constraint constraint) { String message = (String) constraint.getConfiguration().get("message"); if (isNotBlank(message) && !message.startsWith("{")) { return this.propertyPlaceholderHelper.replacePlaceholders(message, new ConstraintPlaceholderResolver(constraint)); } try { String key = constraint.getName() + ".description"; return this.propertyPlaceholderHelper.replacePlaceholders(getDescription(key), new ConstraintPlaceholderResolver(constraint)); } catch (MissingResourceException e) { log.debug("No description found for constraint {}: {}.", constraint.getName(), e.getMessage()); return ""; } } DynamicResourceBundleConstraintDescriptionResolver();  DynamicResourceBundleConstraintDescriptionResolver(ResourceBundle resourceBundle); @Override String resolveDescription(Constraint constraint);  }
@Test public void descriptionIsResolvedFromAnnotationMessage() { Map<String, Object> configuration = new HashMap<>(); configuration.put("message", "Must be it"); Constraint constraint = new Constraint("test.Constraint1", configuration); String description = resolver.resolveDescription(constraint); assertThat(description).isEqualTo("Must be it"); }
@Test public void descriptionIsResolvedFromResource() { Map<String, Object> configuration = new HashMap<>(); Constraint constraint = new Constraint("test.Constraint2", configuration); String description = resolver.resolveDescription(constraint); assertThat(description).isEqualTo("Must be limited"); }
@Test public void descriptionIsNotResolved() { Map<String, Object> configuration = new HashMap<>(); Constraint constraint = new Constraint("test.Constraint3", configuration); String description = resolver.resolveDescription(constraint); assertThat(description).isEmpty(); }