FirstSupportingResolverAdapter.java

1
package fr.sii.ogham.template.thymeleaf.common.adapter;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
7
import org.thymeleaf.templateresolver.ITemplateResolver;
8
9
import fr.sii.ogham.core.resource.resolver.ResourceResolver;
10
import fr.sii.ogham.template.exception.NoResolverAdapterException;
11
import fr.sii.ogham.template.thymeleaf.common.TemplateResolverOptions;
12
13
/**
14
 * Decorator that will ask each resolver adapter if it is able to handle the
15
 * template resolver. If the resolver adapter supports it, then this
16
 * implementation asks the resolver adapter to provide the Thymeleaf template
17
 * resolver.
18
 * 
19
 * Only the first resolver adapter that can handle the template resolver is
20
 * used.
21
 * 
22
 * @author Aurélien Baudet
23
 */
24
public class FirstSupportingResolverAdapter implements TemplateResolverAdapter {
25
26
	/**
27
	 * The list of adapters used to convert the general resolvers into Thymeleaf
28
	 * specific resolvers
29
	 */
30
	private List<TemplateResolverAdapter> adapters;
31
32
	/**
33
	 * Initialize the decorator with none, one or several resolver adapter
34
	 * implementations. The registration order may be important.
35
	 * 
36
	 * @param adapters
37
	 *            the adapters to register
38
	 */
39
	public FirstSupportingResolverAdapter(TemplateResolverAdapter... adapters) {
40
		this(new ArrayList<>(Arrays.asList(adapters)));
41
	}
42
43
	/**
44
	 * Initialize the decorator with the provided resolver adapter
45
	 * implementations. The registration order may be important.
46
	 * 
47
	 * @param adapters
48
	 *            the adapters to register
49
	 */
50
	public FirstSupportingResolverAdapter(List<TemplateResolverAdapter> adapters) {
51
		super();
52
		this.adapters = adapters;
53
	}
54
55
	public FirstSupportingResolverAdapter() {
56
		this(new ArrayList<>());
57
	}
58
59
	@Override
60
	public boolean supports(ResourceResolver resolver) {
61
		for (TemplateResolverAdapter adapter : adapters) {
62 2 1. supports : negated conditional → NO_COVERAGE
2. supports : negated conditional → KILLED
			if (adapter.supports(resolver)) {
63 2 1. supports : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → NO_COVERAGE
2. supports : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → KILLED
				return true;
64
			}
65
		}
66 2 1. supports : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → NO_COVERAGE
2. supports : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → KILLED
		return false;
67
	}
68
69
	@Override
70
	public ITemplateResolver adapt(ResourceResolver resolver) throws NoResolverAdapterException {
71
		for (TemplateResolverAdapter adapter : adapters) {
72 5 1. adapt : negated conditional → TIMED_OUT
2. adapt : negated conditional → KILLED
3. adapt : negated conditional → KILLED
4. adapt : negated conditional → KILLED
5. adapt : negated conditional → KILLED
			if (adapter.supports(resolver)) {
73 5 1. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → TIMED_OUT
2. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED
3. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED
4. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED
5. adapt : replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED
				return adapter.adapt(resolver);
74
			}
75
		}
76
		throw new NoResolverAdapterException("No resolver adapter found for the provided resolver: " + resolver.getClass().getSimpleName(), resolver);
77
	}
78
79
	/**
80
	 * Register a new adapter. The adapter is added at the end.
81
	 * 
82
	 * @param adapter
83
	 *            the adapter to register
84
	 */
85
	public void addAdapter(TemplateResolverAdapter adapter) {
86
		adapters.add(adapter);
87
	}
88
89
	public List<TemplateResolverAdapter> getAdapters() {
90 1 1. getAdapters : replaced return value with Collections.emptyList for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::getAdapters → NO_COVERAGE
		return adapters;
91
	}
92
93
	@Override
94
	public void setOptions(TemplateResolverOptions options) {
95
		for (TemplateResolverAdapter adapter : adapters) {
96 6 1. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → NO_COVERAGE
2. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → TIMED_OUT
3. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED
4. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED
5. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED
6. setOptions : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED
			adapter.setOptions(options);
97
		}
98
	}
99
}

Mutations

62

1.1
Location : supports
Killed by : oghamthymeleaf.ut.FirstSupportingResolverAdapterTest.supportsIfAtLeastOneSupports()
negated conditional → KILLED

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

63

1.1
Location : supports
Killed by : oghamthymeleaf.ut.FirstSupportingResolverAdapterTest.supportsIfAtLeastOneSupports()
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → KILLED

2.2
Location : supports
Killed by : none
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → NO_COVERAGE

66

1.1
Location : supports
Killed by : oghamthymeleaf.ut.FirstSupportingResolverAdapterTest.supportsIfAtLeastOneSupports()
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → KILLED

2.2
Location : supports
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::supports → NO_COVERAGE

72

1.1
Location : adapt
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
negated conditional → KILLED

2.2
Location : adapt
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

3.3
Location : adapt
Killed by : oghamthymeleaf.ut.FirstSupportingResolverAdapterTest.noSupportingAdapterShouldFail()
negated conditional → KILLED

4.4
Location : adapt
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

5.5
Location : adapt
Killed by : none
negated conditional → TIMED_OUT

73

1.1
Location : adapt
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED

2.2
Location : adapt
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED

3.3
Location : adapt
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED

4.4
Location : adapt
Killed by : none
replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → TIMED_OUT

5.5
Location : adapt
Killed by : oghamthymeleaf.ut.FirstSupportingResolverAdapterTest.adaptUsingFirstSupporting()
replaced return value with null for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::adapt → KILLED

90

1.1
Location : getAdapters
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::getAdapters → NO_COVERAGE

96

1.1
Location : setOptions
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → NO_COVERAGE

2.2
Location : setOptions
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED

3.3
Location : setOptions
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → TIMED_OUT

4.4
Location : setOptions
Killed by : oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest.missingBeanErrorUsingThymeleaf(oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED

5.5
Location : setOptions
Killed by : oghamthymeleafv3.it.ThymeleafParserTest.html(oghamthymeleafv3.it.ThymeleafParserTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED

6.6
Location : setOptions
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/TemplateResolverAdapter::setOptions → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM