DisplayIfProcessor.java

1
package pro.verron.officestamper.preset.processors.displayif;
2
3
import org.docx4j.wml.Tbl;
4
import org.docx4j.wml.Tr;
5
import org.springframework.lang.Nullable;
6
import pro.verron.officestamper.api.*;
7
import pro.verron.officestamper.core.ObjectDeleter;
8
import pro.verron.officestamper.core.PlaceholderReplacer;
9
import pro.verron.officestamper.preset.CommentProcessorFactory;
10
11
import java.util.ArrayList;
12
import java.util.List;
13
14
import static pro.verron.officestamper.api.OfficeStamperException.throwing;
15
16
/// Processor for the [CommentProcessorFactory.IDisplayIfProcessor] comment.
17
///
18
/// @author Joseph Verron
19
/// @author Tom Hombergs
20
/// @version ${version}
21
/// @since 1.0.0
22
public class DisplayIfProcessor
23
        extends AbstractCommentProcessor
24
        implements CommentProcessorFactory.IDisplayIfProcessor {
25
26
    private List<Paragraph> paragraphsToBeRemoved = new ArrayList<>();
27
    private List<Tbl> tablesToBeRemoved = new ArrayList<>();
28
    private List<Tr> tableRowsToBeRemoved = new ArrayList<>();
29
30
    private DisplayIfProcessor(ParagraphPlaceholderReplacer placeholderReplacer) {
31
        super(placeholderReplacer);
32
    }
33
34
    /// Creates a new DisplayIfProcessor instance.
35
    ///
36
    /// @param pr the [PlaceholderReplacer] used for replacing expressions.
37
    ///
38
    /// @return a new DisplayIfProcessor instance.
39
    public static CommentProcessor newInstance(ParagraphPlaceholderReplacer pr) {
40 1 1. newInstance : replaced return value with null for pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::newInstance → KILLED
        return new DisplayIfProcessor(pr);
41
    }
42
43
    @Override public void commitChanges(DocxPart source) {
44 1 1. commitChanges : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::removeParagraphs → KILLED
        removeParagraphs();
45 1 1. commitChanges : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::removeTables → KILLED
        removeTables();
46 1 1. commitChanges : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::removeTableRows → KILLED
        removeTableRows();
47
    }
48
49
    private void removeParagraphs() {
50 1 1. removeParagraphs : removed call to java/util/List::forEach → KILLED
        paragraphsToBeRemoved.forEach(Paragraph::remove);
51
    }
52
53
    private void removeTables() {
54 1 1. removeTables : removed call to java/util/List::forEach → KILLED
        tablesToBeRemoved.forEach(ObjectDeleter::deleteTable);
55
    }
56
57
    private void removeTableRows() {
58 1 1. removeTableRows : removed call to java/util/List::forEach → KILLED
        tableRowsToBeRemoved.forEach(ObjectDeleter::deleteTableRow);
59
    }
60
61
    @Override public void reset() {
62
        paragraphsToBeRemoved = new ArrayList<>();
63
        tablesToBeRemoved = new ArrayList<>();
64
        tableRowsToBeRemoved = new ArrayList<>();
65
    }
66
67
    @Override public void displayParagraphIf(@Nullable Boolean condition) {
68 1 1. displayParagraphIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
69
        paragraphsToBeRemoved.add(this.getParagraph());
70
    }
71
72
    @Override public void displayParagraphIfPresent(@Nullable Object condition) {
73 2 1. displayParagraphIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayParagraphIf → SURVIVED
2. displayParagraphIfPresent : negated conditional → KILLED
        displayParagraphIf(condition != null);
74
    }
75
76
    @Override public void displayTableRowIf(@Nullable Boolean condition) {
77 1 1. displayTableRowIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
78
        var tr = this.getParagraph()
79
                     .parent(Tr.class)
80
                     .orElseThrow(throwing("Paragraph is not within a row!"));
81
        tableRowsToBeRemoved.add(tr);
82
    }
83
84
    @Override public void displayTableRowIfPresent(@Nullable Object condition) {
85 2 1. displayTableRowIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableRowIf → NO_COVERAGE
2. displayTableRowIfPresent : negated conditional → NO_COVERAGE
        displayTableRowIf(condition != null);
86
    }
87
88
    @Override public void displayTableIf(Boolean condition) {
89 1 1. displayTableIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
90
        var tbl = this.getParagraph()
91
                      .parent(Tbl.class)
92
                      .orElseThrow(throwing("Paragraph is not within a table!"));
93
        tablesToBeRemoved.add(tbl);
94
    }
95
96
    @Override public void displayTableIfPresent(@Nullable Object condition) {
97 2 1. displayTableIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableIf → NO_COVERAGE
2. displayTableIfPresent : negated conditional → NO_COVERAGE
        displayTableIf(condition != null);
98
    }
99
100
    @Override public void displayWordsIf(@Nullable Boolean condition) {
101 1 1. displayWordsIf : negated conditional → NO_COVERAGE
        if (Boolean.TRUE.equals(condition)) return;
102
        var commentWrapper = getCurrentCommentWrapper();
103
        commentWrapper.getParent()
104
                      .getContent()
105
                      .removeAll(commentWrapper.getElements());
106
    }
107
108
    @Override public void displayWordsIfPresent(@Nullable Object condition) {
109 2 1. displayWordsIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayWordsIf → NO_COVERAGE
2. displayWordsIfPresent : negated conditional → NO_COVERAGE
        displayWordsIf(condition != null);
110
    }
111
112
    @Override public void displayDocPartIf(@Nullable Boolean condition) {
113 1 1. displayDocPartIf : negated conditional → NO_COVERAGE
        if (Boolean.TRUE.equals(condition)) return;
114
        var commentWrapper = getCurrentCommentWrapper();
115
        commentWrapper.getParent()
116
                      .getContent()
117
                      .removeAll(commentWrapper.getElements());
118
    }
119
120
    @Override public void displayDocPartIfPresent(@Nullable Object condition) {
121 2 1. displayDocPartIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayDocPartIf → NO_COVERAGE
2. displayDocPartIfPresent : negated conditional → NO_COVERAGE
        displayDocPartIf(condition != null);
122
    }
123
}

Mutations

40

1.1
Location : newInstance
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:#34]
replaced return value with null for pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::newInstance → KILLED

44

1.1
Location : commitChanges
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:#23]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::removeParagraphs → KILLED

45

1.1
Location : commitChanges
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:#23]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::removeTables → KILLED

46

1.1
Location : commitChanges
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:#22]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::removeTableRows → KILLED

50

1.1
Location : removeParagraphs
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:#23]
removed call to java/util/List::forEach → KILLED

54

1.1
Location : removeTables
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:#23]
removed call to java/util/List::forEach → KILLED

58

1.1
Location : removeTableRows
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:#22]
removed call to java/util/List::forEach → KILLED

68

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

73

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

2.2
Location : displayParagraphIfPresent
Killed by : none
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayParagraphIf → SURVIVED
Covering tests

77

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

85

1.1
Location : displayTableRowIfPresent
Killed by : none
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableRowIf → NO_COVERAGE

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

89

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

97

1.1
Location : displayTableIfPresent
Killed by : none
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableIf → NO_COVERAGE

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

101

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

109

1.1
Location : displayWordsIfPresent
Killed by : none
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayWordsIf → NO_COVERAGE

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

113

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

121

1.1
Location : displayDocPartIfPresent
Killed by : none
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayDocPartIf → NO_COVERAGE

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

Active mutators

Tests examined


Report generated by PIT 1.17.1