1 /***
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package test.net.sourceforge.pmd.testframework;
5
6 import net.sourceforge.pmd.Report;
7 import net.sourceforge.pmd.Rule;
8 import net.sourceforge.pmd.RuleContext;
9 import net.sourceforge.pmd.RuleViolation;
10
11 import java.util.HashSet;
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.Properties;
15 import java.util.Set;
16
17 public class MockRule implements Rule {
18
19 private String name;
20 private String description;
21 private String message;
22 private Set violations = new HashSet();
23 private Properties properties = new Properties();
24 private String example;
25 private int priority;
26
27 public String getExample() {
28 return example;
29 }
30
31 public void setExample(String example) {
32 this.example = example;
33 }
34
35 public int getPriority() {
36 return this.priority;
37 }
38
39 public String getPriorityName() {
40 return null;
41 }
42
43 public void setPriority(int priority) {
44 this.priority = priority;
45 }
46
47 public String getDescription() {
48 return description;
49 }
50
51 public void setDescription(String description) {
52 this.description = description;
53 }
54
55 public String getName() {
56 return name;
57 }
58
59 public void setName(String name) {
60 this.name = name;
61 }
62
63 public String getMessage() {
64 return message;
65 }
66
67 public void setMessage(String message) {
68 this.message = message;
69 }
70
71 public boolean hasProperty(String name) {
72 return properties.containsKey(name);
73 }
74
75 public void addProperty(String name, String value) {
76 properties.setProperty(name, value);
77 }
78
79 public int getIntProperty(String name) {
80 return Integer.parseInt(properties.getProperty(name));
81 }
82
83 public double getDoubleProperty(String name) {
84 return Double.parseDouble(properties.getProperty(name));
85 }
86
87 public boolean getBooleanProperty(String name) {
88 return Boolean.valueOf(properties.getProperty(name)).booleanValue();
89 }
90
91 public String getStringProperty(String name) {
92 return properties.getProperty(name);
93 }
94
95 public Properties getProperties() {
96 return properties;
97 }
98
99 public boolean include() {
100 return true;
101 }
102
103 public void setInclude(boolean include) {
104 }
105
106 /***
107 * For use by RuleSetFactory only!
108 */
109 public MockRule() {
110 }
111
112 public MockRule(String name, String description, String message) {
113 this.name = name;
114 this.description = description;
115 this.message = message;
116 }
117
118
119 public void addViolation(RuleViolation violation) {
120 violations.add(violation);
121 }
122
123 public void apply(List astCompilationUnits, RuleContext ctx) {
124 Report report = ctx.getReport();
125
126 Iterator vs = violations.iterator();
127 while (vs.hasNext()) {
128 report.addRuleViolation((RuleViolation) vs.next());
129 }
130 }
131
132 }
This page was automatically generated by Maven