MimeMessageUtils { public Optional<String> subjectWithPrefix(String subjectPrefix) throws MessagingException { return prefixSubject(message.getSubject(), subjectPrefix); } MimeMessageUtils(MimeMessage message); Optional<String> subjectWithPrefix(String subjectPrefix); Optional<String> subjectWithPrefix(String subjectPrefix, Mail originalMail, String subject); String getMessageHeaders(); List<Header> toHeaderList();  }
@Test public void subjectWithPrefixShouldReturnSubjectWithPrefixWhenSubjectIsPresent() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("subject"); Optional<String> subjectWithPrefix = new MimeMessageUtils(message).subjectWithPrefix("my"); assertThat(subjectWithPrefix).contains("my subject"); }
@Test public void subjectWithPrefixShouldReturnPrefixAsSubjectWhenSubjectIsAbsent() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); Optional<String> subjectWithPrefix = new MimeMessageUtils(message).subjectWithPrefix("my"); assertThat(subjectWithPrefix).contains("my"); }
@Test public void subjectWithPrefixShouldReturnAbsentWhenNullPrefix() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("original subject"); FakeMail oldMail = FakeMail.from(message); String subjectPrefix = null; String subject = null; Optional<String> subjectWithPrefix = new MimeMessageUtils(message).subjectWithPrefix(subjectPrefix, oldMail, subject); assertThat(subjectWithPrefix).isEmpty(); }
@Test public void subjectWithPrefixShouldReturnAbsentWhenEmptyPrefix() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("original subject"); FakeMail oldMail = FakeMail.from(message); String subjectPrefix = ""; String subject = null; Optional<String> subjectWithPrefix = new MimeMessageUtils(message).subjectWithPrefix(subjectPrefix, oldMail, subject); assertThat(subjectWithPrefix).isEmpty(); }