UpdateCurrentContextMerger.java

1
package fr.sii.ogham.spring.v3.template.thymeleaf;
2
3
import java.util.Map;
4
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7
import org.thymeleaf.context.AbstractContext;
8
import org.thymeleaf.context.IContext;
9
10
import fr.sii.ogham.spring.template.thymeleaf.ContextMerger;
11
12
/**
13
 * Add additional variables to an existing Thymeleaf context. It only works if
14
 * the {@link IContext} instance extends {@link AbstractContext}.
15
 * 
16
 * It updates the original context in place returning the same instance.
17
 * 
18
 * If you need to set variables on an instance that doesn't inherit from
19
 * {@link AbstractContext}, you have to provide another implementation.
20
 * 
21
 * @author Aurélien Baudet
22
 *
23
 */
24
public class UpdateCurrentContextMerger implements ContextMerger {
25
	private static final Logger LOG = LoggerFactory.getLogger(UpdateCurrentContextMerger.class);
26
27
	@Override
28
	public IContext mergeVariables(IContext base, Map<String, Object> additionalVariables) {
29 1 1. mergeVariables : negated conditional → KILLED
		if (base instanceof AbstractContext) {
30 1 1. mergeVariables : removed call to org/thymeleaf/context/AbstractContext::setVariables → KILLED
			((AbstractContext) base).setVariables(additionalVariables);
31
		} else {
32
			LOG.debug("Not an AbstractContext => skip additional variables");
33
		}
34 1 1. mergeVariables : replaced return value with null for fr/sii/ogham/spring/v3/template/thymeleaf/UpdateCurrentContextMerger::mergeVariables → KILLED
		return base;
35
	}
36
37
	@Override
38
	public IContext merge(IContext base, IContext other) {
39
		for (String variableName : other.getVariableNames()) {
40 1 1. merge : negated conditional → KILLED
			if (base instanceof AbstractContext) {
41 1 1. merge : removed call to org/thymeleaf/context/AbstractContext::setVariable → KILLED
				((AbstractContext) base).setVariable(variableName, other.getVariable(variableName));
42
			} else {
43
				LOG.debug("Not an AbstractContext => skip additional variables");
44
			}
45
		}
46 1 1. merge : replaced return value with null for fr/sii/ogham/spring/v3/template/thymeleaf/UpdateCurrentContextMerger::merge → KILLED
		return base;
47
	}
48
}

Mutations

29

1.1
Location : mergeVariables
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
negated conditional → KILLED

30

1.1
Location : mergeVariables
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
removed call to org/thymeleaf/context/AbstractContext::setVariables → KILLED

34

1.1
Location : mergeVariables
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
replaced return value with null for fr/sii/ogham/spring/v3/template/thymeleaf/UpdateCurrentContextMerger::mergeVariables → KILLED

40

1.1
Location : merge
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
negated conditional → KILLED

41

1.1
Location : merge
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
removed call to org/thymeleaf/context/AbstractContext::setVariable → KILLED

46

1.1
Location : merge
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
replaced return value with null for fr/sii/ogham/spring/v3/template/thymeleaf/UpdateCurrentContextMerger::merge → KILLED

Active mutators

Tests examined


Report generated by PIT 1.13.1