ReplaceWithProcessor.java

1
package pro.verron.officestamper.preset.processors.replacewith;
2
3
import org.docx4j.wml.R;
4
import org.springframework.lang.Nullable;
5
import pro.verron.officestamper.api.AbstractCommentProcessor;
6
import pro.verron.officestamper.api.CommentProcessor;
7
import pro.verron.officestamper.api.DocxPart;
8
import pro.verron.officestamper.api.ParagraphPlaceholderReplacer;
9
import pro.verron.officestamper.preset.CommentProcessorFactory;
10
import pro.verron.officestamper.utils.WmlFactory;
11
12
import java.util.List;
13
import java.util.function.Function;
14
15
import static pro.verron.officestamper.utils.WmlFactory.newText;
16
17
/// Processor that replaces the current run with the provided expression.
18
/// This is useful for replacing an expression in a comment with the result of the expression.
19
///
20
/// @author Joseph Verron
21
/// @author Tom Hombergs
22
/// @version ${version}
23
/// @since 1.0.7
24
public class ReplaceWithProcessor
25
        extends AbstractCommentProcessor
26
        implements CommentProcessorFactory.IReplaceWithProcessor {
27
28
    private final Function<R, List<Object>> nullSupplier;
29
30
    private ReplaceWithProcessor(
31
            ParagraphPlaceholderReplacer placeholderReplacer, Function<R, List<Object>> nullSupplier
32
    ) {
33
        super(placeholderReplacer);
34
        this.nullSupplier = nullSupplier;
35
    }
36
37
    /// Creates a new processor that replaces the current run with the result of the expression.
38
    ///
39
    /// @param pr the placeholder replacer to use
40
    ///
41
    /// @return the processor
42
    public static CommentProcessor newInstance(ParagraphPlaceholderReplacer pr) {
43 1 1. newInstance : replaced return value with null for pro/verron/officestamper/preset/processors/replacewith/ReplaceWithProcessor::newInstance → KILLED
        return new ReplaceWithProcessor(pr, R::getContent);
44
    }
45
46
    /// {@inheritDoc}
47
    @Override public void commitChanges(DocxPart document) {
48
        // nothing to commit
49
    }
50
51
    /// {@inheritDoc}
52
    @Override public void reset() {
53
        // nothing to reset
54
    }
55
56
    /// {@inheritDoc}
57
    @Override public void replaceWordWith(@Nullable String expression) {
58 1 1. replaceWordWith : removed call to pro/verron/officestamper/preset/processors/replacewith/ReplaceWithProcessor::replaceWith → KILLED
        replaceWith(expression);
59
    }
60
61
    @Override
62
    public void replaceWith(@Nullable String expression) {
63
        R run = this.getCurrentRun();
64 1 1. replaceWith : negated conditional → KILLED
        if (run != null) { //TODO Remove the run-based secundary case that becomes redundant
65 1 1. replaceWith : negated conditional → KILLED
            var target = expression != null ? List.of(newText(expression)) : nullSupplier.apply(run);
66
            var runContent = run.getContent();
67 1 1. replaceWith : removed call to java/util/List::clear → SURVIVED
            runContent.clear();
68
            runContent.addAll(target);
69
        }
70
        else {
71
            var comment = this.getCurrentCommentWrapper();
72
            var from = comment.getCommentRangeStart();
73
            var to = comment.getCommentRangeEnd();
74 1 1. replaceWith : removed call to pro/verron/officestamper/api/Paragraph::replace → KILLED
            getParagraph().replace(from, to, WmlFactory.newRun(expression));
75
        }
76
    }
77
}

Mutations

43

1.1
Location : newInstance
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testStaticResolution(java.lang.String, boolean, boolean, boolean, java.lang.String, java.lang.String)]/[test-template-invocation:#6]
replaced return value with null for pro/verron/officestamper/preset/processors/replacewith/ReplaceWithProcessor::newInstance → KILLED

58

1.1
Location : replaceWordWith
Killed by : pro.verron.officestamper.test.ProcessorReplaceWithTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorReplaceWithTest]/[method:notWorking1()]
removed call to pro/verron/officestamper/preset/processors/replacewith/ReplaceWithProcessor::replaceWith → KILLED

64

1.1
Location : replaceWith
Killed by : pro.verron.officestamper.test.ProcessorReplaceWithTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorReplaceWithTest]/[method:notWorking1()]
negated conditional → KILLED

65

1.1
Location : replaceWith
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:#2]
negated conditional → KILLED

67

1.1
Location : replaceWith
Killed by : none
removed call to java/util/List::clear → SURVIVED
Covering tests

74

1.1
Location : replaceWith
Killed by : pro.verron.officestamper.test.ProcessorReplaceWithTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorReplaceWithTest]/[method:notWorking1()]
removed call to pro/verron/officestamper/api/Paragraph::replace → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0