AnnotationConditionProvider.java

1
package fr.sii.ogham.core.condition.provider;
2
3
import fr.sii.ogham.core.builder.condition.RequiredClass;
4
import fr.sii.ogham.core.builder.condition.RequiredClasses;
5
import fr.sii.ogham.core.builder.condition.RequiredProperties;
6
import fr.sii.ogham.core.builder.condition.RequiredProperty;
7
import fr.sii.ogham.core.condition.AndCondition;
8
import fr.sii.ogham.core.condition.Condition;
9
import fr.sii.ogham.core.env.PropertyResolver;
10
11
/**
12
 * Implementation that handle conditions defined through annotations.
13
 * 
14
 * See {@link RequiredProperties}, {@link RequiredProperty},
15
 * {@link RequiredClasses} and {@link RequiredClass} for more information about
16
 * the annotations.
17
 * 
18
 * <p>
19
 * If no condition annotation is present on the source object, then a condition
20
 * that always evaluates to true is returned.
21
 * </p>
22
 * 
23
 * @author Aurélien Baudet
24
 *
25
 * @param <T>
26
 *            the object to analyze that may be annotated
27
 */
28
public class AnnotationConditionProvider<T> implements ConditionProvider<Class<?>, T> {
29
	private final RequiredPropertyAnnotationProvider<T> propertyConditionProvider;
30
	private final RequiredPropertiesAnnotationProvider<T> propertiesConditionProvider;
31
	private final RequiredClassAnnotationProvider<T> classConditionProvider;
32
	private final RequiredClassesAnnotationProvider<T> classesConditionProvider;
33
34
	/**
35
	 * Initializes with a {@link PropertyResolver} instance. The property
36
	 * resolver is used by {@link RequiredPropertiesAnnotationProvider} and
37
	 * {@link RequiredPropertyAnnotationProvider} in order to check if property
38
	 * exists in the provided property resolver.
39
	 * 
40
	 * @param propertyResolver
41
	 *            the property resolver
42
	 */
43
	public AnnotationConditionProvider(PropertyResolver propertyResolver) {
44
		super();
45
		propertyConditionProvider = new RequiredPropertyAnnotationProvider<>(propertyResolver);
46
		propertiesConditionProvider = new RequiredPropertiesAnnotationProvider<>(propertyResolver);
47
		classConditionProvider = new RequiredClassAnnotationProvider<>();
48
		classesConditionProvider = new RequiredClassesAnnotationProvider<>();
49
	}
50
51
	@Override
52
	public Condition<T> provide(Class<?> source) {
53
		AndCondition<T> mainCondition = new AndCondition<>();
54
		mainCondition.and(propertyConditionProvider.provide(source.getAnnotation(RequiredProperty.class)));
55
		mainCondition.and(propertiesConditionProvider.provide(source.getAnnotation(RequiredProperties.class)));
56
		mainCondition.and(classConditionProvider.provide(source.getAnnotation(RequiredClass.class)));
57
		mainCondition.and(classesConditionProvider.provide(source.getAnnotation(RequiredClasses.class)));
58 8 1. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → NO_COVERAGE
2. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → SURVIVED
3. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED
4. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED
5. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED
6. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED
7. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED
8. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED
		return mainCondition;
59
	}
60
61
}

Mutations

58

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

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

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

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

5.5
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/AnnotationConditionProvider::provide → KILLED

6.6
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/AnnotationConditionProvider::provide → KILLED

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

8.8
Location : provide
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
replaced return value with null for fr/sii/ogham/core/condition/provider/AnnotationConditionProvider::provide → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM