ObjectResolverRegistry.java

1
package pro.verron.officestamper.core;
2
3
import org.docx4j.wml.R;
4
import org.springframework.lang.Nullable;
5
import pro.verron.officestamper.api.DocxPart;
6
import pro.verron.officestamper.api.ObjectResolver;
7
import pro.verron.officestamper.api.OfficeStamperException;
8
import pro.verron.officestamper.api.Placeholder;
9
10
import java.util.ArrayList;
11
import java.util.List;
12
13
/**
14
 * A registry for object resolvers. It allows registering and resolving object resolvers based on certain criteria.
15
 *
16
 * @author Joseph Verron
17
 * @version ${version}
18
 * @since 1.6.7
19
 */
20
public final class ObjectResolverRegistry {
21
    private final List<ObjectResolver> resolvers = new ArrayList<>();
22
23
    /**
24
     * A registry for object resolvers. It allows registering and resolving object resolvers based on certain criteria.
25
     *
26
     * @param resolvers the ordered list of object resolvers to be registered in
27
     *                  the registry
28
     */
29
    public ObjectResolverRegistry(List<ObjectResolver> resolvers) {
30
        this.resolvers.addAll(resolvers);
31
    }
32
33
    /**
34
     * Resolves the expression in the given document with the provided object.
35
     *
36
     * @param document   the WordprocessingMLPackage document in which to resolve the placeholder
37
     * @param placeholder the expression value to be replaced
38
     * @param object     the object to be used for resolving the expression
39
     * @return the resolved value for the expression
40
     * @throws OfficeStamperException if no resolver is found for the object
41
     */
42
    public R resolve(
43
            DocxPart document,
44
            Placeholder placeholder,
45
            @Nullable Object object
46
    ) {
47
        for (ObjectResolver resolver : resolvers)
48 1 1. resolve : negated conditional → KILLED
            if (resolver.canResolve(object))
49 1 1. resolve : replaced return value with null for pro/verron/officestamper/core/ObjectResolverRegistry::resolve → KILLED
                return resolver.resolve(document, placeholder, object);
50
        throw new OfficeStamperException("No resolver for %s".formatted(object));
51
    }
52
}

Mutations

48

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:#31]
negated conditional → KILLED

49

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:#28]
replaced return value with null for pro/verron/officestamper/core/ObjectResolverRegistry::resolve → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1