@Test
public void shouldThrowExceptionIfSchemaValidationFails() throws Exception {

    final String actionName = "example.action-name";
    final String envelopeJson = "{\"envelope\": \"json\"}";
    final String errorMessage = "error message";
    final JSONObject payload = mock(JSONObject.class);
    final Schema schema = mock(Schema.class);
    final ValidationException validationException = mock(ValidationException.class);
    when(payloadExtractor.extractPayloadFrom(envelopeJson)).thenReturn(payload);
    when(jsonSchemaLoader.loadSchema(actionName)).thenReturn(schema);
    when(schemaValidationErrorMessageGenerator.generateErrorMessage(validationException)).thenReturn(errorMessage);
    doThrow(validationException).when(schema).validate(payload);
    try {
        fileBasedJsonSchemaValidator.validateWithoutSchemaCatalog(envelopeJson, actionName);
        fail();
    } catch (final JsonSchemaValidationException e) {
        assertThat(e.getMessage(), is(errorMessage));
        assertThat(e.getCause(), is(validationException));
    }
}