CidBuilder.java

1
package fr.sii.ogham.email.builder;
2
3
import fr.sii.ogham.core.builder.Builder;
4
import fr.sii.ogham.core.builder.context.BuildContext;
5
import fr.sii.ogham.core.fluent.AbstractParent;
6
import fr.sii.ogham.core.id.generator.IdGenerator;
7
import fr.sii.ogham.core.id.generator.SequentialIdGenerator;
8
import fr.sii.ogham.email.message.Email;
9
10
/**
11
 * Configures how images are attached to {@link Email}s.
12
 * 
13
 * Image defined in a html must be referenced by a
14
 * <a href="https://tools.ietf.org/html/rfc4021#section-2.2.2">Content-ID (or
15
 * CID)</a> if the image is attached to the email. You can define how CIDs are
16
 * generated.
17
 * 
18
 * 
19
 * @author Aurélien Baudet
20
 *
21
 */
22
public class CidBuilder extends AbstractParent<AttachImageBuilder> implements Builder<IdGenerator> {
23
	private final BuildContext buildContext;
24
	private IdGenerator idGenerator;
25
	private boolean sequential;
26
27
	/**
28
	 * Initializes with the parent (used when calling {@link #and()} method for
29
	 * fluent chaining).
30
	 * 
31
	 * @param parent
32
	 *            the parent builder
33
	 * @param buildContext
34
	 *            for registering instances and property evaluation
35
	 */
36
	public CidBuilder(AttachImageBuilder parent, BuildContext buildContext) {
37
		super(parent);
38
		this.buildContext = buildContext;
39
	}
40
41
	/**
42
	 * Image defined in a html must be referenced by a
43
	 * <a href="https://tools.ietf.org/html/rfc4021#section-2.2.2">Content-ID
44
	 * (or CID)</a> if the image is attached to the email. You can define how
45
	 * CIDs are generated by defining an {@link IdGenerator}.
46
	 * 
47
	 * <p>
48
	 * Use this method to provide custom CID generation strategy.
49
	 * 
50
	 * <p>
51
	 * Any call to this method preempts any other configuration.
52
	 * 
53
	 * <p>
54
	 * If this method is called several times, only the last provided value is
55
	 * used.
56
	 * 
57
	 * <p>
58
	 * If {@code null} value is provided, it disables custom generator.
59
	 * 
60
	 * @param generator
61
	 *            the cid generator
62
	 * @return this instance for fluent chaining
63
	 */
64
	public CidBuilder generator(IdGenerator generator) {
65
		idGenerator = generator;
66 1 1. generator : replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::generator → NO_COVERAGE
		return this;
67
	}
68
69
	/**
70
	 * Image defined in a html must be referenced by a
71
	 * <a href="https://tools.ietf.org/html/rfc4021#section-2.2.2">Content-ID
72
	 * (or CID)</a> if the image is attached to the email. You can define how
73
	 * CIDs are generated by defining an {@link IdGenerator}.
74
	 * 
75
	 * <p>
76
	 * Enables basic sequential CID generation: 0, 1, 2, 3...
77
	 * 
78
	 * 
79
	 * @return this instance for fluent chaining
80
	 */
81
	public CidBuilder sequential() {
82
		this.sequential = true;
83 1 1. sequential : replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::sequential → RUN_ERROR
		return this;
84
	}
85
86
	@Override
87
	public IdGenerator build() {
88 1 1. build : negated conditional → RUN_ERROR
		if (idGenerator != null) {
89 1 1. build : replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::build → NO_COVERAGE
			return idGenerator;
90
		}
91 1 1. build : negated conditional → RUN_ERROR
		if (sequential) {
92 1 1. build : replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::build → RUN_ERROR
			return buildContext.register(new SequentialIdGenerator());
93
		}
94
		return null;
95
	}
96
}

Mutations

66

1.1
Location : generator
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::generator → NO_COVERAGE

83

1.1
Location : sequential
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::sequential → RUN_ERROR

88

1.1
Location : build
Killed by :
negated conditional → RUN_ERROR

89

1.1
Location : build
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::build → NO_COVERAGE

91

1.1
Location : build
Killed by :
negated conditional → RUN_ERROR

92

1.1
Location : build
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/CidBuilder::build → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1