Source:
public void testNotificationsEmails() throws Exception { getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD); NotificationsUserProfilePage p; p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME); p.setPageCreatedEmail(true); getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD); DocumentReference page1 = new DocumentReference("xwiki", getTestClassName(), "Page1"); DocumentReference page2 = new DocumentReference("xwiki", getTestClassName(), "Page2"); getUtil().createPage(getTestClassName(), "Page1", "Content 1", "Title 1"); getUtil().createPage(getTestClassName(), "Page2", "Content 2", "Title 2"); getUtil().login(SUPERADMIN_USER_NAME, SUPERADMIN_PASSWORD); SchedulerHomePage schedulerHomePage = SchedulerHomePage.gotoPage(); schedulerHomePage.clickJobActionTrigger("Notifications daily email"); this.mail.waitForIncomingEmail(1); assertEquals(1, this.mail.getReceivedMessages().length); MimeMessage message = this.mail.getReceivedMessages()[0]; assertEquals("5 event(s) on the wiki", message.getSubject()); Multipart content = (Multipart) message.getContent(); assertTrue(content.getContentType().startsWith("multipart/mixed;")); assertEquals(1, content.getCount()); MimeBodyPart mimeBodyPart1 = (MimeBodyPart) content.getBodyPart(0); Multipart multipart1 = (Multipart) mimeBodyPart1.getContent(); assertEquals(2, multipart1.getCount()); assertEquals("text/plain; charset=UTF-8", multipart1.getBodyPart(0).getContentType()); assertEquals("text/html; charset=UTF-8", multipart1.getBodyPart(1).getContentType()); String email = prepareMail(multipart1.getBodyPart(0).getContent().toString()); assertTrue(email.contains( prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail1.txt"))) ) ); assertTrue(email.contains( prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail2.txt"))) ) ); assertTrue(email.contains( prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail3.txt"))) ) ); getUtil().rest().delete(page1); getUtil().rest().delete(page2); }

Target:
public void testNotificationsEmails() throws Exception { getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD); NotificationsUserProfilePage p; p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME); p.setPageCreatedEmail(true); getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD); DocumentReference page1 = new DocumentReference("xwiki", getTestClassName(), "Page1"); DocumentReference page2 = new DocumentReference("xwiki", getTestClassName(), "Page2"); getUtil().createPage(getTestClassName(), "Page1", "Content 1", "Title 1"); getUtil().createPage(getTestClassName(), "Page2", "Content 2", "Title 2"); getUtil().login(SUPERADMIN_USER_NAME, SUPERADMIN_PASSWORD); SchedulerHomePage schedulerHomePage = SchedulerHomePage.gotoPage(); schedulerHomePage.clickJobActionTrigger("Notifications daily email"); this.mail.waitForIncomingEmail(1); assertEquals(1, this.mail.getReceivedMessages().length); MimeMessage message = this.mail.getReceivedMessages()[0]; assertTrue(message.getSubject().endsWith("event(s) on the wiki")); Multipart content = (Multipart) message.getContent(); assertTrue(content.getContentType().startsWith("multipart/mixed;")); assertEquals(1, content.getCount()); MimeBodyPart mimeBodyPart1 = (MimeBodyPart) content.getBodyPart(0); Multipart multipart1 = (Multipart) mimeBodyPart1.getContent(); assertEquals(2, multipart1.getCount()); assertEquals("text/plain; charset=UTF-8", multipart1.getBodyPart(0).getContentType()); assertEquals("text/html; charset=UTF-8", multipart1.getBodyPart(1).getContentType()); String email = prepareMail(multipart1.getBodyPart(0).getContent().toString()); assertTrue(email.contains( prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail1.txt"))) ) ); assertTrue(email.contains( prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail2.txt"))) ) ); assertTrue(email.contains( prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail3.txt"))) ) ); getUtil().rest().delete(page1); getUtil().rest().delete(page2); }