### Question:
CustomValidationErrorPayloadMessageInterpolator implements MessageInterpolator { private String getMessage(final String message, final Context context) { if (isConstraintWithCustomMessage(message)) { return message; } if (isConstraintWithCustomMessageTemplate(message)) { return message; } if (isConstraintWithValidationErrorPayload(context)) { return getValidationErrorPayloadMessage(context); } return message; } CustomValidationErrorPayloadMessageInterpolator();  CustomValidationErrorPayloadMessageInterpolator(final MessageInterpolator delegate); @Override String interpolate(String message, Context context); @Override String interpolate(String message, Context context, Locale locale);  }### Answer:
@Test public void customMessageShouldBeInterpolated() { TestEntityWithValidationErrorPayloadAndCustomMessage entity = new TestEntityWithValidationErrorPayloadAndCustomMessage(); Set<ConstraintViolation<TestEntityWithValidationErrorPayloadAndCustomMessage>> constraintViolations = validator.validate(entity); assertThat(constraintViolations).hasSize(1); ConstraintViolation<TestEntityWithValidationErrorPayloadAndCustomMessage> constraintViolation = constraintViolations.iterator().next(); assertThat(constraintViolation.getMessage()).isEqualTo("VALUE_IS_NULL"); assertThat(constraintViolation.getMessageTemplate()).isEqualTo("VALUE_IS_NULL"); }
@Test public void customMessageTemplateShouldBeInterpolated() { TestEntityWithValidationErrorPayloadAndCustomMessageTemplate entity = new TestEntityWithValidationErrorPayloadAndCustomMessageTemplate(); Set<ConstraintViolation<TestEntityWithValidationErrorPayloadAndCustomMessageTemplate>> constraintViolations = validator.validate(entity); assertThat(constraintViolations).hasSize(1); ConstraintViolation<TestEntityWithValidationErrorPayloadAndCustomMessageTemplate> constraintViolation = constraintViolations.iterator().next(); assertThat(constraintViolation.getMessage()).isEqualTo("value must not be null"); assertThat(constraintViolation.getMessageTemplate()).isEqualTo("{VALUE_IS_NULL}"); }
@Test public void errorCodeShouldBeInterpolated() { TestEntityWithValidationErrorPayload entity = new TestEntityWithValidationErrorPayload(); Set<ConstraintViolation<TestEntityWithValidationErrorPayload>> constraintViolations = validator.validate(entity); assertThat(constraintViolations).hasSize(1); ConstraintViolation<TestEntityWithValidationErrorPayload> constraintViolation = constraintViolations.iterator().next(); assertThat(constraintViolation.getMessage()).isEqualTo("value must not be null"); assertThat(constraintViolation.getMessageTemplate()).isEqualTo("{javax.validation.constraints.NotNull.message}"); }
@Test public void defaultMessageShouldBeInterpolated() { TestEntityWithoutValidationErrorPayload entity = new TestEntityWithoutValidationErrorPayload(); Set<ConstraintViolation<TestEntityWithoutValidationErrorPayload>> constraintViolations = validator.validate(entity); assertThat(constraintViolations).hasSize(1); ConstraintViolation<TestEntityWithoutValidationErrorPayload> constraintViolation = constraintViolations.iterator().next(); assertThat(constraintViolation.getMessage()).isEqualTo("must not be null"); assertThat(constraintViolation.getMessageTemplate()).isEqualTo("{javax.validation.constraints.NotNull.message}"); }