TriFunctionBuilder.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
import pro.verron.officestamper.utils.function.TriFunction;
7
8
import java.util.List;
9
import java.util.function.Function;
10
11
/// A builder class for defining and registering custom TriFunction implementations. This class is responsible for
12
/// constructing a [TriFunction] implementation with three input types and registering it within a provided
13
/// [DocxStamperConfiguration]. The [TriFunction] allows execution of a specific behavior based on the three input
14
/// arguments and provides a result.
15
///
16
/// @param <T> the type of the first input to the [TriFunction]
17
/// @param <U> the type of the second input to the [TriFunction]
18
/// @param <V> the type of the third input to the [TriFunction]
19
public class TriFunctionBuilder<T, U, V>
20
        implements CustomFunction.NeedsTriFunctionImpl<T, U, V> {
21
    private final DocxStamperConfiguration configuration;
22
    private final String name;
23
    private final Class<T> class0;
24
    private final Class<U> class1;
25
    private final Class<V> class2;
26
27
    /// Constructs a new instance of [TriFunctionBuilder]. This constructor initializes the [TriFunctionBuilder] with
28
    /// the given configuration, name, and input types. It prepares the builder to define and register a custom
29
    /// [TriFunction].
30
    ///
31
    /// @param configuration the [DocxStamperConfiguration] to which the custom [TriFunction] will be
32
    ///         registered
33
    /// @param name the name of the custom [TriFunction] being defined
34
    /// @param class0 the class of the first input type of the [TriFunction]
35
    /// @param class1 the class of the second input type of the [TriFunction]
36
    /// @param class2 the class of the third input type of the [TriFunction]
37
    public TriFunctionBuilder(
38
            DocxStamperConfiguration configuration,
39
            String name,
40
            Class<T> class0,
41
            Class<U> class1,
42
            Class<V> class2
43
    ) {
44
        this.configuration = configuration;
45
        this.name = name;
46
        this.class0 = class0;
47
        this.class1 = class1;
48
        this.class2 = class2;
49
    }
50
51
    /// Registers a custom implementation of a [TriFunction] that operates on three input arguments of types [T], [U],
52
    /// and [V], and produces a result.
53
    ///
54
    /// The provided implementation is encapsulated as a [CustomFunction] and added to the underlying configuration for
55
    /// later use.
56
    ///
57
    /// @param implementation the [TriFunction] implementation to register. This function takes three input
58
    ///         arguments of types [T], [U], and [V] and produces a result.
59
    @Override
60
    public OfficeStamperConfiguration withImplementation(TriFunction<T, U, V, ?> implementation) {
61
        Function<List<Object>, Object> function = args -> {
62
            var arg0 = class0.cast(args.getFirst());
63
            var arg1 = class1.cast(args.get(1));
64
            var arg2 = class2.cast(args.get(2));
65 1 1. lambda$withImplementation$0 : replaced return value with null for pro/verron/officestamper/core/functions/TriFunctionBuilder::lambda$withImplementation$0 → KILLED
            return implementation.apply(arg0, arg1, arg2);
66
        };
67
        var customFunction = new CustomFunction(name, List.of(class0, class1, class2), function);
68 1 1. withImplementation : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → TIMED_OUT
        configuration.addCustomFunction(customFunction);
69 1 1. withImplementation : replaced return value with null for pro/verron/officestamper/core/functions/TriFunctionBuilder::withImplementation → KILLED
        return configuration;
70
    }
71
}

Mutations

65

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

68

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

69

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/TriFunctionBuilder::withImplementation → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0