diff --git a/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java b/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java index b3640fd41a..2745fd7f2a 100644 --- a/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java +++ b/pmd-netbeans/src/pmd/config/PMDOptionsSettings.java @@ -39,6 +39,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; +import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.RuleSetFactory; import org.openide.util.NbPreferences; /** @@ -87,7 +89,7 @@ public class PMDOptionsSettings { "AvoidReassigningParametersRule, OnlyOneReturn, UseSingletonRule, " + "DontImportJavaLang, UnusedImports, DuplicateImports, "; - /** Name of key for storing part of cumstom rulesets settings. */ + /** Name of key for storing part of custom rule-set settings. */ private static String PROP_INCLUDE_STD_RULES = "includeStdRules"; private static final String NODE_RULESETS = "rulesets"; @@ -189,7 +191,7 @@ public class PMDOptionsSettings { int idx = keyName.indexOf(".", PROP_RULE_PROPERTIES.length()+2); if (idx == -1) continue; - String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx - 1); + String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx); Map props = ruleProps.get(ruleName); if (props == null) { props = new HashMap(); @@ -223,7 +225,7 @@ public class PMDOptionsSettings { int idx = keyName.indexOf(".", PROP_RULE_PROPERTIES.length()+2); if (idx == -1) continue; - String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx - 1); + String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx); String propName = keyName.substring(idx+1); if (ruleProperties.get(ruleName) != null && ruleProperties.get(ruleName).get(propName) == null) { prefs.remove(keyName); diff --git a/pmd-netbeans/test/unit/src/pmd/config/PMDOptionsSettingsTest.java b/pmd-netbeans/test/unit/src/pmd/config/PMDOptionsSettingsTest.java new file mode 100644 index 0000000000..f99ff8c93c --- /dev/null +++ b/pmd-netbeans/test/unit/src/pmd/config/PMDOptionsSettingsTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2002-2003, the pmd-netbeans team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ +package pmd.config; + +import java.util.Map; +import java.util.HashMap; +import org.netbeans.junit.NbTestCase; + +/** + * @author radim + */ +public class PMDOptionsSettingsTest extends NbTestCase { + + public PMDOptionsSettingsTest(String testName) { + super(testName); + } + + /** + * Test of getHelpCtx method, of class pmd.RunPMDAction. + */ + public void testRuleProperties() { +// Preferences prefs = mock(Preferences.class); +// PMDOptionsSettings settings = new PMDOptionsSettings(prefs); + PMDOptionsSettings settings = PMDOptionsSettings.getDefault(); + Map> ruleProperties = new HashMap>(); + Map properties = new HashMap(); + properties.put("propA", "valueA"); + properties.put("propB", "valueB"); + ruleProperties.put("rule1", properties); + properties = new HashMap(); + properties.put("prop1", "value1"); + ruleProperties.put("rule2", properties); + settings.setRuleProperties(ruleProperties); + + Map> readRuleProperties = settings.getRuleProperties(); + assertNotNull(readRuleProperties); + assertTrue("correct size of " + readRuleProperties, readRuleProperties.size() == ruleProperties.size()); + for(Map.Entry> entry : readRuleProperties.entrySet()) { + assertTrue(ruleProperties.containsKey(entry.getKey())); + assertEquals(entry.getValue(), ruleProperties.get(entry.getKey())); + } + } + +}