DefaultMailTemplate implements MailTemplate { @Override public String renderAsString( Locale locale, MailTemplateContext mailTemplateContext) throws IOException { UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter(); render(unsyncStringWriter, locale, mailTemplateContext); return unsyncStringWriter.toString(); } DefaultMailTemplate(String template, boolean escapeHtml); @Override void render(
			Writer writer, Locale locale,
			MailTemplateContext mailTemplateContext); @Override String renderAsString(
			Locale locale, MailTemplateContext mailTemplateContext);  }
@Test public void testEmptyTemplate() throws Exception { MailTemplate mailTemplate = new DefaultMailTemplate( StringPool.BLANK, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals(StringPool.BLANK, result); }
@Test public void testHrefAbsoluteURLRewriting() throws Exception { String template = "<a href=\"/resource\">"; MailTemplate mailTemplate = new DefaultMailTemplate(template, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals("<a href=\"http: }
@Test public void testSrcAbsoluteURLRewriting() throws Exception { String template = "<img src=\"/resource\">"; MailTemplate mailTemplate = new DefaultMailTemplate(template, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals( "<img src=\"http: }
@Test public void testTemplateWithEscapedPlaceholder() throws Exception { String template = "This template contains a [$ESCAPED_VALUE$]"; MailTemplate mailTemplate = new DefaultMailTemplate(template, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals("This template contains a <>", result); }
@Test public void testTemplateWithLocalizedPlaceholder() throws Exception { String template = "This template is in [$LOCALIZED_VALUE$]"; MailTemplate mailTemplate = new DefaultMailTemplate(template, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals("This template is in en", result); }
@Test public void testTemplateWithNoPlaceholder() throws Exception { String template = StringUtil.randomString(); MailTemplate mailTemplate = new DefaultMailTemplate(template, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals(template, result); }
@Test public void testTemplateWithPlaceholder() throws Exception { String template = "This template contains a [$PLACEHOLDER$]"; MailTemplate mailTemplate = new DefaultMailTemplate(template, false); String result = mailTemplate.renderAsString( Locale.ENGLISH, _mailTemplateContext); Assert.assertEquals("This template contains a replacement", result); }