}
}
@Test
public void setMails() {
MailServiceImpl mailService = new MailServiceImpl();
// miss mail id
Map<String, MailBuilder> mails = createHashMap();
mails.put(null, new MailBuilder());
try {
mailService.setMails(mails);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("mail id"));
}
// miss mail object
mails = createHashMap();
mails.put("id", null);
try {
mailService.setMails(mails);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("mail builder"));
}
// set null
mailService = new MailServiceImpl();
mailService.setMails(null);
// reset mails
mails = createHashMap();
mails.put("mail1", new MailBuilder());
mails.put("mail2", new MailBuilder());
mailService.setMails(mails);
assertNotNull(mailService.getMailBuilder("mail1"));
assertNotNull(mailService.getMailBuilder("mail2"));
mails = createHashMap();
mails.put("mail3", new MailBuilder());
mails.put("mail4", new MailBuilder());
mailService.setMails(mails);
try {
mailService.getMailBuilder("mail1");
fail();
} catch (MailNotFoundException e) {
assertThat(e, exception("Could not find mail builder: mail1"));
}
try {
mailService.getMailBuilder("mail2");
fail();
} catch (MailNotFoundException e) {
assertThat(e, exception("Could not find mail builder: mail2"));
}
assertNotNull(mailService.getMailBuilder("mail3"));
assertNotNull(mailService.getMailBuilder("mail4"));
}