|
1
|
|
package fr.sii.ogham.core.convert; |
|
2
|
|
|
|
3
|
|
import java.util.ArrayList; |
|
4
|
|
import java.util.Arrays; |
|
5
|
|
import java.util.List; |
|
6
|
|
|
|
7
|
|
import fr.sii.ogham.core.exception.convert.ConversionException; |
|
8
|
|
|
|
9
|
|
/** |
|
10
|
|
* Calls registered {@link SupportingConverter}s to make the real conversion. It |
|
11
|
|
* asks each {@link SupportingConverter} if it can make the conversion. If the |
|
12
|
|
* {@link SupportingConverter} can do the conversion, the conversion is applied |
|
13
|
|
* using that {@link SupportingConverter} and the result is immediately |
|
14
|
|
* returned. |
|
15
|
|
* |
|
16
|
|
* If none of the registered {@link SupportingConverter}s can make the |
|
17
|
|
* conversion, then a {@link ConversionException} is thrown. |
|
18
|
|
* |
|
19
|
|
* If the source is null, then the result is null too. |
|
20
|
|
* |
|
21
|
|
* <strong>Registration order is important.</strong> |
|
22
|
|
* |
|
23
|
|
* @author Aurélien Baudet |
|
24
|
|
* |
|
25
|
|
*/ |
|
26
|
|
public class DelegateConverter implements Converter, ConverterRegistry { |
|
27
|
|
private final List<SupportingConverter> delegates; |
|
28
|
|
|
|
29
|
|
/** |
|
30
|
|
* Registers none, one or several converters |
|
31
|
|
* |
|
32
|
|
* @param delegates |
|
33
|
|
* the converters to register |
|
34
|
|
*/ |
|
35
|
|
public DelegateConverter(SupportingConverter... delegates) { |
|
36
|
|
this(new ArrayList<>(Arrays.asList(delegates))); |
|
37
|
|
} |
|
38
|
|
|
|
39
|
|
/** |
|
40
|
|
* Registers a list of converters. The list must not be null |
|
41
|
|
* |
|
42
|
|
* @param delegates |
|
43
|
|
* the converters to register |
|
44
|
|
*/ |
|
45
|
|
public DelegateConverter(List<SupportingConverter> delegates) { |
|
46
|
|
super(); |
|
47
|
|
this.delegates = delegates; |
|
48
|
|
} |
|
49
|
|
|
|
50
|
|
@Override |
|
51
|
|
public ConverterRegistry register(SupportingConverter converter) { |
|
52
|
8
1. register : negated conditional → SURVIVED
2. register : negated conditional → TIMED_OUT
3. register : negated conditional → KILLED
4. register : negated conditional → KILLED
5. register : negated conditional → KILLED
6. register : negated conditional → KILLED
7. register : negated conditional → KILLED
8. register : negated conditional → KILLED
|
if (!delegates.contains(converter)) { |
|
53
|
|
delegates.add(converter); |
|
54
|
|
} |
|
55
|
2
1. register : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::register → SURVIVED
2. register : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::register → TIMED_OUT
|
return this; |
|
56
|
|
} |
|
57
|
|
|
|
58
|
|
@Override |
|
59
|
|
public <T> T convert(Object source, Class<T> targetType) { |
|
60
|
7
1. convert : negated conditional → NO_COVERAGE
2. convert : negated conditional → SURVIVED
3. convert : negated conditional → KILLED
4. convert : negated conditional → KILLED
5. convert : negated conditional → KILLED
6. convert : negated conditional → KILLED
7. convert : negated conditional → KILLED
|
if (source == null) { |
|
61
|
|
return null; |
|
62
|
|
} |
|
63
|
|
for (SupportingConverter converter : delegates) { |
|
64
|
7
1. convert : negated conditional → NO_COVERAGE
2. convert : negated conditional → TIMED_OUT
3. convert : negated conditional → KILLED
4. convert : negated conditional → KILLED
5. convert : negated conditional → KILLED
6. convert : negated conditional → KILLED
7. convert : negated conditional → KILLED
|
if (converter.supports(source.getClass(), targetType)) { |
|
65
|
7
1. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → NO_COVERAGE
2. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → TIMED_OUT
3. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED
4. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED
5. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED
6. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED
7. convert : replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED
|
return converter.convert(source, targetType); |
|
66
|
|
} |
|
67
|
|
} |
|
68
|
|
throw new ConversionException("No converter available to convert " + source + " into " + targetType.getSimpleName()); |
|
69
|
|
} |
|
70
|
|
|
|
71
|
|
@Override |
|
72
|
|
public List<SupportingConverter> getRegisteredConverters() { |
|
73
|
1
1. getRegisteredConverters : replaced return value with Collections.emptyList for fr/sii/ogham/core/convert/DelegateConverter::getRegisteredConverters → NO_COVERAGE
|
return delegates; |
|
74
|
|
} |
|
75
|
|
|
|
76
|
|
} |
| | Mutations |
| 52 |
|
1.1 Location : register Killed by : oghamspringbootv1autoconfigure.it.StaticMethodsAccessTest.emailUsingFreemarkerTemplateShouldBeAbleToCallStaticMethods(oghamspringbootv1autoconfigure.it.StaticMethodsAccessTest) negated conditional → KILLED 2.2 Location : register Killed by : none negated conditional → SURVIVED 3.3 Location : register Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest) negated conditional → KILLED 4.4 Location : register Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest) negated conditional → KILLED 5.5 Location : register Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec negated conditional → KILLED 6.6 Location : register Killed by : oghamcore.it.core.configuration.ConfigurationLifecycleSpec negated conditional → KILLED 7.7 Location : register Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) negated conditional → KILLED 8.8 Location : register Killed by : none negated conditional → TIMED_OUT
|
| 55 |
|
1.1 Location : register Killed by : none replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::register → SURVIVED 2.2 Location : register Killed by : none replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::register → TIMED_OUT
|
| 60 |
|
1.1 Location : convert Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest) negated conditional → KILLED 2.2 Location : convert Killed by : none negated conditional → NO_COVERAGE 3.3 Location : convert Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) negated conditional → KILLED 4.4 Location : convert Killed by : none negated conditional → SURVIVED 5.5 Location : convert Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec negated conditional → KILLED 6.6 Location : convert Killed by : oghamcore.ut.core.convert.DelegateConverterSpec negated conditional → KILLED 7.7 Location : convert Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest) negated conditional → KILLED
|
| 64 |
|
1.1 Location : convert Killed by : none negated conditional → NO_COVERAGE 2.2 Location : convert Killed by : oghamcore.ut.core.convert.DelegateConverterSpec negated conditional → KILLED 3.3 Location : convert Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec negated conditional → KILLED 4.4 Location : convert Killed by : none negated conditional → TIMED_OUT 5.5 Location : convert Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) negated conditional → KILLED 6.6 Location : convert Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest) negated conditional → KILLED 7.7 Location : convert Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest) negated conditional → KILLED
|
| 65 |
|
1.1 Location : convert Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest) replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED 2.2 Location : convert Killed by : oghamcore.ut.core.convert.DelegateConverterSpec replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED 3.3 Location : convert Killed by : none replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → TIMED_OUT 4.4 Location : convert Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest) replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED 5.5 Location : convert Killed by : none replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → NO_COVERAGE 6.6 Location : convert Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest) replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED 7.7 Location : convert Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec replaced return value with null for fr/sii/ogham/core/convert/DelegateConverter::convert → KILLED
|
| 73 |
|
1.1 Location : getRegisteredConverters Killed by : none replaced return value with Collections.emptyList for fr/sii/ogham/core/convert/DelegateConverter::getRegisteredConverters → NO_COVERAGE
|