| 1 | package fr.sii.ogham.core.condition.provider; | |
| 2 | ||
| 3 | import static fr.sii.ogham.core.condition.fluent.Conditions.alwaysTrue; | |
| 4 | import static fr.sii.ogham.core.condition.fluent.Conditions.not; | |
| 5 | import static fr.sii.ogham.core.condition.fluent.Conditions.requiredProperty; | |
| 6 | import static fr.sii.ogham.core.condition.fluent.Conditions.requiredPropertyValue; | |
| 7 | ||
| 8 | import java.util.regex.Pattern; | |
| 9 | ||
| 10 | import fr.sii.ogham.core.builder.condition.RequiredProperty; | |
| 11 | import fr.sii.ogham.core.condition.Condition; | |
| 12 | import fr.sii.ogham.core.condition.fluent.Conditions; | |
| 13 | import fr.sii.ogham.core.condition.fluent.FluentCondition; | |
| 14 | import fr.sii.ogham.core.env.PropertyResolver; | |
| 15 | ||
| 16 | /** | |
| 17 | * Provider that handle {@link RequiredProperty} annotation to provide a | |
| 18 | * condition. | |
| 19 | * | |
| 20 | * @author Aurélien Baudet | |
| 21 | * | |
| 22 | * @param <T> | |
| 23 | * the kind of the object under conditions | |
| 24 | */ | |
| 25 | public class RequiredPropertyAnnotationProvider<T> implements ConditionProvider<RequiredProperty, T> { | |
| 26 | private final PropertyResolver propertyResolver; | |
| 27 | ||
| 28 | public RequiredPropertyAnnotationProvider(PropertyResolver propertyResolver) { | |
| 29 | super(); | |
| 30 | this.propertyResolver = propertyResolver; | |
| 31 | } | |
| 32 | ||
| 33 | @Override | |
| 34 | public Condition<T> provide(RequiredProperty annotation) { | |
| 35 |
8
1. provide : negated conditional → NO_COVERAGE 2. provide : negated conditional → KILLED 3. provide : negated conditional → KILLED 4. provide : negated conditional → KILLED 5. provide : negated conditional → KILLED 6. provide : negated conditional → KILLED 7. provide : negated conditional → KILLED 8. provide : negated conditional → KILLED |
if (annotation == null) { |
| 36 |
8
1. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → NO_COVERAGE 2. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → SURVIVED 3. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED 4. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED 5. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED 6. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED 7. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED 8. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED |
return alwaysTrue(); |
| 37 | } else { | |
| 38 | FluentCondition<T> mainCondition = exists(annotation); | |
| 39 |
2
1. provide : negated conditional → NO_COVERAGE 2. provide : negated conditional → KILLED |
if (!annotation.is().isEmpty()) { |
| 40 | mainCondition = mainCondition.and(matchesValue(annotation)); | |
| 41 | } | |
| 42 |
2
1. provide : negated conditional → NO_COVERAGE 2. provide : negated conditional → KILLED |
if (!annotation.pattern().isEmpty()) { |
| 43 | mainCondition = mainCondition.and(matchesPattern(annotation)); | |
| 44 | } | |
| 45 | for (String excludeValue : annotation.excludes()) { | |
| 46 | mainCondition = mainCondition.and(not(matchesExcludes(annotation, excludeValue))); | |
| 47 | } | |
| 48 |
2
1. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → NO_COVERAGE 2. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED |
return mainCondition; |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | private FluentCondition<T> exists(RequiredProperty annotation) { | |
| 53 | FluentCondition<T> condition = requiredProperty(propertyResolver, annotation.value()); | |
| 54 | for (String alternative : annotation.alternatives()) { | |
| 55 | condition = condition.or(Conditions.<T> requiredProperty(propertyResolver, alternative)); | |
| 56 | } | |
| 57 |
2
1. exists : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::exists → NO_COVERAGE 2. exists : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::exists → KILLED |
return condition; |
| 58 | } | |
| 59 | ||
| 60 | private FluentCondition<T> matchesValue(RequiredProperty annotation) { | |
| 61 | FluentCondition<T> condition = requiredPropertyValue(propertyResolver, annotation.value(), annotation.is()); | |
| 62 | for (String alternative : annotation.alternatives()) { | |
| 63 | condition = condition.or(Conditions.<T> requiredPropertyValue(propertyResolver, alternative, annotation.is())); | |
| 64 | } | |
| 65 |
2
1. matchesValue : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesValue → NO_COVERAGE 2. matchesValue : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesValue → KILLED |
return condition; |
| 66 | } | |
| 67 | ||
| 68 | private FluentCondition<T> matchesPattern(RequiredProperty annotation) { | |
| 69 | Pattern pattern = Pattern.compile(annotation.pattern(), annotation.flags()); | |
| 70 | FluentCondition<T> condition = requiredPropertyValue(propertyResolver, annotation.value(), pattern); | |
| 71 | for (String alternative : annotation.alternatives()) { | |
| 72 | condition = condition.or(Conditions.<T> requiredPropertyValue(propertyResolver, alternative, pattern)); | |
| 73 | } | |
| 74 |
2
1. matchesPattern : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesPattern → NO_COVERAGE 2. matchesPattern : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesPattern → KILLED |
return condition; |
| 75 | } | |
| 76 | ||
| 77 | private FluentCondition<T> matchesExcludes(RequiredProperty annotation, String excludeValue) { | |
| 78 | FluentCondition<T> condition = requiredPropertyValue(propertyResolver, annotation.value(), excludeValue); | |
| 79 | for (String alternative : annotation.alternatives()) { | |
| 80 | condition = condition.or(Conditions.<T> requiredPropertyValue(propertyResolver, alternative, excludeValue)); | |
| 81 | } | |
| 82 |
2
1. matchesExcludes : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesExcludes → NO_COVERAGE 2. matchesExcludes : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesExcludes → KILLED |
return condition; |
| 83 | } | |
| 84 | ||
| 85 | } | |
Mutations | ||
| 35 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 36 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 39 |
1.1 2.2 |
|
| 42 |
1.1 2.2 |
|
| 48 |
1.1 2.2 |
|
| 57 |
1.1 2.2 |
|
| 65 |
1.1 2.2 |
|
| 74 |
1.1 2.2 |
|
| 82 |
1.1 2.2 |