TextualDocxPart.java

1
package pro.verron.officestamper.core;
2
3
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
4
import org.docx4j.openpackaging.parts.Part;
5
import org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart;
6
import org.docx4j.openpackaging.parts.relationships.RelationshipsPart;
7
import org.docx4j.relationships.Relationship;
8
import org.docx4j.wml.ContentAccessor;
9
import org.docx4j.wml.P;
10
import pro.verron.officestamper.api.DocxPart;
11
12
import java.util.List;
13
import java.util.Objects;
14
import java.util.stream.Stream;
15
16
public final class TextualDocxPart
17
        implements DocxPart {
18
    private final WordprocessingMLPackage document;
19
    private final Part part;
20
    private final ContentAccessor contentAccessor;
21
22
    public TextualDocxPart(WordprocessingMLPackage document) {
23
        this(document, document.getMainDocumentPart(), document.getMainDocumentPart());
24
    }
25
26
    public TextualDocxPart(
27
            WordprocessingMLPackage document,
28
            Part part,
29
            ContentAccessor contentAccessor
30
    ) {
31
        this.document = document;
32
        this.part = part;
33
        this.contentAccessor = contentAccessor;
34
    }
35
36
    public Stream<P> streamParagraphs() {
37 1 1. streamParagraphs : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParagraphs → KILLED
        return DocumentUtil.streamObjectElements(this, P.class);
38
    }
39
40
    public Stream<DocxPart> streamParts(String type) {
41 1 1. streamParts : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParts → KILLED
        return document.getMainDocumentPart()
42
                       .getRelationshipsPart()
43
                       .getRelationshipsByType(type)
44
                       .stream()
45
                       .map(this::getPart)
46 1 1. lambda$streamParts$0 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParts$0 → KILLED
                       .map(p -> new TextualDocxPart(document, p, (ContentAccessor) p));
47
    }
48
49
    public Part getPart(Relationship r) {
50 1 1. getPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getPart → KILLED
        return getRelationshipsPart().getPart(r);
51
    }
52
53 1 1. document : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::document → KILLED
    public WordprocessingMLPackage document() {return document;}
54
55
    private RelationshipsPart getRelationshipsPart() {
56 1 1. getRelationshipsPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getRelationshipsPart → KILLED
        return part().getRelationshipsPart();
57
    }
58
59
    public CommentsPart commentsPart() {
60 1 1. commentsPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::commentsPart → KILLED
        return CommentUtil.getCommentsPart(document.getParts());
61
    }
62
63
    @Override public DocxPart from(ContentAccessor accessor) {
64 1 1. from : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::from → KILLED
        return new TextualDocxPart(document, part, accessor);
65
    }
66
67 1 1. part : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::part → KILLED
    @Override public Part part() {return part;}
68
69 1 1. content : replaced return value with Collections.emptyList for pro/verron/officestamper/core/TextualDocxPart::content → KILLED
    @Override public List<Object> content() {return contentAccessor.getContent();}
70
71
    @Override
72
    public int hashCode() {
73 1 1. hashCode : replaced int return with 0 for pro/verron/officestamper/core/TextualDocxPart::hashCode → NO_COVERAGE
        return Objects.hash(document, part, contentAccessor);
74
    }
75
76
    @Override
77
    public boolean equals(Object obj) {
78 2 1. equals : replaced boolean return with false for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE
2. equals : negated conditional → NO_COVERAGE
        if (obj == this) return true;
79 3 1. equals : negated conditional → NO_COVERAGE
2. equals : negated conditional → NO_COVERAGE
3. equals : replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE
        if (obj == null || obj.getClass() != this.getClass()) return false;
80
        var that = (TextualDocxPart) obj;
81 2 1. equals : replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE
2. equals : negated conditional → NO_COVERAGE
        return Objects.equals(this.document, that.document) &&
82 1 1. equals : negated conditional → NO_COVERAGE
               Objects.equals(this.part, that.part) &&
83 1 1. equals : negated conditional → NO_COVERAGE
               Objects.equals(this.contentAccessor, that.contentAccessor);
84
    }
85
86
    @Override public String toString() {
87 1 1. toString : replaced return value with "" for pro/verron/officestamper/core/TextualDocxPart::toString → NO_COVERAGE
        return "DocxPart{doc=%s, part=%s}".formatted(document.name(), part.getPartName());
88
    }
89
90
}

Mutations

37

1.1
Location : streamParagraphs
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:#17]
replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParagraphs → KILLED

41

1.1
Location : streamParts
Killed by : pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest]/[method:expressionReplacementInHeaderAndFooterTest()]
replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParts → KILLED

46

1.1
Location : lambda$streamParts$0
Killed by : pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest]/[method:expressionReplacementInHeaderAndFooterTest()]
replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParts$0 → KILLED

50

1.1
Location : getPart
Killed by : pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest]/[method:expressionReplacementInHeaderAndFooterTest()]
replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getPart → KILLED

53

1.1
Location : document
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/TextualDocxPart::document → KILLED

56

1.1
Location : getRelationshipsPart
Killed by : pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.PlaceholderReplacementInHeaderAndFooterTest]/[method:expressionReplacementInHeaderAndFooterTest()]
replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getRelationshipsPart → KILLED

60

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

64

1.1
Location : from
Killed by : pro.verron.officestamper.test.MultiStampTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.MultiStampTest]/[method:expressionsAreResolvedOnMultiStamp()]
replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::from → KILLED

67

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

69

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

73

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for pro/verron/officestamper/core/TextualDocxPart::hashCode → NO_COVERAGE

78

1.1
Location : equals
Killed by : none
replaced boolean return with false for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE

2.2
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

79

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : equals
Killed by : none
replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE

81

1.1
Location : equals
Killed by : none
replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE

2.2
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

82

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

83

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

87

1.1
Location : toString
Killed by : none
replaced return value with "" for pro/verron/officestamper/core/TextualDocxPart::toString → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.17.0