| 1 | package fr.sii.ogham.core.filler; | |
| 2 | ||
| 3 | import java.util.Map; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper; | |
| 6 | import fr.sii.ogham.core.exception.filler.FillMessageException; | |
| 7 | import fr.sii.ogham.core.message.Message; | |
| 8 | ||
| 9 | /** | |
| 10 | * Base class to help to fill a particular {@link Message} type. | |
| 11 | * | |
| 12 | * @author Aurélien Baudet | |
| 13 | * | |
| 14 | * @param <M> | |
| 15 | * the type of the message that the filler is able to handle | |
| 16 | */ | |
| 17 | public abstract class AbstractMessageAwareFiller<M> implements MessageFiller { | |
| 18 | protected final Map<String, ConfigurationValueBuilderHelper<?, ?>> defaultValues; | |
| 19 | private final Class<M> messageType; | |
| 20 | ||
| 21 | /** | |
| 22 | * The list of properties is indexed by an alias that is known by the | |
| 23 | * implementation. For example, if the keys is defined like this: | |
| 24 | * | |
| 25 | * <pre> | |
| 26 | * Map<String, List<String>> keys = new HashMap<>(); | |
| 27 | * keys.put("to", valueBuilder.properties("ogham.email.to.default-value")); | |
| 28 | * keys.put("from", valueBuilder.properties("ogham.email.from.default-value", "mail.smtp.from")); | |
| 29 | * </pre> | |
| 30 | * | |
| 31 | * The implementation can then retrieve real property value using map key | |
| 32 | * (alias): | |
| 33 | * | |
| 34 | * <pre> | |
| 35 | * getProperty("from"); | |
| 36 | * // will return either the value of "ogham.email.from.default-value" or | |
| 37 | * // "mail.smtp.from" | |
| 38 | * </pre> | |
| 39 | * | |
| 40 | * @param defaultValues | |
| 41 | * a list of property keys indexed by an alias | |
| 42 | * @param messageType | |
| 43 | * the class of the message that this implementation can handle | |
| 44 | */ | |
| 45 | protected AbstractMessageAwareFiller(Map<String, ConfigurationValueBuilderHelper<?, ?>> defaultValues, Class<M> messageType) { | |
| 46 | super(); | |
| 47 | this.defaultValues = defaultValues; | |
| 48 | this.messageType = messageType; | |
| 49 | } | |
| 50 | ||
| 51 | @SuppressWarnings("unchecked") | |
| 52 | @Override | |
| 53 | public void fill(Message message) throws FillMessageException { | |
| 54 |
5
1. fill : negated conditional → NO_COVERAGE 2. fill : negated conditional → SURVIVED 3. fill : negated conditional → TIMED_OUT 4. fill : negated conditional → KILLED 5. fill : negated conditional → KILLED |
if (messageType.isAssignableFrom(message.getClass())) { |
| 55 |
5
1. fill : removed call to fr/sii/ogham/core/filler/AbstractMessageAwareFiller::fill → SURVIVED 2. fill : removed call to fr/sii/ogham/core/filler/AbstractMessageAwareFiller::fill → NO_COVERAGE 3. fill : removed call to fr/sii/ogham/core/filler/AbstractMessageAwareFiller::fill → TIMED_OUT 4. fill : removed call to fr/sii/ogham/core/filler/AbstractMessageAwareFiller::fill → KILLED 5. fill : removed call to fr/sii/ogham/core/filler/AbstractMessageAwareFiller::fill → KILLED |
fill((M) message); |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | protected abstract void fill(M message); | |
| 60 | ||
| 61 | /** | |
| 62 | * Return whether the given property alias has at least one property key | |
| 63 | * that is available for resolution, i.e., the value for the given key is | |
| 64 | * not {@code null}. | |
| 65 | * | |
| 66 | * @param alias | |
| 67 | * the property alias to resolve | |
| 68 | * @return true if property exists, false otherwise | |
| 69 | */ | |
| 70 | protected boolean containsProperty(String alias) { | |
| 71 | ConfigurationValueBuilderHelper<?, ?> valueBuilder = defaultValues.get(alias); | |
| 72 |
17
1. containsProperty : replaced boolean return with true for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::containsProperty → NO_COVERAGE 2. containsProperty : negated conditional → SURVIVED 3. containsProperty : negated conditional → NO_COVERAGE 4. containsProperty : negated conditional → NO_COVERAGE 5. containsProperty : replaced boolean return with true for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::containsProperty → TIMED_OUT 6. containsProperty : negated conditional → TIMED_OUT 7. containsProperty : negated conditional → TIMED_OUT 8. containsProperty : replaced boolean return with true for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::containsProperty → KILLED 9. containsProperty : replaced boolean return with true for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::containsProperty → KILLED 10. containsProperty : replaced boolean return with true for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::containsProperty → KILLED 11. containsProperty : replaced boolean return with true for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::containsProperty → KILLED 12. containsProperty : negated conditional → KILLED 13. containsProperty : negated conditional → KILLED 14. containsProperty : negated conditional → KILLED 15. containsProperty : negated conditional → KILLED 16. containsProperty : negated conditional → KILLED 17. containsProperty : negated conditional → KILLED |
return valueBuilder != null && valueBuilder.getValue() != null; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Returns the value of first property represented by the provided alias | |
| 77 | * that has a value (not {@code null}). | |
| 78 | * | |
| 79 | * @param alias | |
| 80 | * the property alias to resolve | |
| 81 | * @param valueClass | |
| 82 | * the class of the resulting value | |
| 83 | * @param <T> | |
| 84 | * the type of the resulting value | |
| 85 | * @return the property value or null | |
| 86 | */ | |
| 87 | @SuppressWarnings("unchecked") | |
| 88 | protected <T> T getProperty(String alias, Class<T> valueClass) { | |
| 89 | ConfigurationValueBuilderHelper<?, T> valueBuilder = (ConfigurationValueBuilderHelper<?, T>) defaultValues.get(alias); | |
| 90 |
6
1. getProperty : negated conditional → NO_COVERAGE 2. getProperty : replaced return value with null for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::getProperty → NO_COVERAGE 3. getProperty : negated conditional → KILLED 4. getProperty : negated conditional → KILLED 5. getProperty : replaced return value with null for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::getProperty → KILLED 6. getProperty : replaced return value with null for fr/sii/ogham/core/filler/AbstractMessageAwareFiller::getProperty → KILLED |
return valueBuilder == null ? null : valueBuilder.getValue(); |
| 91 | } | |
| 92 | } | |
Mutations | ||
| 54 |
1.1 2.2 3.3 4.4 5.5 |
|
| 55 |
1.1 2.2 3.3 4.4 5.5 |
|
| 72 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 14.14 15.15 16.16 17.17 |
|
| 90 |
1.1 2.2 3.3 4.4 5.5 6.6 |