UpdateCurrentContextMerger.java

1
package fr.sii.ogham.spring.v2.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 → TIMED_OUT
		if (base instanceof AbstractContext) {
30 1 1. mergeVariables : removed call to org/thymeleaf/context/AbstractContext::setVariables → TIMED_OUT
			((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/v2/template/thymeleaf/UpdateCurrentContextMerger::mergeVariables → TIMED_OUT
		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 → TIMED_OUT
			if (base instanceof AbstractContext) {
41 1 1. merge : removed call to org/thymeleaf/context/AbstractContext::setVariable → TIMED_OUT
				((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/v2/template/thymeleaf/UpdateCurrentContextMerger::merge → TIMED_OUT
		return base;
47
	}
48
}

Mutations

29

1.1
Location : mergeVariables
Killed by : none
negated conditional → TIMED_OUT

30

1.1
Location : mergeVariables
Killed by : none
removed call to org/thymeleaf/context/AbstractContext::setVariables → TIMED_OUT

34

1.1
Location : mergeVariables
Killed by : none
replaced return value with null for fr/sii/ogham/spring/v2/template/thymeleaf/UpdateCurrentContextMerger::mergeVariables → TIMED_OUT

40

1.1
Location : merge
Killed by : none
negated conditional → TIMED_OUT

41

1.1
Location : merge
Killed by : none
removed call to org/thymeleaf/context/AbstractContext::setVariable → TIMED_OUT

46

1.1
Location : merge
Killed by : none
replaced return value with null for fr/sii/ogham/spring/v2/template/thymeleaf/UpdateCurrentContextMerger::merge → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT OGHAM