AutofillSmsBuilder.java

1
package fr.sii.ogham.sms.builder;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
6
import fr.sii.ogham.core.builder.Builder;
7
import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper;
8
import fr.sii.ogham.core.builder.context.BuildContext;
9
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
10
import fr.sii.ogham.core.filler.EveryFillerDecorator;
11
import fr.sii.ogham.core.filler.MessageFiller;
12
import fr.sii.ogham.core.fluent.AbstractParent;
13
import fr.sii.ogham.sms.filler.SmsFiller;
14
import fr.sii.ogham.sms.message.Sms;
15
16
/**
17
 * Configures how Ogham will add default values to the {@link Sms} if some
18
 * information is missing.
19
 * 
20
 * If sender phone number is missing, a default one can be defined in
21
 * configuration properties.
22
 * 
23
 * If recipient phone number is missing, a default one can be defined in
24
 * configuration properties.
25
 * 
26
 * @author Aurélien Baudet
27
 * @see SmsFiller
28
 *
29
 */
30
public class AutofillSmsBuilder extends AbstractParent<SmsBuilder> implements Builder<MessageFiller> {
31
	private final BuildContext buildContext;
32
	private AutofillDefaultPhoneNumberBuilder<String> senderNumberBuilder;
33
	private AutofillDefaultPhoneNumberBuilder<String[]> recipientNumberBuilder;
34
35
	/**
36
	 * Initializes with the parent builder and the {@link EnvironmentBuilder}.
37
	 * The parent builder is used when calling the {@link #and()} method. The
38
	 * {@link EnvironmentBuilder} is used by {@link #build()} method to evaluate
39
	 * property values.
40
	 * 
41
	 * @param parent
42
	 *            the parent builder
43
	 * @param buildContext
44
	 *            for property resolution
45
	 */
46
	public AutofillSmsBuilder(SmsBuilder parent, BuildContext buildContext) {
47
		super(parent);
48
		this.buildContext = buildContext;
49
	}
50
51
	/**
52
	 * Configures how to handle missing sender phone number: if no sender phone
53
	 * number is explicitly defined on the message, Ogham will use this phone
54
	 * number as default sender number.
55
	 * 
56
	 * @return the builder to configure default sender number
57
	 */
58
	public AutofillDefaultPhoneNumberBuilder<String> from() {
59 1 1. from : negated conditional → RUN_ERROR
		if (senderNumberBuilder == null) {
60
			senderNumberBuilder = new AutofillDefaultPhoneNumberBuilder<>(this, String.class, buildContext);
61
		}
62 1 1. from : replaced return value with null for fr/sii/ogham/sms/builder/AutofillSmsBuilder::from → RUN_ERROR
		return senderNumberBuilder;
63
	}
64
65
	/**
66
	 * Configures how to handle missing recipient phone number: if no recipient
67
	 * phone number is explicitly defined on the message, Ogham will use this
68
	 * phone number as default recipient number.
69
	 * 
70
	 * @return the builder to configure default recipient number
71
	 */
72
	public AutofillDefaultPhoneNumberBuilder<String[]> to() {
73 1 1. to : negated conditional → RUN_ERROR
		if (recipientNumberBuilder == null) {
74
			recipientNumberBuilder = new AutofillDefaultPhoneNumberBuilder<>(this, String[].class, buildContext);
75
		}
76 1 1. to : replaced return value with null for fr/sii/ogham/sms/builder/AutofillSmsBuilder::to → RUN_ERROR
		return recipientNumberBuilder;
77
	}
78
79
	@Override
80
	public MessageFiller build() {
81
		EveryFillerDecorator filler = buildContext.register(new EveryFillerDecorator());
82
		Map<String, ConfigurationValueBuilderHelper<?, ?>> props = new HashMap<>();
83
		props.put("from", (ConfigurationValueBuilderHelper<?, String>) senderNumberBuilder.defaultValue());
84
		props.put("to", (ConfigurationValueBuilderHelper<?, String[]>) recipientNumberBuilder.defaultValue());
85
		filler.addFiller(buildContext.register(new SmsFiller(props)));
86 1 1. build : replaced return value with null for fr/sii/ogham/sms/builder/AutofillSmsBuilder::build → RUN_ERROR
		return filler;
87
	}
88
}

Mutations

59

1.1
Location : from
Killed by :
negated conditional → RUN_ERROR

62

1.1
Location : from
Killed by :
replaced return value with null for fr/sii/ogham/sms/builder/AutofillSmsBuilder::from → RUN_ERROR

73

1.1
Location : to
Killed by :
negated conditional → RUN_ERROR

76

1.1
Location : to
Killed by :
replaced return value with null for fr/sii/ogham/sms/builder/AutofillSmsBuilder::to → RUN_ERROR

86

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

Active mutators

Tests examined


Report generated by PIT 1.13.1