Skip to content

Commit 214b5b0

Browse files
Phillip KrallPhillip Krall
authored andcommitted
Fix the Tests that were broken
1 parent d384150 commit 214b5b0

File tree

2 files changed

+195
-203
lines changed

2 files changed

+195
-203
lines changed

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCmdTest.java

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@
4848
import org.junit.Before;
4949
import org.junit.Test;
5050

51+
import name.herlin.command.CommandException;
52+
import name.herlin.command.UnsetInputPropertiesException;
5153
import net.sourceforge.pmd.Rule;
5254
import net.sourceforge.pmd.RuleSet;
55+
import net.sourceforge.pmd.RuleSets;
5356
import net.sourceforge.pmd.eclipse.EclipseUtils;
5457
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
5558
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
5659
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
5760

58-
import name.herlin.command.CommandException;
59-
import name.herlin.command.UnsetInputPropertiesException;
60-
6161
/**
6262
* This tests the PMD Processor command
6363
*
@@ -131,45 +131,44 @@ public void testReviewCmdBasic() throws CommandException, CoreException {
131131
*/
132132
@Test
133133
public void testProjectBuildPath() throws Exception {
134-
// TODO (pk) Fix this
135-
// IProjectProperties properties = PMDPlugin.getDefault().getPropertiesManager()
136-
// .loadProjectProperties(testProject);
137-
// Rule compareObjectsWithEquals = properties.getProjectRuleSet().getRuleByName("CompareObjectsWithEquals");
138-
// RuleSet projectRuleSet = RuleSetUtil.newSingle(compareObjectsWithEquals);
139-
// properties.setProjectRuleSets(projectRuleSet);
140-
// boolean oldSetting = PMDPlugin.getDefault().getPreferencesManager().loadPreferences()
141-
// .isProjectBuildPathEnabled();
142-
//
143-
// try {
144-
// PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(true);
145-
// EclipseUtils.createTestSourceFile(testProject, "/src/MyEnum.java", "public enum MyEnum { A, B }");
146-
// IFile sourceFile = EclipseUtils.createTestSourceFile(testProject, "/src/Foo.java",
147-
// "class Foo {\n" + " boolean bar(MyEnum a, MyEnum b) {\n" + " return a == b;\n" + // line 3
148-
// " }\n" + "}");
149-
// testProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
150-
// testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
151-
//
152-
// ReviewCodeCmd cmd = new ReviewCodeCmd();
153-
// cmd.addResource(testProject);
154-
// cmd.performExecute();
155-
// cmd.join();
156-
// Map<IFile, Set<MarkerInfo2>> markers = cmd.getMarkers();
157-
// // with type resolution, this comparison is ok, as MyEnum is a enum
158-
// Assert.assertTrue("Type Resolution didn't work", markers.get(sourceFile).isEmpty());
159-
//
160-
// // without type resolution, there is a violation
161-
// PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(false);
162-
// cmd = new ReviewCodeCmd();
163-
// cmd.addResource(testProject);
164-
// cmd.performExecute();
165-
// cmd.join();
166-
// markers = cmd.getMarkers();
167-
// // there is a violation expected without type resolution
168-
// Assert.assertFalse(markers.get(sourceFile).isEmpty());
169-
//
170-
// } finally {
171-
// PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(oldSetting);
172-
// }
134+
IProjectProperties properties = PMDPlugin.getDefault().getPropertiesManager()
135+
.loadProjectProperties(testProject);
136+
Rule compareObjectsWithEquals = properties.getProjectRuleSet().getRuleByName("CompareObjectsWithEquals");
137+
RuleSet projectRuleSet = RuleSetUtil.newSingle(compareObjectsWithEquals);
138+
properties.setProjectRuleSets(new RuleSets(projectRuleSet));
139+
boolean oldSetting = PMDPlugin.getDefault().getPreferencesManager().loadPreferences()
140+
.isProjectBuildPathEnabled();
141+
142+
try {
143+
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(true);
144+
EclipseUtils.createTestSourceFile(testProject, "/src/MyEnum.java", "public enum MyEnum { A, B }");
145+
IFile sourceFile = EclipseUtils.createTestSourceFile(testProject, "/src/Foo.java",
146+
"class Foo {\n" + " boolean bar(MyEnum a, MyEnum b) {\n" + " return a == b;\n" + // line 3
147+
" }\n" + "}");
148+
testProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
149+
testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
150+
151+
ReviewCodeCmd cmd = new ReviewCodeCmd();
152+
cmd.addResource(testProject);
153+
cmd.performExecute();
154+
cmd.join();
155+
Map<IFile, Set<MarkerInfo2>> markers = cmd.getMarkers();
156+
// with type resolution, this comparison is ok, as MyEnum is a enum
157+
Assert.assertTrue("Type Resolution didn't work", markers.get(sourceFile).isEmpty());
158+
159+
// without type resolution, there is a violation
160+
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(false);
161+
cmd = new ReviewCodeCmd();
162+
cmd.addResource(testProject);
163+
cmd.performExecute();
164+
cmd.join();
165+
markers = cmd.getMarkers();
166+
// there is a violation expected without type resolution
167+
Assert.assertFalse(markers.get(sourceFile).isEmpty());
168+
169+
} finally {
170+
PMDPlugin.getDefault().getPreferencesManager().loadPreferences().setProjectBuildPathEnabled(oldSetting);
171+
}
173172
}
174173

175174
/**

0 commit comments

Comments
 (0)