TemplateContent.java

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 1 1. <init> : negated conditional → NO_COVERAGE
		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 1 1. <init> : negated conditional → NO_COVERAGE
		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 1 1. <init> : negated conditional → NO_COVERAGE
		this(path, bean != null ? new BeanContext(bean) : new NullContext());
80
	}
81
82
	@Override
83
	public ResourcePath getPath() {
84 1 1. getPath : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getPath → RUN_ERROR
		return path;
85
	}
86
87
	public Context getContext() {
88 1 1. getContext : replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getContext → RUN_ERROR
		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 1 1. toString : replaced return value with "" for fr/sii/ogham/core/message/content/TemplateContent::toString → NO_COVERAGE
		return builder.toString();
96
	}
97
98
	@Override
99
	public int hashCode() {
100 1 1. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/TemplateContent::hashCode → RUN_ERROR
		return new HashCodeBuilder().append(path, context).hashCode();
101
	}
102
103
	@Override
104
	public boolean equals(Object obj) {
105 2 1. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/TemplateContent::equals → RUN_ERROR
2. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/TemplateContent::equals → RUN_ERROR
		return new EqualsBuilder(this, obj).appendFields("path", "context").isEqual();
106
	}
107
}

Mutations

41

1.1
Location : <init>
Killed by :
negated conditional → NO_COVERAGE

66

1.1
Location : <init>
Killed by :
negated conditional → NO_COVERAGE

79

1.1
Location : <init>
Killed by :
negated conditional → NO_COVERAGE

84

1.1
Location : getPath
Killed by :
replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getPath → RUN_ERROR

88

1.1
Location : getContext
Killed by :
replaced return value with null for fr/sii/ogham/core/message/content/TemplateContent::getContext → RUN_ERROR

95

1.1
Location : toString
Killed by :
replaced return value with "" for fr/sii/ogham/core/message/content/TemplateContent::toString → NO_COVERAGE

100

1.1
Location : hashCode
Killed by :
replaced int return with 0 for fr/sii/ogham/core/message/content/TemplateContent::hashCode → RUN_ERROR

105

1.1
Location : equals
Killed by :
replaced boolean return with true for fr/sii/ogham/core/message/content/TemplateContent::equals → RUN_ERROR

2.2
Location : equals
Killed by :
replaced boolean return with false for fr/sii/ogham/core/message/content/TemplateContent::equals → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1