StandardComment.java

1
package pro.verron.officestamper.core;
2
3
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
4
import org.docx4j.wml.CommentRangeEnd;
5
import org.docx4j.wml.CommentRangeStart;
6
import org.docx4j.wml.Comments;
7
import org.docx4j.wml.ContentAccessor;
8
import org.docx4j.wml.R.CommentReference;
9
import pro.verron.officestamper.api.Comment;
10
11
import java.util.ArrayList;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15
16
/**
17
 * <p>CommentWrapper class.</p>
18
 *
19
 * @author Joseph Verron
20
 * @author Tom Hombergs
21
 * @version ${version}
22
 * @since 1.0.2
23
 */
24
public class StandardComment
25
        implements Comment {
26
27
    private final Set<Comment> children = new HashSet<>();
28
    private final WordprocessingMLPackage document;
29
    private Comments.Comment comment;
30
    private CommentRangeStart commentRangeStart;
31
    private CommentRangeEnd commentRangeEnd;
32
    private CommentReference commentReference;
33
34
    /**
35
     * Constructs a new StandardComment object.
36
     *
37
     * @param document the WordprocessingMLPackage document instance
38
     */
39
    public StandardComment(WordprocessingMLPackage document) {
40
        this.document = document;
41
    }
42
43
    /**
44
     * <p>getParent.</p>
45
     *
46
     * @return the comment's author.
47
     */
48
    @Override
49
    public ContentAccessor getParent() {
50 1 1. getParent : replaced return value with null for pro/verron/officestamper/core/StandardComment::getParent → KILLED
        return DocumentUtil.findSmallestCommonParent(getCommentRangeStart(), getCommentRangeEnd());
51
    }
52
53
    /**
54
     * @return the elements in the document that are between the comment range anchors.
55
     */
56
    @Override
57
    public List<Object> getElements() {
58
        List<Object> elements = new ArrayList<>();
59
        boolean startFound = false;
60
        boolean endFound = false;
61
        var parentElements = getParent().getContent();
62
        for (Object element : parentElements) {
63 2 1. getElements : negated conditional → KILLED
2. getElements : negated conditional → KILLED
            startFound = startFound || DocumentUtil.depthElementSearch(getCommentRangeStart(), element);
64 2 1. getElements : negated conditional → KILLED
2. getElements : negated conditional → KILLED
            if (startFound && !endFound) elements.add(element);
65 2 1. getElements : negated conditional → KILLED
2. getElements : negated conditional → KILLED
            endFound = endFound || DocumentUtil.depthElementSearch(getCommentRangeEnd(), element);
66
        }
67 1 1. getElements : replaced return value with Collections.emptyList for pro/verron/officestamper/core/StandardComment::getElements → KILLED
        return elements;
68
    }
69
70
    /**
71
     * <p>Getter for the field <code>commentRangeEnd</code>.</p>
72
     *
73
     * @return a {@link CommentRangeEnd} object
74
     */
75
    @Override
76
    public CommentRangeEnd getCommentRangeEnd() {
77 1 1. getCommentRangeEnd : replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentRangeEnd → KILLED
        return commentRangeEnd;
78
    }
79
80
    public void setCommentRangeEnd(CommentRangeEnd commentRangeEnd) {
81
        this.commentRangeEnd = commentRangeEnd;
82
    }
83
84
    /**
85
     * <p>Getter for the field <code>commentRangeStart</code>.</p>
86
     *
87
     * @return a {@link CommentRangeStart} object
88
     */
89
    @Override
90
    public CommentRangeStart getCommentRangeStart() {
91 1 1. getCommentRangeStart : replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentRangeStart → KILLED
        return commentRangeStart;
92
    }
93
94
    public void setCommentRangeStart(CommentRangeStart commentRangeStart) {
95
        this.commentRangeStart = commentRangeStart;
96
    }
97
98
    /**
99
     * <p>Getter for the field <code>commentReference</code>.</p>
100
     *
101
     * @return a {@link CommentReference} object
102
     */
103
    @Override
104
    public CommentReference getCommentReference() {
105 1 1. getCommentReference : replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentReference → KILLED
        return commentReference;
106
    }
107
108
    public void setCommentReference(CommentReference commentReference) {
109
        this.commentReference = commentReference;
110
    }
111
112
    /**
113
     * <p>Getter for the field <code>children</code>.</p>
114
     *
115
     * @return a {@link Set} object
116
     */
117
    @Override
118
    public Set<Comment> getChildren() {
119 1 1. getChildren : replaced return value with Collections.emptySet for pro/verron/officestamper/core/StandardComment::getChildren → KILLED
        return children;
120
    }
121
122
    public void setChildren(Set<Comment> children) {
123
        this.children.addAll(children);
124
    }
125
126
    /**
127
     * <p>Getter for the field <code>comment</code>.</p>
128
     *
129
     * @return a {@link Comments.Comment} object
130
     */
131
    @Override
132
    public Comments.Comment getComment() {
133 1 1. getComment : replaced return value with null for pro/verron/officestamper/core/StandardComment::getComment → KILLED
        return comment;
134
    }
135
136
    public void setComment(Comments.Comment comment) {
137
        this.comment = comment;
138
    }
139
140
    @Override public WordprocessingMLPackage getDocument() {
141 1 1. getDocument : replaced return value with null for pro/verron/officestamper/core/StandardComment::getDocument → KILLED
        return document;
142
    }
143
144
}

Mutations

50

1.1
Location : getParent
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/core/StandardComment::getParent → KILLED

63

1.1
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

2.2
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

64

1.1
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

2.2
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

65

1.1
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

2.2
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

67

1.1
Location : getElements
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
replaced return value with Collections.emptyList for pro/verron/officestamper/core/StandardComment::getElements → KILLED

77

1.1
Location : getCommentRangeEnd
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[method:fails()]
replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentRangeEnd → KILLED

91

1.1
Location : getCommentRangeStart
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[method:fails()]
replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentRangeStart → KILLED

105

1.1
Location : getCommentReference
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:#30]
replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentReference → KILLED

119

1.1
Location : getChildren
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
replaced return value with Collections.emptySet for pro/verron/officestamper/core/StandardComment::getChildren → KILLED

133

1.1
Location : getComment
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[method:fails()]
replaced return value with null for pro/verron/officestamper/core/StandardComment::getComment → KILLED

141

1.1
Location : getDocument
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:#9]
replaced return value with null for pro/verron/officestamper/core/StandardComment::getDocument → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0