public void getDefaultTransport() {
MailServiceImpl mailService = new MailServiceImpl();
// 1 transport
Map<String, MailTransport> transports = createHashMap();
transports.put("transport1", new MailTransport());
mailService.setMailTransports(transports);
assertNotNull(mailService.getMailTransport()); // the only transport is the default transport
// 2 transports
transports.put("transport2", new MailTransport());
mailService.setMailTransports(transports);
try {
mailService.getMailTransport();
fail();
} catch (MailTransportNotFoundException e) {
assertThat(e, exception("Could not find mail transport: _DEFAULT_"));
}
// with default transport
MailTransport transport3 = new MailTransport();
transport3.setDefault(true);
transports.put("transport3", transport3);
mailService.setMailTransports(transports);
assertNotNull(mailService.getMailTransport());
assertNotNull(mailService.getMailTransport("transport3"));
// 2 default transports
MailTransport transport4 = new MailTransport();
transport4.setDefault(true);
transports.put("transport4", transport4);
try {
mailService.setMailTransports(transports);
fail();