ExceptionUtils { public static void insertMessage(Throwable onObject, String msg) { try { Field field = Throwable.class.getDeclaredField("detailMessage"); field.setAccessible(true); if (onObject.getMessage() != null) { field.set(onObject, "\n[\n" + msg + "\n]\n[\nMessage: " + onObject.getMessage() + "\n]"); } else { field.set(onObject, "\n[\n" + msg + "]\n"); } } catch (RuntimeException e) { throw e; } catch (Exception e) { } }  static void insertMessage(Throwable onObject, String msg);  }
@Frutilla( Given = "an exception", When = "I insert a text in the exception message", Then = {"the new text must exist in the exception message", "and the original message must not be deleted" } ) @Test public void testInsertMessage() throws Exception { final RuntimeException exception = new RuntimeException(MESSAGE); insertMessage(exception, NEW_MESSAGE); assertTrue(exception.getMessage().contains(MESSAGE)); assertTrue(exception.getMessage().contains(NEW_MESSAGE)); }