| 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 |
|
| 42 |
1.1 |
|
| 44 |
1.1 2.2 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 53 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 62 |
1.1 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 71 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 80 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 89 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 98 |
1.1 |
|
| 102 |
1.1 2.2 |
|
| 103 |
1.1 |
|
| 105 |
1.1 2.2 |
|
| 106 |
1.1 |
|
| 108 |
1.1 |
|
| 113 |
1.1 |
|
| 114 |
1.1 |
|
| 116 |
1.1 |
|
| 120 |
1.1 2.2 3.3 |
|
| 124 |
1.1 2.2 3.3 |
|
| 128 |
1.1 |