### Question:
MessageMimeMessageFactory extends AbstractMimeMessageFactory<MimeMessage> { @Override public MimeMessage createMessage(Object source, Map<String, Object> parameters) throws MessagingException { if (!(source instanceof MimeMessage)) { throw new MessagingException( String.format("Failed to create mime message from source [%s]", source.getClass())); } return new ExtendedMimeMessage((MimeMessage) source); }  @Override MimeMessage createMessage(Object source, Map<String, Object> parameters);  }### Answer:
@Test public void createMessageWithBadSource() { Throwable exception = assertThrows(MessagingException.class, () -> { this.mimeMessageFactory.createMessage("source", null); }); assertEquals("Failed to create mime message from source [class java.lang.String]", exception.getMessage()); }
@Test public void createMultipleMessages() throws Exception { MimeMessage source = new MimeMessage(Session.getInstance(new Properties())); source.setFrom(new InternetAddress("localhost@xwiki.org")); source.addRecipient(Message.RecipientType.TO, new InternetAddress("john@doe.com")); source.setSubject("Subject"); source.setText("Content"); MimeMessage first =this.mimeMessageFactory.createMessage(source, null); assertEqualMimeMessage(first, source); first.setFrom(new InternetAddress("jane@doe.com")); first.addRecipient(Message.RecipientType.TO, new InternetAddress("jack@doe.com")); first.setSubject("First subject"); first.setText("First content"); MimeMessage second = this.mimeMessageFactory.createMessage(source, null); assertEqualMimeMessage(second, source); }
@Test public void ensureMessageReceiveSameMessageID() throws Exception { MimeMessage source = new MimeMessage(Session.getInstance(new Properties())); source.setText("Content"); MimeMessage first = this.mimeMessageFactory.createMessage(source, null); MimeMessage second = this.mimeMessageFactory.createMessage(source, null); assertThat(first.getMessageID(), notNullValue()); assertThat(second.getMessageID(), notNullValue()); assertThat(first.getMessageID(), equalTo(second.getMessageID())); }