Skip to content

Commit 699e477

Browse files
committed
Fix test ProjectPropertiesModelTest
1 parent 04ab9a7 commit 699e477

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/ProjectPropertiesModelTest.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import java.util.Iterator;
2020
import java.util.LinkedList;
2121
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Map.Entry;
2224
import java.util.Objects;
2325
import java.util.Set;
26+
import java.util.TreeMap;
27+
import java.util.regex.Pattern;
2428

2529
import org.apache.commons.io.IOUtils;
2630
import org.eclipse.core.resources.IFile;
@@ -48,7 +52,9 @@
4852
import net.sourceforge.pmd.eclipse.runtime.builder.PMDNature;
4953
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager;
5054
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
55+
import net.sourceforge.pmd.lang.LanguageRegistry;
5156
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
57+
import net.sourceforge.pmd.properties.PropertyDescriptor;
5258

5359
/**
5460
* Test the project properties model.
@@ -84,7 +90,36 @@ public void setUp() throws Exception {
8490
}
8591
Assert.assertEquals(ruleCount, this.initialPluginRuleSet.getRules().size());
8692
RuleSet cloned = RuleSetUtil.newCopyOf(this.initialPluginRuleSet);
87-
Assert.assertEquals(cloned.getRules(), this.initialPluginRuleSet.getRules());
93+
Assert.assertEquals(cloned.getRules().size(), this.initialPluginRuleSet.getRules().size());
94+
Iterator<Rule> clonedIterator = cloned.getRules().iterator();
95+
Iterator<Rule> initialIterator = this.initialPluginRuleSet.getRules().iterator();
96+
for (int i = 0; i < cloned.getRules().size(); i++) {
97+
System.out.println("Comparing rule " + i);
98+
Rule clonedRule = clonedIterator.next();
99+
Rule initialRule = initialIterator.next();
100+
Assert.assertSame(clonedRule.getClass(), initialRule.getClass());
101+
Assert.assertEquals(clonedRule.getName(), initialRule.getName());
102+
Assert.assertEquals(clonedRule.getPriority(), initialRule.getPriority());
103+
Map<PropertyDescriptor<?>, Object> clonedProperties = new TreeMap<>((a, b) -> a.name().compareTo(b.name()));
104+
clonedProperties.putAll(clonedRule.getPropertiesByPropertyDescriptor());
105+
Map<PropertyDescriptor<?>, Object> initialProperties = new TreeMap<>((a, b) -> a.name().compareTo(b.name()));
106+
initialProperties.putAll(initialRule.getPropertiesByPropertyDescriptor());
107+
Assert.assertEquals(clonedProperties.size(), initialProperties.size());
108+
Iterator<Entry<PropertyDescriptor<?>, Object>> clonedPropertiesIterator = clonedProperties.entrySet().iterator();
109+
Iterator<Entry<PropertyDescriptor<?>, Object>> initialPropertiesIterator = initialProperties.entrySet().iterator();
110+
for (int j = 0; j < clonedProperties.size(); j++) {
111+
Entry<PropertyDescriptor<?>, Object> clonedProperty = clonedPropertiesIterator.next();
112+
Entry<PropertyDescriptor<?>, Object> initialProperty = initialPropertiesIterator.next();
113+
Assert.assertEquals(clonedProperty.getKey(), initialProperty.getKey());
114+
if (clonedProperty.getValue() instanceof Pattern) {
115+
Pattern clonedPattern = (Pattern) clonedProperty.getValue();
116+
Pattern initialPattern = (Pattern) initialProperty.getValue();
117+
Assert.assertEquals(clonedPattern.pattern(), initialPattern.pattern());
118+
} else {
119+
Assert.assertEquals(clonedProperty.getValue(), initialProperty.getValue());
120+
}
121+
}
122+
}
88123

89124
PMDPlugin.getDefault().getPreferencesManager().setRuleSet(this.initialPluginRuleSet);
90125

@@ -309,6 +344,7 @@ public String getName() {
309344
return "MyRule";
310345
}
311346
};
347+
myRule.setLanguage(LanguageRegistry.PMD.getLanguageById("java"));
312348

313349
RuleSet newRuleSet = RuleSetUtil.newEmpty("foo", "bar");
314350
newRuleSet = RuleSetUtil.addRules(newRuleSet, this.initialPluginRuleSet.getRules());
@@ -592,7 +628,7 @@ public void testProjectClasspath() throws Exception {
592628
urls.add(url.toURI());
593629
}
594630

595-
Assert.assertEquals(6, urls.size());
631+
Assert.assertEquals("Found these URIs: " + urls, 6, urls.size());
596632

597633
// own project's output folder
598634
Assert.assertTrue(urls.remove(

0 commit comments

Comments
 (0)