FunctionBuilder.java

1
package pro.verron.officestamper.core.functions;
2
3
import pro.verron.officestamper.api.CustomFunction;
4
import pro.verron.officestamper.api.OfficeStamperConfiguration;
5
import pro.verron.officestamper.core.DocxStamperConfiguration;
6
7
import java.util.List;
8
import java.util.function.Function;
9
10
/// A builder class for creating and registering custom functions in the context of a [DocxStamperConfiguration].
11
///
12
/// The custom functions are defined by a name, a single input parameter type, and their implementation.
13
///
14
/// @param <T> the type of the input to the function
15
public class FunctionBuilder<T>
16
        implements CustomFunction.NeedsFunctionImpl<T> {
17
    private final DocxStamperConfiguration source;
18
    private final String name;
19
    private final Class<T> class0;
20
21
    /// Constructs a new [FunctionBuilder] to define and register a custom function in the provided
22
    /// [DocxStamperConfiguration].
23
    ///
24
    /// @param source the [DocxStamperConfiguration] instance in which the custom function will be registered.
25
    /// @param name the name of the custom function to be defined
26
    /// @param class0 the [Class] object representing the type of the single input parameter for the custom
27
    ///         function.
28
    public FunctionBuilder(DocxStamperConfiguration source, String name, Class<T> class0) {
29
        this.source = source;
30
        this.name = name;
31
        this.class0 = class0;
32
    }
33
34
    /// Sets the implementation for the custom function being built. The implementation defines the behavior of the
35
    /// function for a specific input type and is wrapped in a `CustomFunction` instance that is added to the
36
    /// configuration.
37
    ///
38
    /// @param implementation a `Function` that takes an input of type `T` and produces a result
39
    @Override
40
    public OfficeStamperConfiguration withImplementation(Function<T, ?> implementation) {
41
        Function<List<Object>, Object> objectFunction = args -> {
42
            var arg0 = class0.cast(args.getFirst());
43 1 1. lambda$withImplementation$0 : replaced return value with null for pro/verron/officestamper/core/functions/FunctionBuilder::lambda$withImplementation$0 → KILLED
            return implementation.apply(arg0);
44
        };
45
        var customFunction = new CustomFunction(name, List.of(class0), objectFunction);
46 1 1. withImplementation : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → TIMED_OUT
        source.addCustomFunction(customFunction);
47 1 1. withImplementation : replaced return value with null for pro/verron/officestamper/core/functions/FunctionBuilder::withImplementation → KILLED
        return source;
48
    }
49
}

Mutations

43

1.1
Location : lambda$withImplementation$0
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:functions(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/core/functions/FunctionBuilder::lambda$withImplementation$0 → KILLED

46

1.1
Location : withImplementation
Killed by : none
removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → TIMED_OUT

47

1.1
Location : withImplementation
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/core/functions/FunctionBuilder::withImplementation → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0