##### Coverage Report - org.jbehave.core.reporters.FreemarkerProcessor

Classes in this File | Line Coverage | Branch Coverage | Complexity
FreemarkerProcessor |
100% | 15/15
N/A | N/A
| 1.4;1.4
FreemarkerProcessor$FreemarkerProcessingFailed |
100% | 2/2
N/A | N/A
| 1.4;1.4

1 |  |
     package org.jbehave.core.reporters;
2 |  |
3 |  |
     import java.io.Writer;
4 |  |
     import java.util.Map;
5 |  |
6 |  |
     import freemarker.template.Configuration;
7 |  |
     import freemarker.template.ObjectWrapper;
8 |  |
9 |  |
     public class FreemarkerProcessor implements TemplateProcessor {
10 |  |
         private Class<?> templateLoadingFrom;
11 |  |
12 |  |
         public FreemarkerProcessor() {
13 | 1007 |
             this(FreemarkerProcessor.class);
14 | 1007 |
         }
15 |  |
16 | 1007 |
         public FreemarkerProcessor(Class<?> templateLoadingFrom) {
17 | 1007 |
             this.templateLoadingFrom = templateLoadingFrom;
18 | 1007 |
         }
19 |  |
20 |  |
         public void process(String resource, Map<String, Object> dataModel, Writer writer) {
21 | 54 |
             Configuration configuration = configuration();
22 |  |
             try {
23 | 54 |
                 configuration.getTemplate(resource).process(dataModel, writer);
24 | 1 |
             } catch (Exception e) {
25 | 1 |
                 throw new FreemarkerProcessingFailed(configuration, resource, dataModel, e);
26 | 53 |
             }
27 | 53 |
         }
28 |  |
29 |  |
         public Configuration configuration() {
30 | 54 |
             Configuration configuration = new Configuration();
31 | 54 |
             configuration.setClassForTemplateLoading(templateLoadingFrom, "/");
32 | 54 |
             configuration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
33 | 54 |
             return configuration;
34 |  |
         }
35 |  |
36 |  |
         @SuppressWarnings("serial")
37 |  |
         public static class FreemarkerProcessingFailed extends RuntimeException {
38 |  |
39 |  |
             public FreemarkerProcessingFailed(Configuration configuration, String resource, Map<String, Object> dataModel, Exception cause) {
40 | 1 |
                 super("Freemarker failed to process template " + resource + " using configuration "+configuration + " and data model "+dataModel, cause);
41 | 1 |
             }
42 |  |
43 |  |
         }
44 |  |
45 |  |
     }