@Test
public void testHandlingOfJsonProcessingException() throws JsonProcessingException {

    Object data = new Object();
    JsonProcessingException exception = mock(JsonProcessingException.class);
    when(mapper.writeValueAsString(data)).thenThrow(exception);
    try {
        bodyBuilder.json(data);
        fail("No exception thrown!");
    } catch (IllegalStateException iex) {
        assertThat(iex.getCause()).isEqualTo(exception);
    }
}