1 | package fr.sii.ogham.core.message.content; | |
2 | ||
3 | import fr.sii.ogham.core.resource.path.ResourcePath; | |
4 | import fr.sii.ogham.core.resource.path.UnresolvedPath; | |
5 | import fr.sii.ogham.core.template.context.BeanContext; | |
6 | import fr.sii.ogham.core.template.context.Context; | |
7 | import fr.sii.ogham.core.template.context.NullContext; | |
8 | import fr.sii.ogham.core.util.EqualsBuilder; | |
9 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
10 | ||
11 | /** | |
12 | * Content that points to a template. The template contains variables. The | |
13 | * template will be evaluated with the provided context (variable values). | |
14 | * | |
15 | * @author Aurélien Baudet | |
16 | * | |
17 | */ | |
18 | public class TemplateContent implements Content, HasResourcePath { | |
19 | /** | |
20 | * The path to the template | |
21 | */ | |
22 | private ResourcePath path; | |
23 | ||
24 | /** | |
25 | * The context (variable values) | |
26 | */ | |
27 | private Context context; | |
28 | ||
29 | | |
30 | /** | |
31 | * Initialize the content with the path to the template and the context. | |
32 | * | |
33 | * @param path | |
34 | * the path to the template | |
35 | * @param context | |
36 | * the context (variable values) | |
37 | */ | |
38 | public TemplateContent(ResourcePath path, Context context) { | |
39 | super(); | |
40 | this.path = path; | |
41 |
4
1. <init> : negated conditional → NO_COVERAGE 2. <init> : negated conditional → SURVIVED 3. <init> : negated conditional → TIMED_OUT 4. <init> : negated conditional → KILLED |
this.context = context != null ? context : new NullContext(); |
42 | } | |
43 | ||
44 | /** | |
45 | * Initialize the content with the path to the template and the context. | |
46 | * | |
47 | * @param path | |
48 | * the path to the template as string | |
49 | * @param context | |
50 | * the context (variable values) | |
51 | */ | |
52 | public TemplateContent(String path, Context context) { | |
53 | this(new UnresolvedPath(path), context); | |
54 | } | |
55 | ||
56 | /** | |
57 | * Shortcut for directly using any object as source for variable | |
58 | * substitutions. | |
59 | * | |
60 | * @param path | |
61 | * the path to the template | |
62 | * @param bean | |
63 | * the object that contains the variable values | |
64 | */ | |
65 | public TemplateContent(ResourcePath path, Object bean) { | |
66 |
2
1. <init> : negated conditional → NO_COVERAGE 2. <init> : negated conditional → KILLED |
this(path, bean != null ? new BeanContext(bean) : new NullContext()); |
67 | } | |
68 | ||
69 | /** | |
70 | * Shortcut for directly using any object as source for variable | |
71 | * substitutions. | |
72 | * | |
73 | * @param path | |
74 | * the path to the template | |
75 | * @param bean | |
76 | * the object that contains the variable values | |
77 | */ | |
78 | public TemplateContent(String path, Object bean) { | |
79 |
3
1. <init> : negated conditional → NO_COVERAGE 2. <init> : negated conditional → TIMED_OUT 3. <init> : negated conditional → KILLED |
this(path, bean != null ? new BeanContext(bean) : new NullContext()); |
80 | } | |
81 | ||
82 | @Override | |
83 | public ResourcePath getPath() { | |
84 |
4
1. getPath : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getPath → NO_COVERAGE 2. getPath : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getPath → TIMED_OUT 3. getPath : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getPath → KILLED 4. getPath : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getPath → KILLED |
return path; |
85 | } | |
86 | ||
87 | public Context getContext() { | |
88 |
4
1. getContext : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getContext → NO_COVERAGE 2. getContext : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getContext → TIMED_OUT 3. getContext : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getContext → KILLED 4. getContext : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getContext → KILLED |
return context; |
89 | } | |
90 | ||
91 | @Override | |
92 | public String toString() { | |
93 | StringBuilder builder = new StringBuilder(); | |
94 | builder.append("TemplateContent [path=").append(path).append(", context=").append(context).append("]"); | |
95 |
3
1. toString : replaced return value with "" for fr/sii/ogham/core/message/content/TemplateContent::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/core/message/content/TemplateContent::toString → SURVIVED 3. toString : replaced return value with "" for fr/sii/ogham/core/message/content/TemplateContent::toString → TIMED_OUT |
return builder.toString(); |
96 | } | |
97 | ||
98 | @Override | |
99 | public int hashCode() { | |
100 |
2
1. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/TemplateContent::hashCode → NO_COVERAGE 2. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/TemplateContent::hashCode → KILLED |
return new HashCodeBuilder().append(path, context).hashCode(); |
101 | } | |
102 | ||
103 | @Override | |
104 | public boolean equals(Object obj) { | |
105 |
4
1. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/TemplateContent::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/TemplateContent::equals → NO_COVERAGE 3. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/TemplateContent::equals → KILLED 4. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/TemplateContent::equals → KILLED |
return new EqualsBuilder(this, obj).appendFields("path", "context").isEqual(); |
106 | } | |
107 | } | |
Mutations | ||
41 |
1.1 2.2 3.3 4.4 |
|
66 |
1.1 2.2 |
|
79 |
1.1 2.2 3.3 |
|
84 |
1.1 2.2 3.3 4.4 |
|
88 |
1.1 2.2 3.3 4.4 |
|
95 |
1.1 2.2 3.3 |
|
100 |
1.1 2.2 |
|
105 |
1.1 2.2 3.3 4.4 |