@Test public void fromShouldCombinePlainTextAndHtml() throws Exception { String htmlText = "<p>HTML text</p>"; String plainText = "Plain text"; String rowContent = IOUtils.toString( mimeMessageBodyGenerator.from(original, Optional.of(plainText), Optional.of(htmlText)) .getInputStream(), StandardCharsets.UTF_8); assertThat(rowContent).containsSequence(htmlText); assertThat(rowContent).containsSequence(plainText); verifyZeroInteractions(htmlTextExtractor); }
public MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText) throws MessagingException { Preconditions.checkNotNull(messageHoldingHeaders); Preconditions.checkNotNull(plainText); Preconditions.checkNotNull(htmlText); if (htmlText.isPresent()) { messageHoldingHeaders.setContent(generateMultipart(htmlText.get(), plainText)); } else { messageHoldingHeaders.setText(plainText.orElse(EMPTY_TEXT)); } return messageHoldingHeaders; }
MimeMessageBodyGenerator { public MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText) throws MessagingException { Preconditions.checkNotNull(messageHoldingHeaders); Preconditions.checkNotNull(plainText); Preconditions.checkNotNull(htmlText); if (htmlText.isPresent()) { messageHoldingHeaders.setContent(generateMultipart(htmlText.get(), plainText)); } else { messageHoldingHeaders.setText(plainText.orElse(EMPTY_TEXT)); } return messageHoldingHeaders; } }
MimeMessageBodyGenerator { public MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText) throws MessagingException { Preconditions.checkNotNull(messageHoldingHeaders); Preconditions.checkNotNull(plainText); Preconditions.checkNotNull(htmlText); if (htmlText.isPresent()) { messageHoldingHeaders.setContent(generateMultipart(htmlText.get(), plainText)); } else { messageHoldingHeaders.setText(plainText.orElse(EMPTY_TEXT)); } return messageHoldingHeaders; } @Inject @VisibleForTesting  MimeMessageBodyGenerator(HtmlTextExtractor htmlTextExtractor); }
MimeMessageBodyGenerator { public MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText) throws MessagingException { Preconditions.checkNotNull(messageHoldingHeaders); Preconditions.checkNotNull(plainText); Preconditions.checkNotNull(htmlText); if (htmlText.isPresent()) { messageHoldingHeaders.setContent(generateMultipart(htmlText.get(), plainText)); } else { messageHoldingHeaders.setText(plainText.orElse(EMPTY_TEXT)); } return messageHoldingHeaders; } @Inject @VisibleForTesting  MimeMessageBodyGenerator(HtmlTextExtractor htmlTextExtractor); MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText); }
MimeMessageBodyGenerator { public MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText) throws MessagingException { Preconditions.checkNotNull(messageHoldingHeaders); Preconditions.checkNotNull(plainText); Preconditions.checkNotNull(htmlText); if (htmlText.isPresent()) { messageHoldingHeaders.setContent(generateMultipart(htmlText.get(), plainText)); } else { messageHoldingHeaders.setText(plainText.orElse(EMPTY_TEXT)); } return messageHoldingHeaders; } @Inject @VisibleForTesting  MimeMessageBodyGenerator(HtmlTextExtractor htmlTextExtractor); MimeMessage from(MimeMessage messageHoldingHeaders, Optional<String> plainText, Optional<String> htmlText); static final String MIXED; static final String EMPTY_TEXT; }