SingleContentBuilder.java

1
package fr.sii.ogham.core.message.fluent;
2
3
import fr.sii.ogham.core.message.content.Content;
4
import fr.sii.ogham.core.message.content.StringContent;
5
import fr.sii.ogham.core.message.content.StringTemplateContent;
6
import fr.sii.ogham.core.message.content.TemplateContent;
7
import fr.sii.ogham.core.resource.path.ResourcePath;
8
import fr.sii.ogham.core.template.context.Context;
9
10
/**
11
 * Fluent API to build a single content based on:
12
 * <ul>
13
 * <li>Either a string</li>
14
 * <li>Or a template string</li>
15
 * <li>Or a template loaded from a path</li>
16
 * </ul>
17
 * 
18
 * @author Aurélien Baudet
19
 *
20
 * @param <P>
21
 *            the type of the parent for fluent chaining
22
 * @since 3.0.0
23
 */
24
public class SingleContentBuilder<P> {
25
	private final P parent;
26
	private Content content;
27
28
	/**
29
	 * Initializes with the parent to go back to.
30
	 * 
31
	 * @param parent
32
	 *            the parent instance
33
	 */
34
	public SingleContentBuilder(P parent) {
35
		super();
36
		this.parent = parent;
37
	}
38
39
	/**
40
	 * Set the content directly as a simple string.
41
	 * 
42
	 * <p>
43
	 * If this method is called several times, only the last value is used.
44
	 * 
45
	 * <p>
46
	 * If any other method of this class was called before calling this method,
47
	 * only the value of this method is used.
48
	 * 
49
	 * @param content
50
	 *            the content as a string
51
	 * @return the instance for fluent chaining
52
	 */
53
	public P string(String content) {
54
		this.content = new StringContent(content);
55 3 1. string : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::string → NO_COVERAGE
2. string : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::string → KILLED
3. string : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::string → KILLED
		return parent;
56
	}
57
58
	/**
59
	 * Set the content using a template (directly provided as a string). The
60
	 * template contains variables that are evaluated against the bean object.
61
	 * 
62
	 * <p>
63
	 * If this method is called several times, only the last value is used.
64
	 * 
65
	 * <p>
66
	 * If any other method of this class was called before calling this method,
67
	 * only the value of this method is used.
68
	 * 
69
	 * @param template
70
	 *            the template directly provided as a string
71
	 * @param bean
72
	 *            the object that contains the variables that are referenced in
73
	 *            the template
74
	 * @return the instance for fluent chaining
75
	 */
76
	public P templateString(String template, Object bean) {
77
		this.content = new StringTemplateContent(template, bean);
78 2 1. templateString : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::templateString → NO_COVERAGE
2. templateString : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::templateString → KILLED
		return parent;
79
	}
80
81
	/**
82
	 * Set the content using a template (directly provided as a string). The
83
	 * template contains variables that are evaluated against the evaluation
84
	 * context. The context contains at least the values of the variables but
85
	 * can also contain additional information for parsing the template.
86
	 * 
87
	 * <p>
88
	 * If this method is called several times, only the last value is used.
89
	 * 
90
	 * <p>
91
	 * If any other method of this class was called before calling this method,
92
	 * only the value of this method is used.
93
	 * 
94
	 * @param template
95
	 *            the template directly provided as a string
96
	 * @param context
97
	 *            contains at least the variables that are referenced in the
98
	 *            template and may contain additional information to parse the
99
	 *            template
100
	 * @return the instance for fluent chaining
101
	 */
102
	public P templateString(String template, Context context) {
103
		this.content = new StringTemplateContent(template, context);
104 1 1. templateString : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::templateString → NO_COVERAGE
		return parent;
105
	}
106
107
	/**
108
	 * Set the content using a template loaded from a path. The template
109
	 * contains variables that are evaluated against the bean object.
110
	 * 
111
	 * <p>
112
	 * If this method is called several times, only the last value is used.
113
	 * 
114
	 * <p>
115
	 * If any other method of this class was called before calling this method,
116
	 * only the value of this method is used.
117
	 * 
118
	 * @param templatePath
119
	 *            the path to the template
120
	 * @param bean
121
	 *            the object that contains the variables that are referenced in
122
	 *            the template
123
	 * @return the instance for fluent chaining
124
	 */
125
	public P template(String templatePath, Object bean) {
126
		this.content = new TemplateContent(templatePath, bean);
127 2 1. template : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE
2. template : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → KILLED
		return parent;
128
	}
129
130
	/**
131
	 * Set the content using a template loaded from a path. The template
132
	 * contains variables that are evaluated against the bean object.
133
	 * 
134
	 * <p>
135
	 * If this method is called several times, only the last value is used.
136
	 * 
137
	 * <p>
138
	 * If any other method of this class was called before calling this method,
139
	 * only the value of this method is used.
140
	 * 
141
	 * @param templatePath
142
	 *            the path to the template
143
	 * @param bean
144
	 *            the object that contains the variables that are referenced in
145
	 *            the template
146
	 * @return the instance for fluent chaining
147
	 */
148
	public P template(ResourcePath templatePath, Object bean) {
149
		this.content = new TemplateContent(templatePath, bean);
150 1 1. template : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE
		return parent;
151
	}
152
153
	/**
154
	 * Set the content using a template loaded from a path. The template
155
	 * contains variables that are evaluated against the evaluation context. The
156
	 * context contains at least the values of the variables but can also
157
	 * contain additional information for parsing the template.
158
	 * 
159
	 * <p>
160
	 * If this method is called several times, only the last value is used.
161
	 * 
162
	 * <p>
163
	 * If any other method of this class was called before calling this method,
164
	 * only the value of this method is used.
165
	 * 
166
	 * @param templatePath
167
	 *            the path to the template
168
	 * @param context
169
	 *            contains at least the variables that are referenced in the
170
	 *            template and may contain additional information to parse the
171
	 *            template
172
	 * @return the instance for fluent chaining
173
	 */
174
	public P template(String templatePath, Context context) {
175
		this.content = new TemplateContent(templatePath, context);
176 2 1. template : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE
2. template : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → KILLED
		return parent;
177
	}
178
179
	/**
180
	 * Set the content using a template loaded from a path. The template
181
	 * contains variables that are evaluated against the evaluation context. The
182
	 * context contains at least the values of the variables but can also
183
	 * contain additional information for parsing the template.
184
	 * 
185
	 * <p>
186
	 * If this method is called several times, only the last value is used.
187
	 * 
188
	 * <p>
189
	 * If any other method of this class was called before calling this method,
190
	 * only the value of this method is used.
191
	 * 
192
	 * @param templatePath
193
	 *            the path to the template
194
	 * @param context
195
	 *            contains at least the variables that are referenced in the
196
	 *            template and may contain additional information to parse the
197
	 *            template
198
	 * @return the instance for fluent chaining
199
	 */
200
	public P template(ResourcePath templatePath, Context context) {
201
		this.content = new TemplateContent(templatePath, context);
202 1 1. template : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE
		return parent;
203
	}
204
205
	/**
206
	 * Build the final {@link Content}. Only the last registered content is used
207
	 * (the last call to any method of this class)
208
	 * 
209
	 * @return the built content
210
	 */
211
	public Content build() {
212 4 1. build : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → NO_COVERAGE
2. build : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → SURVIVED
3. build : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → KILLED
4. build : replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → KILLED
		return content;
213
	}
214
}

Mutations

55

1.1
Location : string
Killed by : oghamall.it.email.FluentEmailTest.bodyString(oghamall.it.email.FluentEmailTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::string → KILLED

2.2
Location : string
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::string → NO_COVERAGE

3.3
Location : string
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::string → KILLED

78

1.1
Location : templateString
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::templateString → NO_COVERAGE

2.2
Location : templateString
Killed by : oghamall.it.email.FluentEmailTest.bodyTemplateString(oghamall.it.email.FluentEmailTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::templateString → KILLED

104

1.1
Location : templateString
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::templateString → NO_COVERAGE

127

1.1
Location : template
Killed by : oghamall.it.retry.AutoRetryTest.doNotResendSmsIfInvalidTemplate(oghamall.it.retry.AutoRetryTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → KILLED

2.2
Location : template
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE

150

1.1
Location : template
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE

176

1.1
Location : template
Killed by : oghamall.it.retry.AutoRetryTest.doNotResendSmsIfTemplateNotFound(oghamall.it.retry.AutoRetryTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → KILLED

2.2
Location : template
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE

202

1.1
Location : template
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::template → NO_COVERAGE

212

1.1
Location : build
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → NO_COVERAGE

2.2
Location : build
Killed by : oghamall.it.email.FluentEmailTest.bodyString(oghamall.it.email.FluentEmailTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → KILLED

3.3
Location : build
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → KILLED

4.4
Location : build
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/fluent/SingleContentBuilder::build → SURVIVED

Active mutators

Tests examined


Report generated by PIT OGHAM