OverrideJavaMailResolver.java

1
package fr.sii.ogham.email.builder.javamail;
2
3
import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper;
4
import fr.sii.ogham.core.convert.Converter;
5
import fr.sii.ogham.core.env.PropertyResolver;
6
7
/**
8
 * Decorate original {@link PropertyResolver} to override some values.
9
 * 
10
 * For example, if a list of hosts is provided with the following values
11
 * <code>"ogham.email.host", "mail.smtp.host"</code> then when caller asks for
12
 * <code>"mail.host"</code>, it returns:
13
 * <ul>
14
 * <li>the value of the property "ogham.email.host" if it exists</li>
15
 * <li>the value of the property "mail.smtp.host" if "ogham.email.host" doesn't
16
 * exist and "mail.smtp.host" exists</li>
17
 * <li>the value of "mail.host" otherwise</li>
18
 * </ul>
19
 * 
20
 * It works the same for ports.
21
 * 
22
 * @author Aurélien Baudet
23
 *
24
 */
25
public class OverrideJavaMailResolver implements PropertyResolver {
26
	private final PropertyResolver delegate;
27
	private final Converter converter;
28
	private final ConfigurationValueBuilderHelper<?, String> host;
29
	private final ConfigurationValueBuilderHelper<?, Integer> port;
30
31
	public OverrideJavaMailResolver(PropertyResolver delegate, Converter converter, ConfigurationValueBuilderHelper<?, String> host, ConfigurationValueBuilderHelper<?, Integer> port) {
32
		super();
33
		this.delegate = delegate;
34
		this.converter = converter;
35
		this.host = host;
36
		this.port = port;
37
	}
38
39
	@Override
40
	public boolean containsProperty(String key) {
41 1 1. containsProperty : negated conditional → RUN_ERROR
		if (getValue(key) != null) {
42 1 1. containsProperty : replaced boolean return with false for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::containsProperty → RUN_ERROR
			return true;
43
		}
44 2 1. containsProperty : replaced boolean return with false for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::containsProperty → RUN_ERROR
2. containsProperty : replaced boolean return with true for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::containsProperty → RUN_ERROR
		return delegate.containsProperty(key);
45
	}
46
47
	@Override
48
	public String getProperty(String key) {
49
		String value = getValue(key);
50 1 1. getProperty : negated conditional → RUN_ERROR
		if (value != null) {
51 1 1. getProperty : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR
			return value;
52
		}
53 1 1. getProperty : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR
		return delegate.getProperty(key);
54
	}
55
56
	@Override
57
	public String getProperty(String key, String defaultValue) {
58
		String value = getValue(key);
59 1 1. getProperty : negated conditional → RUN_ERROR
		if (value != null) {
60 1 1. getProperty : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR
			return value;
61
		}
62 1 1. getProperty : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE
		return delegate.getProperty(key, defaultValue);
63
	}
64
65
	@Override
66
	public <T> T getProperty(String key, Class<T> targetType) {
67
		String value = getValue(key);
68 1 1. getProperty : negated conditional → RUN_ERROR
		if (value != null) {
69 1 1. getProperty : replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR
			return converter.convert(value, targetType);
70
		}
71 1 1. getProperty : replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE
		return delegate.getProperty(key, targetType);
72
	}
73
74
	@Override
75
	public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
76
		String value = getValue(key);
77 1 1. getProperty : negated conditional → NO_COVERAGE
		if (value != null) {
78 1 1. getProperty : replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE
			return converter.convert(value, targetType);
79
		}
80 1 1. getProperty : replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE
		return delegate.getProperty(key, targetType, defaultValue);
81
	}
82
83
	@Override
84
	public String getRequiredProperty(String key) {
85
		String value = getValue(key);
86 1 1. getRequiredProperty : negated conditional → NO_COVERAGE
		if (value != null) {
87 1 1. getRequiredProperty : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE
			return value;
88
		}
89 1 1. getRequiredProperty : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE
		return delegate.getRequiredProperty(key);
90
	}
91
92
	@Override
93
	public <T> T getRequiredProperty(String key, Class<T> targetType) {
94
		String value = getValue(key);
95 1 1. getRequiredProperty : negated conditional → NO_COVERAGE
		if (value != null) {
96 1 1. getRequiredProperty : replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE
			return converter.convert(value, targetType);
97
		}
98 1 1. getRequiredProperty : replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE
		return delegate.getRequiredProperty(key, targetType);
99
	}
100
101
	private String getValue(String key) {
102 2 1. getValue : negated conditional → RUN_ERROR
2. getValue : negated conditional → RUN_ERROR
		if (isPortKey(key) && getPortValue() != null) {
103 1 1. getValue : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getValue → RUN_ERROR
			return getPortValue();
104
		}
105 2 1. getValue : negated conditional → RUN_ERROR
2. getValue : negated conditional → RUN_ERROR
		if (isHostKey(key) && getHostValue() != null) {
106 1 1. getValue : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getValue → RUN_ERROR
			return getHostValue();
107
		}
108 1 1. getValue : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getValue → RUN_ERROR
		return null;
109
	}
110
111
	private String getPortValue() {
112
		Integer value = port.getValue();
113 1 1. getPortValue : negated conditional → RUN_ERROR
		if (value == null) {
114 1 1. getPortValue : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getPortValue → NO_COVERAGE
			return null;
115
		}
116 1 1. getPortValue : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getPortValue → RUN_ERROR
		return String.valueOf(value);
117
	}
118
119
	private static boolean isHostKey(Object key) {
120 3 1. isHostKey : negated conditional → RUN_ERROR
2. isHostKey : replaced boolean return with true for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::isHostKey → RUN_ERROR
3. isHostKey : negated conditional → RUN_ERROR
		return "mail.smtp.host".equals(key) || "mail.host".equals(key);
121
	}
122
123
	private static boolean isPortKey(Object key) {
124 3 1. isPortKey : replaced boolean return with true for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::isPortKey → RUN_ERROR
2. isPortKey : negated conditional → RUN_ERROR
3. isPortKey : negated conditional → RUN_ERROR
		return "mail.smtp.port".equals(key) || "mail.port".equals(key);
125
	}
126
127
	private String getHostValue() {
128 1 1. getHostValue : replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getHostValue → RUN_ERROR
		return host.getValue();
129
	}
130
}

Mutations

41

1.1
Location : containsProperty
Killed by :
negated conditional → RUN_ERROR

42

1.1
Location : containsProperty
Killed by :
replaced boolean return with false for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::containsProperty → RUN_ERROR

44

1.1
Location : containsProperty
Killed by :
replaced boolean return with false for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::containsProperty → RUN_ERROR

2.2
Location : containsProperty
Killed by :
replaced boolean return with true for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::containsProperty → RUN_ERROR

50

1.1
Location : getProperty
Killed by :
negated conditional → RUN_ERROR

51

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR

53

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR

59

1.1
Location : getProperty
Killed by :
negated conditional → RUN_ERROR

60

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR

62

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE

68

1.1
Location : getProperty
Killed by :
negated conditional → RUN_ERROR

69

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → RUN_ERROR

71

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE

77

1.1
Location : getProperty
Killed by :
negated conditional → NO_COVERAGE

78

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE

80

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getProperty → NO_COVERAGE

86

1.1
Location : getRequiredProperty
Killed by :
negated conditional → NO_COVERAGE

87

1.1
Location : getRequiredProperty
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE

89

1.1
Location : getRequiredProperty
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE

95

1.1
Location : getRequiredProperty
Killed by :
negated conditional → NO_COVERAGE

96

1.1
Location : getRequiredProperty
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE

98

1.1
Location : getRequiredProperty
Killed by :
replaced return value with null for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getRequiredProperty → NO_COVERAGE

102

1.1
Location : getValue
Killed by :
negated conditional → RUN_ERROR

2.2
Location : getValue
Killed by :
negated conditional → RUN_ERROR

103

1.1
Location : getValue
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getValue → RUN_ERROR

105

1.1
Location : getValue
Killed by :
negated conditional → RUN_ERROR

2.2
Location : getValue
Killed by :
negated conditional → RUN_ERROR

106

1.1
Location : getValue
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getValue → RUN_ERROR

108

1.1
Location : getValue
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getValue → RUN_ERROR

113

1.1
Location : getPortValue
Killed by :
negated conditional → RUN_ERROR

114

1.1
Location : getPortValue
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getPortValue → NO_COVERAGE

116

1.1
Location : getPortValue
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getPortValue → RUN_ERROR

120

1.1
Location : isHostKey
Killed by :
negated conditional → RUN_ERROR

2.2
Location : isHostKey
Killed by :
replaced boolean return with true for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::isHostKey → RUN_ERROR

3.3
Location : isHostKey
Killed by :
negated conditional → RUN_ERROR

124

1.1
Location : isPortKey
Killed by :
replaced boolean return with true for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::isPortKey → RUN_ERROR

2.2
Location : isPortKey
Killed by :
negated conditional → RUN_ERROR

3.3
Location : isPortKey
Killed by :
negated conditional → RUN_ERROR

128

1.1
Location : getHostValue
Killed by :
replaced return value with "" for fr/sii/ogham/email/builder/javamail/OverrideJavaMailResolver::getHostValue → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1