use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager in project pmd-eclipse-plugin by pmd.
the class UpdateProjectPropertiesCmdTest method testBug.
/**
* Bug: when a user deselect a project rule it is not saved
*/
@Test
public void testBug() throws CommandException, PropertiesException {
final RuleSetFactory factory = new RuleSetFactory();
// First ensure that the plugin initial ruleset is equal to the project
// ruleset
final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
RuleSet projectRuleSet = model.getProjectRuleSet();
Assert.assertEquals("The project ruleset is not equal to the plugin ruleset", PMDPlugin.getDefault().getPreferencesManager().getRuleSet().getRules(), projectRuleSet.getRules());
int ruleCountBefore = projectRuleSet.getRules().size();
// 2. remove a rule (keep its name for assertion)
RuleSet newRuleSet = RuleSetUtil.newEmpty("test-ruleset", "ruleset for unit testing");
newRuleSet = RuleSetUtil.addRules(newRuleSet, projectRuleSet.getRules());
final Rule removedRule = newRuleSet.getRuleByName("UnnecessaryParentheses");
newRuleSet = RuleSetUtil.removeRule(newRuleSet, removedRule);
final UpdateProjectPropertiesCmd cmd = new UpdateProjectPropertiesCmd();
cmd.setPmdEnabled(true);
cmd.setProject(this.testProject);
cmd.setProjectRuleSet(newRuleSet);
cmd.setProjectWorkingSet(null);
cmd.setRuleSetStoredInProject(false);
cmd.execute();
// 3. test the rule has correctly been removed
projectRuleSet = model.getProjectRuleSet();
Assert.assertEquals("Rule count should be 1 less", ruleCountBefore - 1, projectRuleSet.getRules().size());
for (Rule r : projectRuleSet.getRules()) {
if (r.getName().equals(removedRule.getName()) && r.getLanguage() == removedRule.getLanguage()) {
Assert.fail("The rule has not been removed!");
}
}
}
Aggregations