ConstraintReaderImpl implements ConstraintReader { @Override public List<String> getConstraintMessages(Class<?> javaBaseClass, String javaFieldName) { ConstraintDescriptions constraints = new ConstraintDescriptions(javaBaseClass, constraintResolver, constraintAndGroupDescriptionResolver); List<String> constraintMessages = new ArrayList<>(); constraintMessages.addAll(constraints.descriptionsForProperty(javaFieldName)); constraintMessages.addAll(getEnumConstraintMessage(javaBaseClass, javaFieldName)); return constraintMessages; } private  ConstraintReaderImpl(MethodParameterConstraintResolver actualResolver, ObjectMapper objectMapper, SnippetTranslationResolver translationResolver,
            ConstraintDescriptionResolver constraintDescriptionResolver); static ConstraintReaderImpl create(ObjectMapper objectMapper, SnippetTranslationResolver translationResolver, ConstraintDescriptionResolver constraintDescriptionResolver); @Override List<String> getOptionalMessages(Class<?> javaBaseClass, String javaFieldName); @Override String getTypeSpecifier(Class<?> javaBaseClass); @Override List<String> getConstraintMessages(Class<?> javaBaseClass, String javaFieldName); @Override List<String> getConstraintMessages(MethodParameter param);  }
@Test public void getConstraintMessages() { ConstraintReader reader = createWithValidation(); List<String> messages = reader.getConstraintMessages(Constraintz.class, "name"); assertThat(messages).hasSize(0); messages = reader.getConstraintMessages(Constraintz.class, "index"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be at least 1"); messages = reader.getConstraintMessages(Constraintz.class, "items"); assertThat(messages).hasSize(0); messages = reader.getConstraintMessages(Constraintz.class, "amount"); assertThat(messages).hasSize(2); assertThat(messages.get(0)).isEqualTo("Must be at least 10"); assertThat(messages.get(1)).isEqualTo("Must be at most 1000"); messages = reader.getConstraintMessages(Constraintz.class, "type"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be one of [big, small]"); messages = reader.getConstraintMessages(Constraintz.class, "amountWithGroup"); assertThat(messages).hasSize(2); assertThat(messages.get(0)).isEqualTo("Must be at least 10 (update)"); assertThat(messages.get(1)).isEqualTo("Must be at most 1000 (update), Must be at most 1000 (create)"); messages = reader.getConstraintMessages(Constraintz.class, "indexWithGroup"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be null (update)"); messages = reader.getConstraintMessages(Constraintz.class, "num"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be at most 10 (groups: [UnresolvedGroup])"); messages = reader.getConstraintMessages(Constraintz.class, "bool"); assertThat(messages).hasSize(0); messages = reader.getConstraintMessages(Constraintz.class, "str"); assertThat(messages).hasSize(0); messages = reader.getConstraintMessages(Constraintz.class, "enum1"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be one of [ONE, TWO]"); messages = reader.getConstraintMessages(Constraintz.class, "enum2"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Custom enum description: [A, B]"); messages = reader.getConstraintMessages(Constraintz.class, "enum3"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be one of [A first, B second]"); messages = reader.getConstraintMessages(Constraintz.class, "optionalEnum"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be one of [ONE, TWO]"); messages = reader.getConstraintMessages(Constraintz.class, "sizedString"); assertThat(messages).hasSize(1); assertThat(messages.get(0)).isEqualTo("Must be in range [2, 10]"); }