|
48 | 48 | import org.junit.Before; |
49 | 49 | import org.junit.Test; |
50 | 50 |
|
| 51 | +import name.herlin.command.CommandException; |
| 52 | +import name.herlin.command.UnsetInputPropertiesException; |
51 | 53 | import net.sourceforge.pmd.Rule; |
52 | 54 | import net.sourceforge.pmd.RuleSet; |
| 55 | +import net.sourceforge.pmd.RuleSets; |
53 | 56 | import net.sourceforge.pmd.eclipse.EclipseUtils; |
54 | 57 | import net.sourceforge.pmd.eclipse.plugin.PMDPlugin; |
55 | 58 | import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties; |
56 | 59 | import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil; |
57 | 60 |
|
58 | | -import name.herlin.command.CommandException; |
59 | | -import name.herlin.command.UnsetInputPropertiesException; |
60 | | - |
61 | 61 | /** |
62 | 62 | * This tests the PMD Processor command |
63 | 63 | * |
@@ -131,45 +131,44 @@ public void testReviewCmdBasic() throws CommandException, CoreException { |
131 | 131 | */ |
132 | 132 | @Test |
133 | 133 | 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 | + } |
173 | 172 | } |
174 | 173 |
|
175 | 174 | /** |
|
0 commit comments