@Test
public void shouldHandleAJsonProcessingException() throws Exception {

    final JsonProcessingException jsonProcessingException = new JsonGenerationException("Ooops");
    final String actionName = "example.action-name";
    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)).thenThrow(jsonProcessingException);
    envelopeValidator.validate(jsonEnvelope, actionName, mediaType);
    verify(envelopeValidationExceptionHandler).handle(exceptionArgumentCaptor.capture());
    final EnvelopeValidationException envelopeValidationException = exceptionArgumentCaptor.getValue();
    assertThat(envelopeValidationException.getMessage(), is("Error serialising json."));
    assertThat(envelopeValidationException.getCause(), is(jsonProcessingException));
    verifyZeroInteractions(jsonSchemaValidator);
}