@SuppressWarnings("deprecation")
@Test
public void shouldHandleAValidationException() throws Exception {

    final JsonSchemaValidationException validationException = new JsonSchemaValidationException("Ooops", new ValidationException("Opps"));
    final String actionName = "exaple.action-name";
    final String payloadJson = "{\"some\": \"json\"}";
    final Optional<MediaType> mediaType = of(new MediaType("application/vnd.example.action-name+json"));
    final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
    final JsonValue payload = mock(JsonValue.class);
    when(jsonEnvelope.payload()).thenReturn(payload);
    when(objectMapper.writeValueAsString(payload)).thenReturn(payloadJson);
    when(jsonEnvelope.toObfuscatedDebugString()).thenReturn("debug-json");
    doThrow(validationException).when(jsonSchemaValidator).validate(
            payloadJson,
            actionName,
            mediaType);
    envelopeValidator.validate(jsonEnvelope, actionName, mediaType);
    verify(envelopeValidationExceptionHandler).handle(exceptionArgumentCaptor.capture());
    final EnvelopeValidationException envelopeValidationException = exceptionArgumentCaptor.getValue();
    final String exceptionMessage = "Message not valid against schema: \ndebug-json : validation error:" +
            " {\"message\":\"#: Opps\",\"violation\":\"#\",\"causingExceptions\":[]}";
    assertThat(envelopeValidationException.getMessage(), is(exceptionMessage));
    assertThat(envelopeValidationException.getCause(), is(validationException));
}