SimplePropertiesBuilder.java

1
package fr.sii.ogham.core.builder.env;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Properties;
6
7
import fr.sii.ogham.core.fluent.AbstractParent;
8
9
/**
10
 * A {@link PropertiesBuilder} that registers properties (key/value pairs) that
11
 * is used by an {@link EnvironmentBuilder#properties()}.
12
 * 
13
 * @author Aurélien Baudet
14
 *
15
 * @param <P>
16
 *            the type of the parent builder (when calling {@link #and()}
17
 *            method)
18
 */
19
public class SimplePropertiesBuilder<P> extends AbstractParent<P> implements PropertiesBuilder<P> {
20
	private List<Property> properties;
21
22
	/**
23
	 * Initializes the builder with the provided parent. The list of properties
24
	 * is initialized with an empty list.
25
	 * 
26
	 * @param parent
27
	 *            the parent builder
28
	 */
29
	public SimplePropertiesBuilder(P parent) {
30
		super(parent);
31
		properties = new ArrayList<>();
32
	}
33
34
	@Override
35
	public PropertiesBuilder<P> set(String key, String value) {
36
		properties.add(new Property(key, value));
37 1 1. set : replaced return value with null for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder::set → RUN_ERROR
		return this;
38
	}
39
40
	@Override
41
	public PropertiesBuilder<P> set(String key, Object value) {
42 1 1. set : negated conditional → RUN_ERROR
		properties.add(new Property(key, value == null ? null : value.toString()));
43 1 1. set : replaced return value with null for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder::set → RUN_ERROR
		return this;
44
	}
45
46
	@Override
47
	public Properties build() {
48
		Properties props = new Properties();
49
		for (Property prop : properties) {
50 2 1. build : negated conditional → RUN_ERROR
2. build : negated conditional → RUN_ERROR
			if (prop.getKey() != null && prop.getValue() != null) {
51
				props.put(prop.getKey(), prop.getValue());
52 1 1. build : negated conditional → RUN_ERROR
			} else if (prop.getValue() == null) {
53
				props.remove(prop.getKey());
54
			}
55
		}
56 1 1. build : replaced return value with null for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder::build → RUN_ERROR
		return props;
57
	}
58
59
	private static class Property {
60
		private final String key;
61
		private final String value;
62
63
		public Property(String key, String value) {
64
			super();
65
			this.key = key;
66
			this.value = value;
67
		}
68
69
		public String getKey() {
70 1 1. getKey : replaced return value with "" for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder$Property::getKey → RUN_ERROR
			return key;
71
		}
72
73
		public String getValue() {
74 1 1. getValue : replaced return value with "" for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder$Property::getValue → RUN_ERROR
			return value;
75
		}
76
	}
77
}

Mutations

37

1.1
Location : set
Killed by :
replaced return value with null for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder::set → RUN_ERROR

42

1.1
Location : set
Killed by :
negated conditional → RUN_ERROR

43

1.1
Location : set
Killed by :
replaced return value with null for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder::set → RUN_ERROR

50

1.1
Location : build
Killed by :
negated conditional → RUN_ERROR

2.2
Location : build
Killed by :
negated conditional → RUN_ERROR

52

1.1
Location : build
Killed by :
negated conditional → RUN_ERROR

56

1.1
Location : build
Killed by :
replaced return value with null for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder::build → RUN_ERROR

70

1.1
Location : getKey
Killed by :
replaced return value with "" for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder$Property::getKey → RUN_ERROR

74

1.1
Location : getValue
Killed by :
replaced return value with "" for fr/sii/ogham/core/builder/env/SimplePropertiesBuilder$Property::getValue → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1