|
| 1 | +/* |
| 2 | + * Copyright and related rights waived via CC0 |
| 3 | + * |
| 4 | + * You should have received a copy of the CC0 legalcode along with this |
| 5 | + * work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. |
| 6 | + */ |
| 7 | +package fm; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.io.StringWriter; |
| 11 | +import java.util.HashMap; |
| 12 | +import java.util.Map; |
| 13 | + |
| 14 | +import freemarker.template.Configuration; |
| 15 | +import freemarker.template.Template; |
| 16 | +import freemarker.template.TemplateException; |
| 17 | +import org.assertj.core.api.Assertions; |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +public class FreemarkerTest { |
| 21 | + |
| 22 | + @Test |
| 23 | + void test() throws IOException, TemplateException { |
| 24 | + Map<String, Object> root = new HashMap<>(); |
| 25 | + root.put("user", "Big Joe"); |
| 26 | + Product latest = new Product(); |
| 27 | + latest.setUrl("products/greenmouse.html"); |
| 28 | + latest.setName("green mouse"); |
| 29 | + root.put("latestProduct", latest); |
| 30 | + |
| 31 | + Configuration configuration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); |
| 32 | + configuration.setClassForTemplateLoading(this.getClass(), "/"); |
| 33 | + Template template = configuration.getTemplate("test.ftlh"); |
| 34 | + StringWriter writer = new StringWriter(); |
| 35 | + template.process(root, writer); |
| 36 | + |
| 37 | + Assertions.assertThat(writer.toString()).isNotEmpty(); |
| 38 | + } |
| 39 | + |
| 40 | +} |
0 commit comments