StringResolver.java

1
package pro.verron.officestamper.api;
2
3
import org.jspecify.annotations.Nullable;
4
5
import static pro.verron.officestamper.utils.wml.WmlFactory.newRun;
6
7
/// This is an abstract class that provides a generic implementation for resolving objects to strings. It is used in
8
/// conjunction with [ObjectResolver] interface to provide a flexible way to resolve different types of objects to
9
/// strings.
10
///
11
/// @param <T> the type of the object to resolve
12
/// @author Joseph Verron
13
/// @since 1.6.7
14
public abstract class StringResolver<T>
15
        implements ObjectResolver {
16
17
    private final Class<T> type;
18
19
    /// Creates a new StringResolver with the given type.
20
    ///
21
    /// @param type the type of object to be resolved
22
    protected StringResolver(Class<T> type) {
23
        this.type = type;
24
    }
25
26
    /// Resolves an object to a string and creates a new run with the resolved string as content.
27
    ///
28
    /// @param part the WordprocessingMLPackage document
29
    /// @param expression the expression string
30
    /// @param object the object to be resolved
31
    /// @return the newly created run with the resolved string as content
32
    @Override
33
    public final Insert resolve(DocxPart part, String expression, @Nullable Object object) {
34 1 1. resolve : negated conditional → KILLED
        if (object == null) throw new OfficeStamperException("Cannot resolve null object");
35 1 1. resolve : replaced return value with null for pro/verron/officestamper/api/StringResolver::resolve → KILLED
        return new Insert(newRun(resolve(type.cast(object))));
36
    }
37
38
    /// Determines if the given object can be resolved by the StringResolver.
39
    ///
40
    /// @param object the object to be resolved
41
    /// @return true if the object can be resolved, false otherwise
42
    @Override
43
    public final boolean canResolve(@Nullable Object object) {
44 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);
45
    }
46
47
    /// Resolves an object to a string.
48
    ///
49
    /// @param object the object to be resolved
50
    /// @return the string representation of the object
51
    protected abstract String resolve(T object);
52
}

Mutations

34

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.ResolversIntegrationTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolversIntegrationTests]/[test-template:isoTimeWithFormatter(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

35

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.ResolversIntegrationTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolversIntegrationTests]/[test-template:isoTimeWithFormatter(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/api/StringResolver::resolve → KILLED

44

1.1
Location : canResolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, org.docx4j.openpackaging.packages.WordprocessingMLPackage, java.lang.String)]/[test-template-invocation:#5]
replaced boolean return with true for pro/verron/officestamper/api/StringResolver::canResolve → KILLED

2.2
Location : canResolve
Killed by : pro.verron.officestamper.test.ResolversIntegrationTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolversIntegrationTests]/[test-template:isoDateWithFormatter(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#1]
replaced boolean return with false for pro/verron/officestamper/api/StringResolver::canResolve → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.5 support