FirstExistingPropertiesResolver.java

1
package fr.sii.ogham.core.env;
2
3
import java.util.Arrays;
4
import java.util.List;
5
6
/**
7
 * Resolve properties by requesting delegates.
8
 * 
9
 * The first registered delegate is requested for a property value or existence.
10
 * If the first resolver can provide the property (property exists), then the
11
 * property value is returned. If the first can't provide the property, then the
12
 * second is requested and so on until one resolver can provide the value.
13
 * 
14
 * @author Aurélien Baudet
15
 *
16
 */
17
public class FirstExistingPropertiesResolver implements PropertyResolver {
18
	private final List<PropertyResolver> delegates;
19
20
	/**
21
	 * Initialize the resolver with a list of sub-resolvers that will be
22
	 * executed in order to search for a property value.
23
	 * 
24
	 * @param delegates
25
	 *            the ordered list of resolvers
26
	 */
27
	public FirstExistingPropertiesResolver(PropertyResolver... delegates) {
28
		this(Arrays.asList(delegates));
29
	}
30
31
	/**
32
	 * Initialize the resolver with a list of sub-resolvers that will be
33
	 * executed in order to search for a property value.
34
	 * 
35
	 * @param delegates
36
	 *            the ordered list of resolvers
37
	 */
38
	public FirstExistingPropertiesResolver(List<PropertyResolver> delegates) {
39
		super();
40
		this.delegates = delegates;
41
	}
42
43
	@Override
44
	public boolean containsProperty(String key) {
45
		for (PropertyResolver resolver : delegates) {
46 4 1. containsProperty : negated conditional → NO_COVERAGE
2. containsProperty : negated conditional → SURVIVED
3. containsProperty : negated conditional → KILLED
4. containsProperty : negated conditional → KILLED
			if (resolver.containsProperty(key)) {
47 3 1. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → NO_COVERAGE
2. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED
3. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED
				return true;
48
			}
49
		}
50 4 1. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → NO_COVERAGE
2. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED
3. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED
4. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED
		return false;
51
	}
52
53
	@Override
54
	public String getProperty(String key) {
55
		for (PropertyResolver resolver : delegates) {
56 4 1. getProperty : negated conditional → SURVIVED
2. getProperty : negated conditional → NO_COVERAGE
3. getProperty : negated conditional → TIMED_OUT
4. getProperty : negated conditional → KILLED
			if (resolver.containsProperty(key)) {
57 4 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → SURVIVED
3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT
4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
				return resolver.getProperty(key);
58
			}
59
		}
60 5 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT
3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
5. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
		return null;
61
	}
62
63
	@Override
64
	public String getProperty(String key, String defaultValue) {
65
		for (PropertyResolver resolver : delegates) {
66 4 1. getProperty : negated conditional → SURVIVED
2. getProperty : negated conditional → NO_COVERAGE
3. getProperty : negated conditional → TIMED_OUT
4. getProperty : negated conditional → KILLED
			if (resolver.containsProperty(key)) {
67 5 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → SURVIVED
2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT
4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
5. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
				return resolver.getProperty(key, defaultValue);
68
			}
69
		}
70 5 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT
3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
5. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
		return defaultValue;
71
	}
72
73
	@Override
74
	public <T> T getProperty(String key, Class<T> targetType) {
75
		for (PropertyResolver resolver : delegates) {
76 7 1. getProperty : negated conditional → NO_COVERAGE
2. getProperty : negated conditional → TIMED_OUT
3. getProperty : negated conditional → KILLED
4. getProperty : negated conditional → KILLED
5. getProperty : negated conditional → KILLED
6. getProperty : negated conditional → KILLED
7. getProperty : negated conditional → KILLED
			if (resolver.containsProperty(key)) {
77 7 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
2. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT
3. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
4. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
5. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
6. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
7. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED
				return resolver.getProperty(key, targetType);
78
			}
79
		}
80
		return null;
81
	}
82
83
	@Override
84
	public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
85
		for (PropertyResolver resolver : delegates) {
86 1 1. getProperty : negated conditional → NO_COVERAGE
			if (resolver.containsProperty(key)) {
87 1 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
				return resolver.getProperty(key, targetType, defaultValue);
88
			}
89
		}
90 1 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE
		return defaultValue;
91
	}
92
93
	@Override
94
	public String getRequiredProperty(String key) {
95
		for (PropertyResolver resolver : delegates) {
96 1 1. getRequiredProperty : negated conditional → NO_COVERAGE
			if (resolver.containsProperty(key)) {
97 1 1. getRequiredProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE
				return resolver.getRequiredProperty(key);
98
			}
99
		}
100
		throw new IllegalStateException("no value for required property " + key);
101
	}
102
103
	@Override
104
	public <T> T getRequiredProperty(String key, Class<T> targetType) {
105
		for (PropertyResolver resolver : delegates) {
106 1 1. getRequiredProperty : negated conditional → NO_COVERAGE
			if (resolver.containsProperty(key)) {
107 1 1. getRequiredProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE
				return resolver.getRequiredProperty(key, targetType);
108
			}
109
		}
110
		throw new IllegalStateException("no value for required property " + key);
111
	}
112
113
}

Mutations

46

1.1
Location : containsProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
negated conditional → KILLED

2.2
Location : containsProperty
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : containsProperty
Killed by : none
negated conditional → SURVIVED

4.4
Location : containsProperty
Killed by : oghamall.it.configuration.EmptyBuilderTest.manualJavaMailConfigurationCanSendEmail(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

47

1.1
Location : containsProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED

2.2
Location : containsProperty
Killed by : oghamall.it.configuration.EmptyBuilderTest.manualJavaMailConfigurationCanSendEmail(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED

3.3
Location : containsProperty
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → NO_COVERAGE

50

1.1
Location : containsProperty
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED

2.2
Location : containsProperty
Killed by : oghamall.it.email.EmailCustomImplTest.simple(oghamall.it.email.EmailCustomImplTest)
replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED

3.3
Location : containsProperty
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → NO_COVERAGE

4.4
Location : containsProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED

56

1.1
Location : getProperty
Killed by : none
negated conditional → SURVIVED

2.2
Location : getProperty
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : getProperty
Killed by : none
negated conditional → TIMED_OUT

4.4
Location : getProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
negated conditional → KILLED

57

1.1
Location : getProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

2.2
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

3.3
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT

4.4
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → SURVIVED

60

1.1
Location : getProperty
Killed by : oghamall.it.configuration.EmptyBuilderTest.manualJavaMailConfigurationCanSendEmail(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

2.2
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT

3.3
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

4.4
Location : getProperty
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

5.5
Location : getProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

66

1.1
Location : getProperty
Killed by : none
negated conditional → SURVIVED

2.2
Location : getProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
negated conditional → KILLED

3.3
Location : getProperty
Killed by : none
negated conditional → TIMED_OUT

4.4
Location : getProperty
Killed by : none
negated conditional → NO_COVERAGE

67

1.1
Location : getProperty
Killed by : oghamall.it.configuration.JavaMailConfigurationTest.asDeveloperIDefineHostUsingProperties(oghamall.it.configuration.JavaMailConfigurationTest)
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

2.2
Location : getProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

3.3
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → SURVIVED

4.4
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

5.5
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT

70

1.1
Location : getProperty
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

2.2
Location : getProperty
Killed by : oghamcore.ut.core.env.FirstExistingPropertiesResolverSpec
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

3.3
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

4.4
Location : getProperty
Killed by : oghamall.it.configuration.EmptyBuilderTest.manualJavaMailConfigurationCanSendEmail(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

5.5
Location : getProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT

76

1.1
Location : getProperty
Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest)
negated conditional → KILLED

2.2
Location : getProperty
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : getProperty
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
negated conditional → KILLED

4.4
Location : getProperty
Killed by : oghamcore.it.core.configuration.ConfigurationLifecycleSpec
negated conditional → KILLED

5.5
Location : getProperty
Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest)
negated conditional → KILLED

6.6
Location : getProperty
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
negated conditional → KILLED

7.7
Location : getProperty
Killed by : none
negated conditional → TIMED_OUT

77

1.1
Location : getProperty
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

2.2
Location : getProperty
Killed by : none
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT

3.3
Location : getProperty
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

4.4
Location : getProperty
Killed by : none
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

5.5
Location : getProperty
Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest)
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

6.6
Location : getProperty
Killed by : oghamcore.it.core.configuration.ConfigurationLifecycleSpec
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

7.7
Location : getProperty
Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest)
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED

86

1.1
Location : getProperty
Killed by : none
negated conditional → NO_COVERAGE

87

1.1
Location : getProperty
Killed by : none
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

90

1.1
Location : getProperty
Killed by : none
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

96

1.1
Location : getRequiredProperty
Killed by : none
negated conditional → NO_COVERAGE

97

1.1
Location : getRequiredProperty
Killed by : none
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE

106

1.1
Location : getRequiredProperty
Killed by : none
negated conditional → NO_COVERAGE

107

1.1
Location : getRequiredProperty
Killed by : none
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM