### Question:
ExtendedMimeMessage extends MimeMessage { public void setMessageId(String messageId) { try { ensureSaved(); setHeader(MESSAGE_ID_HEADER, messageId); } catch (MessagingException e) { throw new RuntimeException(String.format("Failed to set Message ID header to [%s]", messageId), e); } } ExtendedMimeMessage();  ExtendedMimeMessage(Session session, InputStream is);  ExtendedMimeMessage(MimeMessage source); static ExtendedMimeMessage wrap(MimeMessage message); boolean isEmpty(); void setType(String mailType); String getType(); void setMessageId(String messageId); boolean ensureSaved(); @Override void setHeader(String name, String value); String getUniqueMessageId();  }### Answer:
@Test public void getMessageIdAndEnsureSaved() throws Exception { ExtendedMimeMessage message = new ExtendedMimeMessage(); message.setText(TEST_CONTENT); message.setMessageId(TEST_MESSAGE_ID); message.writeTo(new OutputStream() { @Override public void write(int b) { } }); assertThat(message.getMessageID(), equalTo(TEST_MESSAGE_ID)); }
@Test public void setMessageIdWhenException() { Throwable exception = assertThrows(RuntimeException.class, () -> { ExtendedMimeMessage message = new ThrowingeExtendedMimeMessage(); message.setMessageId("whatever"); }); assertEquals("Failed to set Message ID header to [whatever]", exception.getMessage()); assertEquals("MessagingException: error", ExceptionUtils.getRootCauseMessage(exception)); }