@Test public void whenSMTP_port_CredentialsIsNotConfigured_anExceptionIsThrown() throws Exception { exception.expect(EmailSenderException.class); exception.expectMessage("SMTP port is not configured"); emailSenderService.send(emailTO()); }
public void send(EmailTO emailTO) throws EmailSenderException { try { checkIfEmailCredentialsAreConfigured(); if (emailSendCounter < MAX_EMAILS_TO_BE_SEND) { Email email = new EmailMapper().mapFromEmailTO(emailTO); email.setSSLOnConnect(smtpUseSsl); email.setSmtpPort(Integer.valueOf(smtp_port)); email.setHostName(smtp_server); if (isNoneBlank(smtp_username, smtp_password)) { email.setAuthenticator(new DefaultAuthenticator(smtp_username, smtp_password)); } LOG.info("Sending email: " + emailTO); email.send(); emailSendCounter++; } else { LOG.info("Request of sending email to {} ignored. Limit reached!", emailTO); } } catch (IllegalArgumentException e) { LOG.error("IllegalArgumentException occurred while sending the email ", e); throw e; } catch (EmailException | IOException e) { LOG.error("Errors occurred while sending the email ", e); throw new EmailSenderException(e); } }
EmailSenderService implements JobStartListener { public void send(EmailTO emailTO) throws EmailSenderException { try { checkIfEmailCredentialsAreConfigured(); if (emailSendCounter < MAX_EMAILS_TO_BE_SEND) { Email email = new EmailMapper().mapFromEmailTO(emailTO); email.setSSLOnConnect(smtpUseSsl); email.setSmtpPort(Integer.valueOf(smtp_port)); email.setHostName(smtp_server); if (isNoneBlank(smtp_username, smtp_password)) { email.setAuthenticator(new DefaultAuthenticator(smtp_username, smtp_password)); } LOG.info("Sending email: " + emailTO); email.send(); emailSendCounter++; } else { LOG.info("Request of sending email to {} ignored. Limit reached!", emailTO); } } catch (IllegalArgumentException e) { LOG.error("IllegalArgumentException occurred while sending the email ", e); throw e; } catch (EmailException | IOException e) { LOG.error("Errors occurred while sending the email ", e); throw new EmailSenderException(e); } } }
EmailSenderService implements JobStartListener { public void send(EmailTO emailTO) throws EmailSenderException { try { checkIfEmailCredentialsAreConfigured(); if (emailSendCounter < MAX_EMAILS_TO_BE_SEND) { Email email = new EmailMapper().mapFromEmailTO(emailTO); email.setSSLOnConnect(smtpUseSsl); email.setSmtpPort(Integer.valueOf(smtp_port)); email.setHostName(smtp_server); if (isNoneBlank(smtp_username, smtp_password)) { email.setAuthenticator(new DefaultAuthenticator(smtp_username, smtp_password)); } LOG.info("Sending email: " + emailTO); email.send(); emailSendCounter++; } else { LOG.info("Request of sending email to {} ignored. Limit reached!", emailTO); } } catch (IllegalArgumentException e) { LOG.error("IllegalArgumentException occurred while sending the email ", e); throw e; } catch (EmailException | IOException e) { LOG.error("Errors occurred while sending the email ", e); throw new EmailSenderException(e); } }  }
EmailSenderService implements JobStartListener { public void send(EmailTO emailTO) throws EmailSenderException { try { checkIfEmailCredentialsAreConfigured(); if (emailSendCounter < MAX_EMAILS_TO_BE_SEND) { Email email = new EmailMapper().mapFromEmailTO(emailTO); email.setSSLOnConnect(smtpUseSsl); email.setSmtpPort(Integer.valueOf(smtp_port)); email.setHostName(smtp_server); if (isNoneBlank(smtp_username, smtp_password)) { email.setAuthenticator(new DefaultAuthenticator(smtp_username, smtp_password)); } LOG.info("Sending email: " + emailTO); email.send(); emailSendCounter++; } else { LOG.info("Request of sending email to {} ignored. Limit reached!", emailTO); } } catch (IllegalArgumentException e) { LOG.error("IllegalArgumentException occurred while sending the email ", e); throw e; } catch (EmailException | IOException e) { LOG.error("Errors occurred while sending the email ", e); throw new EmailSenderException(e); } }  void send(EmailTO emailTO); @Override void jobHasBeenStarted(String jobName); }
EmailSenderService implements JobStartListener { public void send(EmailTO emailTO) throws EmailSenderException { try { checkIfEmailCredentialsAreConfigured(); if (emailSendCounter < MAX_EMAILS_TO_BE_SEND) { Email email = new EmailMapper().mapFromEmailTO(emailTO); email.setSSLOnConnect(smtpUseSsl); email.setSmtpPort(Integer.valueOf(smtp_port)); email.setHostName(smtp_server); if (isNoneBlank(smtp_username, smtp_password)) { email.setAuthenticator(new DefaultAuthenticator(smtp_username, smtp_password)); } LOG.info("Sending email: " + emailTO); email.send(); emailSendCounter++; } else { LOG.info("Request of sending email to {} ignored. Limit reached!", emailTO); } } catch (IllegalArgumentException e) { LOG.error("IllegalArgumentException occurred while sending the email ", e); throw e; } catch (EmailException | IOException e) { LOG.error("Errors occurred while sending the email ", e); throw new EmailSenderException(e); } }  void send(EmailTO emailTO); @Override void jobHasBeenStarted(String jobName);  }