RequiredPropertyAnnotationProvider.java

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
Location : provide
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
negated conditional → KILLED

2.2
Location : provide
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
negated conditional → KILLED

3.3
Location : provide
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

4.4
Location : provide
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
negated conditional → KILLED

5.5
Location : provide
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests)
negated conditional → KILLED

6.6
Location : provide
Killed by : none
negated conditional → NO_COVERAGE

7.7
Location : provide
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
negated conditional → KILLED

8.8
Location : provide
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests)
negated conditional → KILLED

36

1.1
Location : provide
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

2.2
Location : provide
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

3.3
Location : provide
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

4.4
Location : provide
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → NO_COVERAGE

5.5
Location : provide
Killed by : oghamspringbootv2autoconfigure.it.StaticMethodAccessTest.emailUsingFreemarkerTemplateAndStaticMethodAccessDisabledShouldFail(oghamspringbootv2autoconfigure.it.StaticMethodAccessTest)
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

6.6
Location : provide
Killed by : oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest.missingBeanErrorUsingThymeleaf(oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest)
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

7.7
Location : provide
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → SURVIVED

8.8
Location : provide
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

39

1.1
Location : provide
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
negated conditional → KILLED

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

42

1.1
Location : provide
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
negated conditional → KILLED

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

48

1.1
Location : provide
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → KILLED

2.2
Location : provide
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::provide → NO_COVERAGE

57

1.1
Location : exists
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::exists → NO_COVERAGE

2.2
Location : exists
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::exists → KILLED

65

1.1
Location : matchesValue
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesValue → KILLED

2.2
Location : matchesValue
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesValue → NO_COVERAGE

74

1.1
Location : matchesPattern
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesPattern → KILLED

2.2
Location : matchesPattern
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesPattern → NO_COVERAGE

82

1.1
Location : matchesExcludes
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesExcludes → NO_COVERAGE

2.2
Location : matchesExcludes
Killed by : oghamcore.it.core.condition.provider.RequiredPropertiesAnnotationProviderSpec
replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredPropertyAnnotationProvider::matchesExcludes → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM