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.relationships.RelationshipsPart;
6
import org.docx4j.relationships.Relationship;
7
import org.docx4j.wml.*;
8
import pro.verron.officestamper.api.DocxPart;
9
import pro.verron.officestamper.api.Paragraph;
10
11
import java.util.Collection;
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, Part part, ContentAccessor contentAccessor
28
    ) {
29
        this.document = document;
30
        this.part = part;
31
        this.contentAccessor = contentAccessor;
32
    }
33
34
35
    public Stream<Paragraph> streamParagraphs() {
36 1 1. streamParagraphs : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParagraphs → KILLED
        return Stream.concat(DocumentUtil.streamObjectElements(this, P.class)
37 1 1. lambda$streamParagraphs$0 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParagraphs$0 → KILLED
                                         .map(p -> StandardParagraph.from(this, p)),
38
                DocumentUtil.streamObjectElements(this, SdtRun.class)
39
                                    .map(SdtRun::getSdtContent)
40
                                    .filter(CTSdtContentRun.class::isInstance)
41
                                    .map(CTSdtContentRun.class::cast)
42 1 1. lambda$streamParagraphs$1 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParagraphs$1 → KILLED
                                    .map(paragraph -> StandardParagraph.from(this, paragraph)));
43
    }
44
45
    @Override public Stream<R> streamRun() {
46 1 1. streamRun : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamRun → KILLED
        return DocumentUtil.streamObjectElements(this, P.class)
47
                           .map(P::getContent)
48
                           .flatMap(Collection::stream)
49
                           .filter(R.class::isInstance)
50
                           .map(R.class::cast);
51
    }
52
53
54
    public Stream<DocxPart> streamParts(String type) {
55 1 1. streamParts : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParts → KILLED
        return document.getMainDocumentPart()
56
                       .getRelationshipsPart()
57
                       .getRelationshipsByType(type)
58
                       .stream()
59
                       .map(this::getPart)
60 1 1. lambda$streamParts$2 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParts$2 → KILLED
                       .map(p -> new TextualDocxPart(document, p, (ContentAccessor) p));
61
    }
62
63
    public Part getPart(Relationship r) {
64 1 1. getPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getPart → KILLED
        return getRelationshipsPart().getPart(r);
65
    }
66
67 1 1. document : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::document → KILLED
    public WordprocessingMLPackage document() {return document;}
68
    private RelationshipsPart getRelationshipsPart() {
69 1 1. getRelationshipsPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getRelationshipsPart → KILLED
        return part().getRelationshipsPart();
70
    }
71
72
73
74
    @Override public DocxPart from(ContentAccessor accessor) {
75 1 1. from : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::from → NO_COVERAGE
        return new TextualDocxPart(document, part, accessor);
76
    }
77
78 1 1. part : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::part → KILLED
    @Override public Part part() {return part;}
79
80 1 1. content : replaced return value with Collections.emptyList for pro/verron/officestamper/core/TextualDocxPart::content → NO_COVERAGE
    @Override public List<Object> content() {return contentAccessor.getContent();}
81
82
83
    @Override public int hashCode() {
84 1 1. hashCode : replaced int return with 0 for pro/verron/officestamper/core/TextualDocxPart::hashCode → NO_COVERAGE
        return Objects.hash(document, part, contentAccessor);
85
    }
86
87
    @Override public boolean equals(Object obj) {
88 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;
89 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;
90
        var that = (TextualDocxPart) obj;
91 4 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
4. equals : negated conditional → NO_COVERAGE
        return Objects.equals(this.document, that.document) && Objects.equals(this.part, that.part) && Objects.equals(
92
                this.contentAccessor,
93
                that.contentAccessor);
94
    }
95
96
    @Override public String toString() {
97 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());
98
    }
99
100
}

Mutations

36

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

37

1.1
Location : lambda$streamParagraphs$0
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:#30]
replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParagraphs$0 → KILLED

42

1.1
Location : lambda$streamParagraphs$1
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:#39]
replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParagraphs$1 → KILLED

46

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

55

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

60

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

64

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

67

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

69

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

75

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

78

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

80

1.1
Location : content
Killed by : none
replaced return value with Collections.emptyList for pro/verron/officestamper/core/TextualDocxPart::content → NO_COVERAGE

84

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

88

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

89

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

91

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

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

97

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.1