### Question:
SmtpTask implements Task { @Override public void execute(Context ctx) throws Exception { Map<String, Object> smtp = getCfg(ctx, Constants.SMTP_PARAMS_KEY, Constants.SMTP_KEY); Map<String, Object> mail = getCfg(ctx, Constants.MAIL_PARAMS_KEY, Constants.MAIL_KEY); send(ctx, smtp, mail); }  @Override void execute(Context ctx); @Deprecated void call(@InjectVariable("context") Context ctx, Map<String, Object> smtpParams, Map<String, Object> mailParams); @Deprecated void call(Map<String, Object> smtpParams, Map<String, Object> mailParams); @Deprecated void send(String hostName, int port, String from, String to, String subject, String message, String bcc);  }### Answer:
@Test public void testVariables() throws Exception { SmtpServer server = mail.getSmtp(); Map<String, Object> smtpParams = new HashMap<>(); smtpParams.put("host", "localhost"); smtpParams.put("port", server.getPort()); Map<String, Object> mailParams = new HashMap<>(); mailParams.put("from", "my@mail.com"); mailParams.put("to", "their@mail.com"); mailParams.put("template", new File(ClassLoader.getSystemResource("test.mustache").toURI()).toString()); Map<String, Object> m = new HashMap<>(); m.put("name", "Concord"); m.put("workDir", "/"); m.put("smtp", smtpParams); m.put("mail", mailParams); Context ctx = new MockContext(m); SmtpTask t = new SmtpTask(); t.execute(ctx); MimeMessage[] messages = mail.getReceivedMessages(); assertEquals("Hello, Concord!\r\n", messages[0].getContent()); mail.reset(); }
@Test public void testAttachments() throws Exception { SmtpServer server = mail.getSmtp(); Map<String, Object> smtpParams = new HashMap<>(); smtpParams.put("host", "localhost"); smtpParams.put("port", server.getPort()); Map<String, Object> mailParams = new HashMap<>(); mailParams.put("from", "my@mail.com"); mailParams.put("to", "their@mail.com"); mailParams.put("template", new File(ClassLoader.getSystemResource("test.mustache").toURI()).toString()); mailParams.put("attachments", Collections.singletonList(new File(ClassLoader.getSystemResource("attahcment.txt").toURI()).toString())); Map<String, Object> m = new HashMap<>(); m.put("name", "Concord"); m.put("workDir", "/"); m.put("smtp", smtpParams); m.put("mail", mailParams); Context ctx = new MockContext(m); SmtpTask t = new SmtpTask(); t.execute(ctx); MimeMessage[] messages = mail.getReceivedMessages(); assertEquals(1, messages.length); MimeMessage msg = messages[0]; assertNotNull(msg.getContent()); assertTrue(msg.getContent() instanceof MimeMultipart); MimeMultipart mp = (MimeMultipart) msg.getContent(); assertEquals(2, mp.getCount()); assertEquals("Hello, Concord!", mp.getBodyPart(0).getContent()); assertEquals("test-attachment", mp.getBodyPart(1).getContent()); mail.reset(); }