@Test public void run_mockedTransport_transportSendAnyMessage() throws MessagingException { Email email = mock(Email.class); when(email.getFromAddress()).thenReturn("a@a.com"); when(email.getFromPersonal()).thenReturn("A Personal"); when(email.getTo()).thenReturn("b@b.com"); when(email.getReplyToAddress()).thenReturn("c@c.com"); Transport transport = mock(Transport.class); SendEmailTask sendEmailTask = new SendEmailTask(email, transport); sendEmailTask.run(); verify(transport).send(any(Message.class)); }
@Override public void run() { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message message = new MimeMessage(session); try { if (email.getFromPersonal().equals(EmailBuilder.DEFAULT_PERSONAL)) { message.setFrom(new InternetAddress(email.getFromAddress())); } else { message.setFrom(new InternetAddress(email.getFromAddress(), email.getFromPersonal())); } message.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getTo())); message.setSubject(email.getSubject()); message.setContent(email.getBody(), CONTENT_TYPE); if (Strings.isNullOrEmpty(email.getReplyToAddress())) { message.setReplyTo(new Address[] { new InternetAddress(email.getReplyToAddress()) }); } transport.send(message); } catch (MessagingException e) { logger.log(Level.WARNING, e.getMessage()); } catch (UnsupportedEncodingException e) { logger.log(Level.WARNING, e.getMessage()); } }
SendEmailTask implements DeferredTask { @Override public void run() { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message message = new MimeMessage(session); try { if (email.getFromPersonal().equals(EmailBuilder.DEFAULT_PERSONAL)) { message.setFrom(new InternetAddress(email.getFromAddress())); } else { message.setFrom(new InternetAddress(email.getFromAddress(), email.getFromPersonal())); } message.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getTo())); message.setSubject(email.getSubject()); message.setContent(email.getBody(), CONTENT_TYPE); if (Strings.isNullOrEmpty(email.getReplyToAddress())) { message.setReplyTo(new Address[] { new InternetAddress(email.getReplyToAddress()) }); } transport.send(message); } catch (MessagingException e) { logger.log(Level.WARNING, e.getMessage()); } catch (UnsupportedEncodingException e) { logger.log(Level.WARNING, e.getMessage()); } } }
SendEmailTask implements DeferredTask { @Override public void run() { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message message = new MimeMessage(session); try { if (email.getFromPersonal().equals(EmailBuilder.DEFAULT_PERSONAL)) { message.setFrom(new InternetAddress(email.getFromAddress())); } else { message.setFrom(new InternetAddress(email.getFromAddress(), email.getFromPersonal())); } message.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getTo())); message.setSubject(email.getSubject()); message.setContent(email.getBody(), CONTENT_TYPE); if (Strings.isNullOrEmpty(email.getReplyToAddress())) { message.setReplyTo(new Address[] { new InternetAddress(email.getReplyToAddress()) }); } transport.send(message); } catch (MessagingException e) { logger.log(Level.WARNING, e.getMessage()); } catch (UnsupportedEncodingException e) { logger.log(Level.WARNING, e.getMessage()); } } SendEmailTask(Email email,
                  Transport transport); }
SendEmailTask implements DeferredTask { @Override public void run() { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message message = new MimeMessage(session); try { if (email.getFromPersonal().equals(EmailBuilder.DEFAULT_PERSONAL)) { message.setFrom(new InternetAddress(email.getFromAddress())); } else { message.setFrom(new InternetAddress(email.getFromAddress(), email.getFromPersonal())); } message.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getTo())); message.setSubject(email.getSubject()); message.setContent(email.getBody(), CONTENT_TYPE); if (Strings.isNullOrEmpty(email.getReplyToAddress())) { message.setReplyTo(new Address[] { new InternetAddress(email.getReplyToAddress()) }); } transport.send(message); } catch (MessagingException e) { logger.log(Level.WARNING, e.getMessage()); } catch (UnsupportedEncodingException e) { logger.log(Level.WARNING, e.getMessage()); } } SendEmailTask(Email email,
                  Transport transport); @Override void run(); }
SendEmailTask implements DeferredTask { @Override public void run() { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message message = new MimeMessage(session); try { if (email.getFromPersonal().equals(EmailBuilder.DEFAULT_PERSONAL)) { message.setFrom(new InternetAddress(email.getFromAddress())); } else { message.setFrom(new InternetAddress(email.getFromAddress(), email.getFromPersonal())); } message.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getTo())); message.setSubject(email.getSubject()); message.setContent(email.getBody(), CONTENT_TYPE); if (Strings.isNullOrEmpty(email.getReplyToAddress())) { message.setReplyTo(new Address[] { new InternetAddress(email.getReplyToAddress()) }); } transport.send(message); } catch (MessagingException e) { logger.log(Level.WARNING, e.getMessage()); } catch (UnsupportedEncodingException e) { logger.log(Level.WARNING, e.getMessage()); } } SendEmailTask(Email email,
                  Transport transport); @Override void run();  }