FirstExistingResourceVariantResolver.java

1
package fr.sii.ogham.template.common.adapter;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
7
import fr.sii.ogham.core.message.capability.HasVariant;
8
import fr.sii.ogham.core.message.content.TemplateContent;
9
import fr.sii.ogham.core.resource.path.ResourcePath;
10
import fr.sii.ogham.template.exception.VariantResolutionException;
11
12
/**
13
 * Try every possible path for the variant until one path points to an existing
14
 * resource.
15
 * 
16
 * @author Aurélien Baudet
17
 *
18
 */
19
public class FirstExistingResourceVariantResolver implements VariantResolver {
20
	private List<VariantResolver> delegates;
21
	private VariantResolver defaultResolver;
22
23
	public FirstExistingResourceVariantResolver(VariantResolver defaultResolver, VariantResolver... delegates) {
24
		this(defaultResolver, new ArrayList<>(Arrays.asList(delegates)));
25
	}
26
27
	public FirstExistingResourceVariantResolver(VariantResolver defaultResolver, List<VariantResolver> delegates) {
28
		super();
29
		this.defaultResolver = defaultResolver;
30
		this.delegates = delegates;
31
	}
32
33
	@Override
34
	public ResourcePath getRealPath(TemplateContent template) throws VariantResolutionException {
35 4 1. getRealPath : negated conditional → SURVIVED
2. getRealPath : negated conditional → NO_COVERAGE
3. getRealPath : negated conditional → TIMED_OUT
4. getRealPath : negated conditional → KILLED
		if (!(template instanceof HasVariant)) {
36 3 1. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → NO_COVERAGE
2. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → TIMED_OUT
3. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → KILLED
			return template.getPath();
37
		}
38
		for (VariantResolver delegate : delegates) {
39 2 1. getRealPath : negated conditional → NO_COVERAGE
2. getRealPath : negated conditional → KILLED
			if(delegate.variantExists(template)) {
40 2 1. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → NO_COVERAGE
2. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → KILLED
				return delegate.getRealPath(template);
41
			}
42
		}
43 2 1. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → NO_COVERAGE
2. getRealPath : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → SURVIVED
		return defaultResolver.getRealPath(template);
44
	}
45
46
	@Override
47
	public boolean variantExists(TemplateContent template) {
48 1 1. variantExists : negated conditional → NO_COVERAGE
		if (!(template instanceof HasVariant)) {
49 1 1. variantExists : replaced boolean return with true for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE
			return false;
50
		}
51
		for (VariantResolver delegate : delegates) {
52 1 1. variantExists : negated conditional → NO_COVERAGE
			if(delegate.variantExists(template)) {
53 1 1. variantExists : replaced boolean return with false for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE
				return true;
54
			}
55
		}
56 2 1. variantExists : replaced boolean return with false for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE
2. variantExists : replaced boolean return with true for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE
		return defaultResolver.variantExists(template);
57
	}
58
59
	public FirstExistingResourceVariantResolver addVariantResolver(VariantResolver variantResolver) {
60
		delegates.add(variantResolver);
61 3 1. addVariantResolver : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::addVariantResolver → SURVIVED
2. addVariantResolver : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::addVariantResolver → NO_COVERAGE
3. addVariantResolver : replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::addVariantResolver → TIMED_OUT
		return this;
62
	}
63
}

Mutations

35

1.1
Location : getRealPath
Killed by : none
negated conditional → SURVIVED

2.2
Location : getRealPath
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndTemplateParsersOnlyRegisteredCantHandleTemplateContentDueToResourceResolutionNotConfigured(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

3.3
Location : getRealPath
Killed by : none
negated conditional → TIMED_OUT

4.4
Location : getRealPath
Killed by : none
negated conditional → NO_COVERAGE

36

1.1
Location : getRealPath
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → NO_COVERAGE

2.2
Location : getRealPath
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → TIMED_OUT

3.3
Location : getRealPath
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndFreemarkerOnlyRegisteredButResourceResolutionNotConfiguredCantHandleTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → KILLED

39

1.1
Location : getRealPath
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndTemplateParsersOnlyRegisteredCantHandleTemplateContentDueToResourceResolutionNotConfigured(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

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

40

1.1
Location : getRealPath
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithParsingError(oghamall.it.email.EmailMultiTemplateTest)
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → KILLED

2.2
Location : getRealPath
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → NO_COVERAGE

43

1.1
Location : getRealPath
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → NO_COVERAGE

2.2
Location : getRealPath
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::getRealPath → SURVIVED

48

1.1
Location : variantExists
Killed by : none
negated conditional → NO_COVERAGE

49

1.1
Location : variantExists
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE

52

1.1
Location : variantExists
Killed by : none
negated conditional → NO_COVERAGE

53

1.1
Location : variantExists
Killed by : none
replaced boolean return with false for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE

56

1.1
Location : variantExists
Killed by : none
replaced boolean return with false for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::variantExists → NO_COVERAGE

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

61

1.1
Location : addVariantResolver
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::addVariantResolver → SURVIVED

2.2
Location : addVariantResolver
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::addVariantResolver → NO_COVERAGE

3.3
Location : addVariantResolver
Killed by : none
replaced return value with null for fr/sii/ogham/template/common/adapter/FirstExistingResourceVariantResolver::addVariantResolver → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT OGHAM