ImageResolver.java

1
package pro.verron.officestamper.preset.resolvers.image;
2
3
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
4
import org.docx4j.wml.R;
5
import org.springframework.lang.Nullable;
6
import pro.verron.officestamper.api.DocxPart;
7
import pro.verron.officestamper.api.ObjectResolver;
8
import pro.verron.officestamper.api.OfficeStamperException;
9
import pro.verron.officestamper.preset.Image;
10
11
/**
12
 * This {@link ObjectResolver} allows context objects to return objects of
13
 * type {@link Image}. An expression that resolves to an {@link Image}
14
 * object will be replaced by an actual image in the resulting .docx document.
15
 * The image will be put as an inline into the surrounding paragraph of text.
16
 *
17
 * @author Joseph Verron
18
 * @version ${version}
19
 * @since 1.6.7
20
 */
21
public class ImageResolver
22
        implements ObjectResolver {
23
24
    @Override
25
    public boolean canResolve(@Nullable Object object) {
26 2 1. canResolve : replaced boolean return with true for pro/verron/officestamper/preset/resolvers/image/ImageResolver::canResolve → KILLED
2. canResolve : replaced boolean return with false for pro/verron/officestamper/preset/resolvers/image/ImageResolver::canResolve → KILLED
        return object instanceof Image;
27
    }
28
29
    @Override
30
    public R resolve(
31
            DocxPart document,
32
            String expression,
33
            Object object
34
    ) {
35 1 1. resolve : negated conditional → KILLED
        if (object instanceof Image image)
36 1 1. resolve : replaced return value with null for pro/verron/officestamper/preset/resolvers/image/ImageResolver::resolve → KILLED
            return resolve(document, image);
37
        String message = "Expected %s to be an Image".formatted(object);
38
        throw new OfficeStamperException(message);
39
    }
40
41
    /**
42
     * Resolves an image and adds it to a {@link WordprocessingMLPackage}
43
     * document.
44
     *
45
     * @param image The image to be resolved and added
46
     *
47
     * @return The run containing the added image
48
     *
49
     * @throws OfficeStamperException If an error occurs while adding the image to the document
50
     */
51
    private R resolve(DocxPart document, Image image) {
52
        try {
53 1 1. resolve : replaced return value with null for pro/verron/officestamper/preset/resolvers/image/ImageResolver::resolve → KILLED
            return image.newRun(document, "dummyFileName", "dummyAltText");
54
        } catch (Exception e) {
55
            throw new OfficeStamperException("Error while adding image to document!", e);
56
        }
57
    }
58
59
}

Mutations

26

1.1
Location : canResolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
replaced boolean return with true for pro/verron/officestamper/preset/resolvers/image/ImageResolver::canResolve → KILLED

2.2
Location : canResolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#31]
replaced boolean return with false for pro/verron/officestamper/preset/resolvers/image/ImageResolver::canResolve → KILLED

35

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#31]
negated conditional → KILLED

36

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#31]
replaced return value with null for pro/verron/officestamper/preset/resolvers/image/ImageResolver::resolve → KILLED

53

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#31]
replaced return value with null for pro/verron/officestamper/preset/resolvers/image/ImageResolver::resolve → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1