OfficeStamperEvaluationContextFactory.java

1
package pro.verron.officestamper.core;
2
3
import org.springframework.expression.EvaluationContext;
4
import pro.verron.officestamper.api.*;
5
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.stream.Stream;
10
11
import static java.util.function.Function.identity;
12
import static pro.verron.officestamper.core.Invokers.streamInvokersFromClass;
13
import static pro.verron.officestamper.core.Invokers.streamInvokersFromCustomFunction;
14
15
/// Factory for creating [EvaluationContext] instances for OfficeStamper.
16
public final class OfficeStamperEvaluationContextFactory {
17
18
    private final List<CustomFunction> customFunctions;
19
    private final Map<Class<?>, CommentProcessorFactory> commentProcessors;
20
    private final Map<Class<?>, Object> interfaceFunctions;
21
    private final EvaluationContextFactory contextFactory;
22
23
    /// Constructs a factory.
24
    ///
25
    /// @param customFunctions custom functions to be registered.
26
    /// @param commentProcessors comment processor factories.
27
    /// @param interfaceFunctions interface functions.
28
    /// @param contextFactory the base evaluation context factory.
29
    OfficeStamperEvaluationContextFactory(
30
            List<CustomFunction> customFunctions,
31
            Map<Class<?>, CommentProcessorFactory> commentProcessors,
32
            Map<Class<?>, Object> interfaceFunctions,
33
            EvaluationContextFactory contextFactory
34
    ) {
35
        this.customFunctions = customFunctions;
36
        this.commentProcessors = commentProcessors;
37
        this.interfaceFunctions = interfaceFunctions;
38
        this.contextFactory = contextFactory;
39
    }
40
41
    /// Creates an evaluation context.
42
    ///
43
    /// @param processorContext the processor context.
44
    /// @param branch           the context branch.
45
    /// @return the evaluation context.
46
    public EvaluationContext create(ProcessorContext processorContext, ContextBranch branch) {
47
        var ec = contextFactory.create(branch);
48
        var processors = instantiate(commentProcessors, processorContext);
49
        var invokerStream = Stream.of(streamInvokersFromClass(processors),
50
                                          streamInvokersFromClass(interfaceFunctions),
51
                                          streamInvokersFromCustomFunction(customFunctions))
52
                                  .flatMap(identity());
53
        var invokers = new Invokers(invokerStream);
54 1 1. create : replaced return value with null for pro/verron/officestamper/core/OfficeStamperEvaluationContextFactory::create → KILLED
        return new UnionEvaluationContext(ec, invokers);
55
    }
56
57
    /// Returns a set view of the mappings contained in this map. Each entry in the set is a mapping between a
58
    /// [Class<?>] key and its associated `CommentProcessor` value.
59
    ///
60
    /// @return a map representing the associations between [Class<?>] keys and their corresponding [CommentProcessor]
61
    ///         values in this map.
62
63
    private static Map<Class<?>, CommentProcessor> instantiate(
64
            Map<Class<?>, CommentProcessorFactory> commentProcessorFactories,
65
            ProcessorContext processorContext
66
    ) {
67
        var map = new HashMap<Class<?>, CommentProcessor>();
68
        for (var entry : commentProcessorFactories.entrySet()) {
69
            var processorClass = entry.getKey();
70
            var processorFactory = entry.getValue();
71
            var processor = processorFactory.create(processorContext);
72
            map.put(processorClass, processor);
73
        }
74 1 1. instantiate : replaced return value with Collections.emptyMap for pro/verron/officestamper/core/OfficeStamperEvaluationContextFactory::instantiate → TIMED_OUT
        return map;
75
    }
76
}

Mutations

54

1.1
Location : create
Killed by : pro.verron.officestamper.test.SpelInjectionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInjectionTest]/[test-template:spelInjectionTest(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/core/OfficeStamperEvaluationContextFactory::create → KILLED

74

1.1
Location : instantiate
Killed by : none
replaced return value with Collections.emptyMap for pro/verron/officestamper/core/OfficeStamperEvaluationContextFactory::instantiate → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT 1.22.0