Emailer { public boolean sendEmail(List<ContactList> listOfContactLists, String subject, String body) throws AddressException, MessagingException { return sendEmail(listOfContactLists, subject, body, null); } Emailer(MailTemplate mailTemplate);   Emailer(MailTemplate mailTemplate, MailPackageStaticDependenciesWrapper facadeToWebappAndMailhelper);  Emailer(OLATPrincipal senderPrincipal, boolean tryInstitutionalEmail, MailTemplate mailTemplate);   Emailer(OLATPrincipal senderPrincipal, boolean tryInstitutionalEmail, MailTemplate mailTemplate, MailPackageStaticDependenciesWrapper facadeToWebappAndMailhelper); boolean sendEmail(List<ContactList> listOfContactLists, String subject, String body); boolean sendEmail(List<ContactList> listOfContactLists, String subject, String body, List<File> attachments); boolean sendEmailCC(String cc, String subject, String body, List<File> attachments); boolean sendEmail(String mailto, String subject, String body);  }
@Test public void testSystemEmailerSetupBySendingAMessageFromAdminToInfo() throws AddressException, SendFailedException, MessagingException{ systemEmailer.sendEmail(ObjectMother.OLATINFO_EMAIL, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY); verify(webappAndMailhelperMockSystemMailer, times(1)).send(any(MimeMessage.class), any(MailerResult.class)); assertEquals("system is mail sender", ObjectMother.OLATADMIN_EMAIL, systemEmailer.mailfrom); }
@Test public void testShouldNotSendAnEmailWithDisabledMailHost() throws AddressException, SendFailedException, MessagingException{ MailPackageStaticDependenciesWrapper webappAndMailhelperMock = createWebappAndMailhelperWithDisabledMailFunctinality(); Emailer anEmailer = new Emailer(mailTemplateMockForSystemMailer, webappAndMailhelperMock); anEmailer.sendEmail(ObjectMother.OLATINFO_EMAIL, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY); verify(webappAndMailhelperMock, never()).send(any(MimeMessage.class), any(MailerResult.class)); }
@Test public void testShouldNotFailWithEmptyContactList() throws AddressException, MessagingException{ systemEmailer.sendEmail(new ArrayList<ContactList>(), ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY); verify(webappAndMailhelperMockSystemMailer, times(1)).send(any(MimeMessage.class), any(MailerResult.class)); }
@Test public void testShouldSendMailToContactListMembers() throws AddressException, MessagingException { systemEmailer.sendEmail(recipientsContactLists, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY); verify(webappAndMailhelperMockSystemMailer, times(1)).send(any(MimeMessage.class), any(MailerResult.class)); caputureAndVerifyValuesForCreateMessage(recipientsContactLists, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY+ObjectMother.MAIL_TEMPLATE_FOOTER,null); }
@Test public void testShouldSendMailToContactListMembersWithFourAttachements() throws AddressException, MessagingException { systemEmailer.sendEmail(recipientsContactLists, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY, fourAttachmentsMocked); verify(webappAndMailhelperMockSystemMailer, times(1)).send(any(MimeMessage.class), any(MailerResult.class)); caputureAndVerifyValuesForCreateMessage(recipientsContactLists, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY+ObjectMother.MAIL_TEMPLATE_FOOTER, fourAttachmentsMocked); }
@Test public void testShouldSendMailToContactListMembersWithEmptyAttachements() throws AddressException, MessagingException { systemEmailer.sendEmail(recipientsContactLists, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY, emptyAttachmentsMocked); verify(webappAndMailhelperMockSystemMailer, times(1)).send(any(MimeMessage.class), any(MailerResult.class)); caputureAndVerifyValuesForCreateMessage(recipientsContactLists, ObjectMother.AN_EXAMPLE_SUBJECT, ObjectMother.HELLOY_KITTY_THIS_IS_AN_EXAMPLE_BODY+ObjectMother.MAIL_TEMPLATE_FOOTER,emptyAttachmentsMocked); }