ExpressionResolver.java

1
package pro.verron.officestamper.core;
2
3
import org.springframework.expression.ExpressionParser;
4
import org.springframework.expression.spel.support.StandardEvaluationContext;
5
import org.springframework.lang.Nullable;
6
import pro.verron.officestamper.api.Placeholder;
7
8
/// Resolves expressions against a given context object. Expressions can be either SpEL expressions or simple property
9
/// expressions.
10
///
11
/// @author Joseph Verron
12
/// @author Tom Hombergs
13
/// @version ${version}
14
/// @since 1.0.0
15
public class ExpressionResolver {
16
17
    private final ExpressionParser parser;
18
    private final StandardEvaluationContext evaluationContext;
19
20
    /// Creates a new ExpressionResolver with the given SpEL parser configuration.
21
    ///
22
    /// @param standardEvaluationContext a [StandardEvaluationContext] object
23
    public ExpressionResolver(
24
            StandardEvaluationContext standardEvaluationContext,
25
            ExpressionParser expressionParser
26
    ) {
27
        this.parser = expressionParser;
28
        this.evaluationContext = standardEvaluationContext;
29
    }
30
31
    /// Resolves the content of a placeholder by evaluating the expression against the evaluation context.
32
    ///
33
    /// @param placeholder the placeholder to resolve
34
    ///
35
    /// @return the resolved value of the placeholder
36
    @Nullable public Object resolve(Placeholder placeholder) {
37
        var expressionString = placeholder.content();
38
        var expression = parser.parseExpression(expressionString);
39 1 1. resolve : replaced return value with null for pro/verron/officestamper/core/ExpressionResolver::resolve → KILLED
        return expression.getValue(evaluationContext);
40
    }
41
42
    /// Sets the context object against which expressions will be resolved.
43
    ///
44
    /// @param contextRoot the context object to set as the root.
45
    public void setContext(Object contextRoot) {
46 1 1. setContext : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setRootObject → KILLED
        evaluationContext.setRootObject(contextRoot);
47
    }
48
}

Mutations

39

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#12]
replaced return value with null for pro/verron/officestamper/core/ExpressionResolver::resolve → KILLED

46

1.1
Location : setContext
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#12]
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setRootObject → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0