|
19 | 19 | import java.util.Iterator; |
20 | 20 | import java.util.LinkedList; |
21 | 21 | import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Map.Entry; |
22 | 24 | import java.util.Objects; |
23 | 25 | import java.util.Set; |
| 26 | +import java.util.TreeMap; |
| 27 | +import java.util.regex.Pattern; |
24 | 28 |
|
25 | 29 | import org.apache.commons.io.IOUtils; |
26 | 30 | import org.eclipse.core.resources.IFile; |
|
48 | 52 | import net.sourceforge.pmd.eclipse.runtime.builder.PMDNature; |
49 | 53 | import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager; |
50 | 54 | import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil; |
| 55 | +import net.sourceforge.pmd.lang.LanguageRegistry; |
51 | 56 | import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; |
| 57 | +import net.sourceforge.pmd.properties.PropertyDescriptor; |
52 | 58 |
|
53 | 59 | /** |
54 | 60 | * Test the project properties model. |
@@ -84,7 +90,36 @@ public void setUp() throws Exception { |
84 | 90 | } |
85 | 91 | Assert.assertEquals(ruleCount, this.initialPluginRuleSet.getRules().size()); |
86 | 92 | 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 | + } |
88 | 123 |
|
89 | 124 | PMDPlugin.getDefault().getPreferencesManager().setRuleSet(this.initialPluginRuleSet); |
90 | 125 |
|
@@ -309,6 +344,7 @@ public String getName() { |
309 | 344 | return "MyRule"; |
310 | 345 | } |
311 | 346 | }; |
| 347 | + myRule.setLanguage(LanguageRegistry.PMD.getLanguageById("java")); |
312 | 348 |
|
313 | 349 | RuleSet newRuleSet = RuleSetUtil.newEmpty("foo", "bar"); |
314 | 350 | newRuleSet = RuleSetUtil.addRules(newRuleSet, this.initialPluginRuleSet.getRules()); |
@@ -592,7 +628,7 @@ public void testProjectClasspath() throws Exception { |
592 | 628 | urls.add(url.toURI()); |
593 | 629 | } |
594 | 630 |
|
595 | | - Assert.assertEquals(6, urls.size()); |
| 631 | + Assert.assertEquals("Found these URIs: " + urls, 6, urls.size()); |
596 | 632 |
|
597 | 633 | // own project's output folder |
598 | 634 | Assert.assertTrue(urls.remove( |
|
0 commit comments