• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmd / pmd / 46

26 Jun 2025 09:17AM UTC coverage: 78.43% (+0.05%) from 78.379%
46

push

github

adangel
[test] Verify suppressed violations in rule tests (#5806)

Merge pull request #5806 from adangel:test/assert-suppressions

17746 of 23468 branches covered (75.62%)

Branch coverage included in aggregate %.

55 of 62 new or added lines in 4 files covered. (88.71%)

38998 of 48882 relevant lines covered (79.78%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/pmd-test-schema/src/main/java/net/sourceforge/pmd/test/schema/RuleTestDescriptor.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.test.schema;
6

7
import java.util.ArrayList;
8
import java.util.List;
9
import java.util.Properties;
10

11
import net.sourceforge.pmd.lang.LanguageVersion;
12
import net.sourceforge.pmd.lang.rule.Rule;
13

14
/**
15
 * @author Clément Fournier
16
 */
17
public class RuleTestDescriptor {
18

19
    private boolean disabled;
20
    private boolean focused;
21
    private String description;
22
    private LanguageVersion languageVersion;
23
    private final Properties properties = new Properties();
1✔
24
    private final int index;
25
    private final Rule rule;
26
    private String code;
27
    private int expectedProblems;
28
    private List<Integer> expectedLineNumbers;
29
    private List<Integer> expectedEndLineNumbers;
30
    private List<String> expectedMessages;
31
    private List<SuppressionDescriptor> expectedSuppressions;
32
    private int lineNumber;
33

34
    public static final class SuppressionDescriptor {
35
        private final int line;
36
        private final String suppressorId;
37

38
        private SuppressionDescriptor(int line, String suppressorId) {
1✔
39
            this.line = line;
1✔
40
            this.suppressorId = suppressorId;
1✔
41
        }
1✔
42

43
        public int getLine() {
44
            return line;
1✔
45
        }
46

47
        public String getSuppressorId() {
48
            return suppressorId;
1✔
49
        }
50
    }
51

52
    public RuleTestDescriptor(int index, Rule rule) {
1✔
53
        this.index = index;
1✔
54
        this.rule = rule;
1✔
55
        this.languageVersion = rule.getLanguage().getDefaultVersion();
1✔
56
    }
1✔
57

58
    public Rule getRule() {
59
        return rule;
1✔
60
    }
61

62
    public Properties getProperties() {
63
        return properties;
1✔
64
    }
65

66
    public boolean isDisabled() {
67
        return disabled;
×
68
    }
69

70
    public void setDisabled(boolean disabled) {
71
        this.disabled = disabled;
1✔
72
    }
1✔
73

74
    public String getDescription() {
75
        return description;
×
76
    }
77

78
    public void setDescription(String description) {
79
        this.description = description;
1✔
80
    }
1✔
81

82
    public LanguageVersion getLanguageVersion() {
83
        return languageVersion;
×
84
    }
85

86
    public void setLanguageVersion(LanguageVersion languageVersion) {
87
        if (!languageVersion.getLanguage().equals(this.getRule().getLanguage())) {
×
88
            throw new IllegalArgumentException("Invalid version " + languageVersion);
×
89
        }
90
        this.languageVersion = languageVersion;
×
91
    }
×
92

93
    public String getCode() {
94
        return code;
1✔
95
    }
96

97
    public void setCode(String code) {
98
        this.code = code;
1✔
99
    }
1✔
100

101
    public void recordExpectedViolations(int expectedProblems, List<Integer> expectedLineNumbers, List<String> expectedMessages) {
102
        checkListSize(expectedProblems, expectedLineNumbers);
1✔
103
        checkListSize(expectedProblems, expectedMessages);
1✔
104

105
        this.expectedProblems = expectedProblems;
1✔
106
        this.expectedLineNumbers = expectedLineNumbers;
1✔
107
        this.expectedMessages = expectedMessages;
1✔
108
    }
1✔
109

110
    public void recordExpectedViolations(int expectedProblems, List<Integer> expectedLineNumbers, List<Integer> expectedEndLineNumbers, List<String> expectedMessages) {
111
        checkListSize(expectedProblems, expectedEndLineNumbers);
1✔
112
        this.expectedEndLineNumbers = expectedEndLineNumbers;
1✔
113
        recordExpectedViolations(expectedProblems, expectedLineNumbers, expectedMessages);
1✔
114
    }
1✔
115

116
    private void checkListSize(int expectedProblems, List<?> expectedMessages) {
117
        if (!expectedMessages.isEmpty() && expectedProblems != expectedMessages.size()) {
1!
118
            throw new IllegalArgumentException(
×
119
                "Expected list of size " + expectedProblems + ", got " + expectedMessages);
120
        }
121
    }
1✔
122

123
    public int getExpectedProblems() {
124
        return expectedProblems;
×
125
    }
126

127
    public int getIndex() {
128
        return index;
×
129
    }
130

131
    public List<Integer> getExpectedLineNumbers() {
132
        return expectedLineNumbers;
×
133
    }
134

135
    public List<Integer> getExpectedEndLineNumbers() {
136
        return expectedEndLineNumbers;
×
137
    }
138

139
    public List<String> getExpectedMessages() {
140
        return expectedMessages;
×
141
    }
142

143
    public boolean isFocused() {
144
        return focused;
×
145
    }
146

147
    public void setFocused(boolean focused) {
148
        this.focused = focused;
1✔
149
    }
1✔
150

151
    public int getLineNumber() {
152
        return lineNumber;
×
153
    }
154

155
    public void setLineNumber(int lineNumber) {
156
        this.lineNumber = lineNumber;
1✔
157
    }
1✔
158

159
    public boolean hasExpectedSuppressions() {
160
        return expectedSuppressions != null;
1✔
161
    }
162

163
    void createEmptyExpectedSuppression() {
164
        expectedSuppressions = new ArrayList<>();
1✔
165
    }
1✔
166

167
    public void recordExpectedSuppression(int line) {
NEW
168
        recordExpectedSuppression(line, null);
×
NEW
169
    }
×
170

171
    public void recordExpectedSuppression(int line, String suppressor) {
172
        if (expectedSuppressions == null) {
1!
NEW
173
            createEmptyExpectedSuppression();
×
174
        }
175
        this.expectedSuppressions.add(new SuppressionDescriptor(line, suppressor));
1✔
176
    }
1✔
177

178
    public List<SuppressionDescriptor> getExpectedSuppressions() {
179
        return expectedSuppressions;
1✔
180
    }
181
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc