StringResolver.java

1
package pro.verron.officestamper.api;
2
3
import org.docx4j.wml.R;
4
import org.springframework.lang.Nullable;
5
6
import static pro.verron.officestamper.utils.WmlFactory.newRun;
7
8
/**
9
 * This is an abstract class that provides a generic implementation for
10
 * resolving objects to strings. It is used in conjunction with
11
 * {@link ObjectResolver} interface to provide a flexible way to
12
 * resolve different types of objects to strings.
13
 *
14
 * @param <T> the type of the object to resolve
15
 *
16
 * @author Joseph Verron
17
 * @version ${version}
18
 * @since 1.6.7
19
 */
20
public abstract class StringResolver<T>
21
        implements ObjectResolver {
22
23
    private final Class<T> type;
24
25
    /**
26
     * Creates a new StringResolver with the given type.
27
     *
28
     * @param type the type of object to be resolved
29
     */
30
    protected StringResolver(Class<T> type) {
31
        assert type != null;
32
        this.type = type;
33
    }
34
35
    /**
36
     * Resolves an object to a string and creates a new run with the resolved string as content.
37
     *
38
     * @param document   the WordprocessingMLPackage document
39
     * @param expression the expression string
40
     * @param object     the object to be resolved
41
     *
42
     * @return the newly created run with the resolved string as content
43
     */
44
    @Override
45
    public final R resolve(
46
            DocxPart document,
47
            String expression,
48
            Object object
49
    ) {
50 1 1. resolve : replaced return value with null for pro/verron/officestamper/api/StringResolver::resolve → KILLED
        return newRun(resolve(type.cast(object)));
51
    }
52
53
    /**
54
     * Determines if the given object can be resolved by the StringResolver.
55
     *
56
     * @param object the object to be resolved
57
     *
58
     * @return true if the object can be resolved, false otherwise
59
     */
60
    @Override
61
    public final boolean canResolve(@Nullable Object object) {
62 2 1. canResolve : replaced boolean return with true for pro/verron/officestamper/api/StringResolver::canResolve → KILLED
2. canResolve : replaced boolean return with false for pro/verron/officestamper/api/StringResolver::canResolve → KILLED
        return type.isInstance(object);
63
    }
64
65
    /**
66
     * Resolves an object to a string.
67
     *
68
     * @param object the object to be resolved
69
     *
70
     * @return the string representation of the object
71
     */
72
    protected abstract String resolve(T object);
73
}

Mutations

50

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/api/StringResolver::resolve → KILLED

62

1.1
Location : canResolve
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]
replaced boolean return with true for pro/verron/officestamper/api/StringResolver::canResolve → KILLED

2.2
Location : canResolve
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 boolean return with false for pro/verron/officestamper/api/StringResolver::canResolve → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1