@Test public void buildNewSubjectShouldReplaceSubjectWhenPrefixIsNull() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); String prefix = null; String originalSubject = "original subject"; String subject = "new subject"; Optional<String> newSubject = new MimeMessageUtils(message).buildNewSubject(prefix, originalSubject, subject); assertThat(newSubject).contains(subject); }
@VisibleForTesting Optional<String> buildNewSubject(String subjectPrefix, String originalSubject, String subject) throws MessagingException { String nullablePrefix = Strings.emptyToNull(subjectPrefix); if (nullablePrefix == null && subject == null) { return Optional.empty(); } if (nullablePrefix == null) { return Optional.of(subject); } String chosenSubject = chooseSubject(subject, originalSubject); return prefixSubject(chosenSubject, nullablePrefix); }
MimeMessageUtils { @VisibleForTesting Optional<String> buildNewSubject(String subjectPrefix, String originalSubject, String subject) throws MessagingException { String nullablePrefix = Strings.emptyToNull(subjectPrefix); if (nullablePrefix == null && subject == null) { return Optional.empty(); } if (nullablePrefix == null) { return Optional.of(subject); } String chosenSubject = chooseSubject(subject, originalSubject); return prefixSubject(chosenSubject, nullablePrefix); } }
MimeMessageUtils { @VisibleForTesting Optional<String> buildNewSubject(String subjectPrefix, String originalSubject, String subject) throws MessagingException { String nullablePrefix = Strings.emptyToNull(subjectPrefix); if (nullablePrefix == null && subject == null) { return Optional.empty(); } if (nullablePrefix == null) { return Optional.of(subject); } String chosenSubject = chooseSubject(subject, originalSubject); return prefixSubject(chosenSubject, nullablePrefix); } MimeMessageUtils(MimeMessage message); }
MimeMessageUtils { @VisibleForTesting Optional<String> buildNewSubject(String subjectPrefix, String originalSubject, String subject) throws MessagingException { String nullablePrefix = Strings.emptyToNull(subjectPrefix); if (nullablePrefix == null && subject == null) { return Optional.empty(); } if (nullablePrefix == null) { return Optional.of(subject); } String chosenSubject = chooseSubject(subject, originalSubject); return prefixSubject(chosenSubject, nullablePrefix); } MimeMessageUtils(MimeMessage message); Optional<String> subjectWithPrefix(String subjectPrefix); Optional<String> subjectWithPrefix(String subjectPrefix, Mail originalMail, String subject); String getMessageHeaders(); List<Header> toHeaderList(); }
MimeMessageUtils { @VisibleForTesting Optional<String> buildNewSubject(String subjectPrefix, String originalSubject, String subject) throws MessagingException { String nullablePrefix = Strings.emptyToNull(subjectPrefix); if (nullablePrefix == null && subject == null) { return Optional.empty(); } if (nullablePrefix == null) { return Optional.of(subject); } String chosenSubject = chooseSubject(subject, originalSubject); return prefixSubject(chosenSubject, nullablePrefix); } MimeMessageUtils(MimeMessage message); Optional<String> subjectWithPrefix(String subjectPrefix); Optional<String> subjectWithPrefix(String subjectPrefix, Mail originalMail, String subject); String getMessageHeaders(); List<Header> toHeaderList();  }