Skip to content

Commit e697deb

Browse files
committed
Merge branch 'issue-43'
2 parents 36d376a + 8b2bc3e commit e697deb

File tree

11 files changed

+72
-59
lines changed

11 files changed

+72
-59
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.project
2+
.settings/
3+
.classpath

ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Eclipse Update Site:
1818

1919
* [#20](https://github.com/pmd/pmd-eclipse-plugin/issues/20): category.xml maybe broken
2020
* [#32](https://github.com/pmd/pmd-eclipse-plugin/issues/32): Upgrade PMD to 6.2.0
21+
* [#43](https://github.com/pmd/pmd-eclipse-plugin/issues/43): Update unit tests to use new ruleset categories
2122

2223
### External Contributions
2324

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

net.sourceforge.pmd.eclipse.plugin.test.fragment/src/main/resources/rulesets/extra1.xml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
The Basic Ruleset contains a collection of good practices which everyone should follow.
77
</description>
88

9-
<rule name="EmptyCatchBlock"
9+
<rule name="ExtraEmptyCatchBlock"
1010
language="java"
1111
message="Avoid empty catch blocks"
1212
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -40,7 +40,7 @@ The Basic Ruleset contains a collection of good practices which everyone should
4040
</example>
4141
</rule>
4242

43-
<rule name="EmptyIfStmt"
43+
<rule name="ExtraEmptyIfStmt"
4444
language="java"
4545
message="Avoid empty 'if' statements"
4646
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -63,7 +63,7 @@ The Basic Ruleset contains a collection of good practices which everyone should
6363
</rule>
6464

6565

66-
<rule name="EmptyWhileStmt"
66+
<rule name="ExtraEmptyWhileStmt"
6767
language="java"
6868
message="Avoid empty 'while' statements"
6969
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -90,7 +90,7 @@ The Basic Ruleset contains a collection of good practices which everyone should
9090
</rule>
9191

9292

93-
<rule name="EmptyTryBlock"
93+
<rule name="ExtraEmptyTryBlock"
9494
language="java"
9595
message="Avoid empty try blocks"
9696
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -117,7 +117,7 @@ Avoid empty try blocks, they serve no purpose.
117117
</example>
118118
</rule>
119119

120-
<rule name="EmptyFinallyBlock"
120+
<rule name="ExtraEmptyFinallyBlock"
121121
language="java"
122122
message="Avoid empty finally blocks"
123123
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -147,7 +147,7 @@ Avoid empty finally blocks, these can be deleted.
147147
</rule>
148148

149149

150-
<rule name="EmptySwitchStatements"
150+
<rule name="ExtraEmptySwitchStatements"
151151
language="java"
152152
message="Avoid empty switch statements"
153153
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -177,7 +177,7 @@ Avoid empty switch statements.
177177
</rule>
178178

179179

180-
<rule name="JumbledIncrementer"
180+
<rule name="ExtraJumbledIncrementer"
181181
language="java"
182182
message="Avoid modifying an outer loop incrementer in an inner loop for update expression"
183183
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -212,7 +212,7 @@ Avoid jumbled loop incrementers as these are usually a mistake and can make code
212212
</rule>
213213

214214

215-
<rule name="ForLoopShouldBeWhileLoop"
215+
<rule name="ExtraForLoopShouldBeWhileLoop"
216216
language="java"
217217
message="This for loop could be simplified to a while loop"
218218
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -243,7 +243,7 @@ Some for loops can be simplified to while loops - this makes them more concise.
243243
</rule>
244244

245245

246-
<rule name="UnnecessaryConversionTemporary"
246+
<rule name="ExtraUnnecessaryConversionTemporary"
247247
message="Avoid unnecessary temporaries when converting primitives to Strings"
248248
class="net.sourceforge.pmd.lang.java.rule.errorprone.UnnecessaryConversionTemporaryRule">
249249
<description>
@@ -260,7 +260,7 @@ Avoid unnecessary temporaries when converting primitives to Strings
260260
</example>
261261
</rule>
262262

263-
<rule name="OverrideBothEqualsAndHashcode"
263+
<rule name="ExtraOverrideBothEqualsAndHashcode"
264264
language="java"
265265
message="Ensure you override both equals() and hashCode()"
266266
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -316,7 +316,7 @@ not
316316
</example>
317317
</rule>
318318

319-
<rule name="DoubleCheckedLocking"
319+
<rule name="ExtraDoubleCheckedLocking"
320320
message="Double checked locking is not thread safe in Java."
321321
class="net.sourceforge.pmd.lang.java.rule.multithreading.DoubleCheckedLockingRule">
322322
<description>
@@ -342,7 +342,7 @@ For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-doubl
342342
</example>
343343
</rule>
344344

345-
<rule name="ReturnFromFinallyBlock"
345+
<rule name="ExtraReturnFromFinallyBlock"
346346
language="java"
347347
message="Avoid returning from a finally block"
348348
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -375,7 +375,7 @@ For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-doubl
375375
</example>
376376
</rule>
377377

378-
<rule name="EmptySynchronizedBlock"
378+
<rule name="ExtraEmptySynchronizedBlock"
379379
language="java"
380380
message="Avoid empty synchronized blocks"
381381
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -399,7 +399,7 @@ Avoid empty synchronized blocks as they do nothing.
399399
</example>
400400
</rule>
401401

402-
<rule name="UnnecessaryReturn"
402+
<rule name="ExtraUnnecessaryReturn"
403403
language="java"
404404
message="Avoid unnecessary return statements"
405405
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -432,7 +432,7 @@ Avoid unnecessary return statements.
432432
</rule>
433433

434434

435-
<rule name="EmptyStaticInitializer"
435+
<rule name="ExtraEmptyStaticInitializer"
436436
language="java"
437437
message="Empty static initializer was found"
438438
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -455,7 +455,7 @@ Avoid unnecessary return statements.
455455
</example>
456456
</rule>
457457

458-
<rule name="UnconditionalIfStatement"
458+
<rule name="ExtraUnconditionalIfStatement"
459459
language="java"
460460
message="Do not use 'if' statements that are always true or always false"
461461
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -483,7 +483,7 @@ Do not use "if" statements that are always true or always false.
483483
</example>
484484
</rule>
485485

486-
<rule name="EmptyStatementNotInLoop"
486+
<rule name="ExtraEmptyStatementNotInLoop"
487487
language="java"
488488
message="An empty statement (semicolon) not part of a loop"
489489
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -523,7 +523,7 @@ could also be a double semicolon, which is useless and should be removed.
523523
</example>
524524
</rule>
525525

526-
<rule name="BooleanInstantiation"
526+
<rule name="ExtraBooleanInstantiation"
527527
language="java"
528528
message="Avoid instantiating Boolean objects; you can usually invoke Boolean.TRUE instead."
529529
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -558,7 +558,7 @@ public class Foo {
558558
</example>
559559
</rule>
560560

561-
<rule name="UnnecessaryFinalModifier"
561+
<rule name="ExtraUnnecessaryFinalModifier"
562562
language="java"
563563
message="Unnecessary final modifier in final class"
564564
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -591,7 +591,7 @@ public final class Foo {
591591
</example>
592592
</rule>
593593

594-
<rule name="CollapsibleIfStatements"
594+
<rule name="ExtraCollapsibleIfStatements"
595595
language="java"
596596
message="These nested if statements could be combined"
597597
class="net.sourceforge.pmd.lang.rule.XPathRule">

net.sourceforge.pmd.eclipse.plugin.test.fragment/src/main/resources/rulesets/extra2.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
The Braces Ruleset contains a collection of braces rules.
77
</description>
88

9-
<rule name="IfStmtsMustUseBraces"
9+
<rule name="ExtraIfStmtsMustUseBraces"
1010
language="java"
1111
message="Avoid using if statements without curly braces"
1212
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -36,7 +36,7 @@ Avoid using if statements without using curly braces
3636
</example>
3737
</rule>
3838

39-
<rule name="WhileLoopsMustUseBraces"
39+
<rule name="ExtraWhileLoopsMustUseBraces"
4040
language="java"
4141
message="Avoid using 'while' statements without curly braces"
4242
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -64,7 +64,7 @@ Avoid using 'while' statements without using curly braces
6464
</example>
6565
</rule>
6666

67-
<rule name="IfElseStmtsMustUseBraces"
67+
<rule name="ExtraIfElseStmtsMustUseBraces"
6868
language="java"
6969
message="Avoid using 'if...else' statements without curly braces"
7070
class="net.sourceforge.pmd.lang.rule.XPathRule">
@@ -102,7 +102,7 @@ Avoid using if..else statements without using curly braces
102102
</example>
103103
</rule>
104104

105-
<rule name="ForLoopsMustUseBraces"
105+
<rule name="ExtraForLoopsMustUseBraces"
106106
language="java"
107107
message="Avoid using 'for' statements without curly braces"
108108
class="net.sourceforge.pmd.lang.rule.XPathRule">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/BasicPMDTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public void testRunPmdJdk13() {
120120
context.setSourceCodeFilename("foo.java");
121121
context.setReport(new Report());
122122

123-
final RuleSet unnecessaryRuleSet = new RuleSetFactory().createRuleSet("rulesets/java/unnecessary.xml");
124-
RuleSets rSets = new RuleSets(unnecessaryRuleSet);
123+
final RuleSet codeStyleRuleSet = new RuleSetFactory().createRuleSet("category/java/codestyle.xml/UnnecessaryReturn");
124+
RuleSets rSets = new RuleSets(codeStyleRuleSet);
125125
new SourceCodeProcessor(configuration).processSourceCode(new StringDataSource(sourceCode).getInputStream(),
126126
rSets, context);
127127

@@ -158,8 +158,8 @@ public void testRunPmdJdk14() {
158158
context.setSourceCodeFilename("foo.java");
159159
context.setReport(new Report());
160160

161-
final RuleSet unnecessaryRuleSet = new RuleSetFactory().createRuleSet("rulesets/java/unnecessary.xml");
162-
RuleSets rSets = new RuleSets(unnecessaryRuleSet);
161+
final RuleSet codeStyleRuleSet = new RuleSetFactory().createRuleSet("category/java/codestyle.xml/UnnecessaryReturn");
162+
RuleSets rSets = new RuleSets(codeStyleRuleSet);
163163
new SourceCodeProcessor(configuration).processSourceCode(new StringDataSource(sourceCode).getInputStream(),
164164
rSets, context);
165165

@@ -196,8 +196,8 @@ public void testRunPmdJdk15() {
196196
context.setSourceCodeFilename("foo.java");
197197
context.setReport(new Report());
198198

199-
final RuleSet unnecessaryRuleSet = new RuleSetFactory().createRuleSet("rulesets/java/unnecessary.xml");
200-
RuleSets rSets = new RuleSets(unnecessaryRuleSet);
199+
final RuleSet codeStyleRuleSet = new RuleSetFactory().createRuleSet("category/java/codestyle.xml/UnnecessaryReturn");
200+
RuleSets rSets = new RuleSets(codeStyleRuleSet);
201201
new SourceCodeProcessor(configuration).processSourceCode(new StringDataSource(sourceCode).getInputStream(),
202202
rSets, context);
203203

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/ProjectPropertiesModelTest.java

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.junit.After;
4747
import org.junit.Assert;
4848
import org.junit.Before;
49+
import org.junit.Ignore;
4950
import org.junit.Test;
5051

5152
import net.sourceforge.pmd.Rule;
@@ -238,55 +239,58 @@ public void testProjectRuleSet1() throws PropertiesException, RuleSetNotFoundExc
238239

239240
final RuleSetFactory factory = new RuleSetFactory();
240241

241-
// use the basic ruleset because it should be included in the plugin
242-
// ruleset.
243-
final RuleSet basicRuleSet = factory.createRuleSet("rulesets/java/basic.xml");
242+
// use the best practices ruleset because it should be included in the plugin ruleset.
243+
final RuleSet bestPracticesRuleSet = factory.createRuleSet("category/java/bestpractices.xml");
244244

245245
// First set the project ruleset
246-
model.setProjectRuleSet(basicRuleSet);
246+
model.setProjectRuleSet(bestPracticesRuleSet);
247247
model.sync();
248248

249249
// Test the ruleset we set is equal to the ruleset we queried
250250
final RuleSet projectRuleSet = model.getProjectRuleSet();
251251
Assert.assertNotNull("Project ruleset has not been set", projectRuleSet);
252252
Assert.assertTrue("The project ruleset is not the basic ruleset",
253-
EclipseUtils.assertRuleSetEquals(basicRuleSet.getRules(), projectRuleSet.getRules(), System.out));
253+
EclipseUtils.assertRuleSetEquals(bestPracticesRuleSet.getRules(), projectRuleSet.getRules(), System.out));
254254
}
255255

256256
/**
257257
* When rules are removed from the plugin preferences, these rules should also be removed from the project euh...
258258
* ben en fait non. annulé.
259259
*/
260260
@Test
261+
@Ignore("implementation is not finished - maybe the behavior would even be wrong")
261262
public void testProjectRuleSet2() throws PropertiesException, RuleSetNotFoundException, CoreException {
262-
/*
263-
* // First ensure that the plugin initial ruleset is equal to the project // ruleset IProjectPropertiesManager
264-
* mgr = PMDPlugin.getDefault().getPropertiesManager(); IProjectProperties model =
265-
* mgr.loadProjectProperties(this.testProject);
266-
*
267-
* RuleSet projectRuleSet = model.getProjectRuleSet();
268-
* assertEquals("The project ruleset is not equal to the plugin ruleset", this.initialPluginRuleSet.getRules(),
269-
* projectRuleSet .getRules());
270-
*
271-
* // use the basic ruleset and set it at the only plugin ruleset RuleSetFactory factory = new RuleSetFactory();
272-
* RuleSet basicRuleSet = factory.createSingleRuleSet("rulesets/basic.xml");
273-
*
274-
* IPreferencesManager pmgr = PMDPlugin.getDefault().getPreferencesManager(); pmgr.setRuleSet(basicRuleSet);
275-
*
276-
* projectRuleSet = model.getProjectRuleSet();
277-
*
278-
* dumpRuleSet(basicRuleSet); dumpRuleSet(projectRuleSet);
279-
* assertEquals("The project ruleset is not equal to the plugin ruleset", basicRuleSet.getRules(),
280-
* projectRuleSet.getRules());
281-
*/
263+
// First ensure that the plugin initial ruleset is equal to the project
264+
// // ruleset IProjectPropertiesManager
265+
final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
266+
final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
267+
268+
RuleSet projectRuleSet = model.getProjectRuleSet();
269+
Assert.assertEquals("The project ruleset is not equal to the plugin ruleset",
270+
this.initialPluginRuleSet.getRules(), projectRuleSet.getRules());
271+
272+
final RuleSetFactory factory = new RuleSetFactory();
273+
274+
// use the best practices ruleset because it should be included in the
275+
// plugin ruleset.
276+
final RuleSet bestPracticesRuleSet = factory.createRuleSet("category/java/bestpractices.xml");
277+
278+
IPreferencesManager pmgr = PMDPlugin.getDefault().getPreferencesManager();
279+
pmgr.setRuleSet(bestPracticesRuleSet);
280+
281+
projectRuleSet = model.getProjectRuleSet();
282+
283+
dumpRuleSet(bestPracticesRuleSet);
284+
dumpRuleSet(projectRuleSet);
285+
Assert.assertEquals("The project ruleset is not equal to the plugin ruleset", bestPracticesRuleSet.getRules(),
286+
projectRuleSet.getRules());
282287
}
283288

284289
/**
285290
* When rules are added to the plugin preferences, these rules should also be added to the project
286291
*/
287292
@Test
288293
public void testProjectRuleSet3() throws PropertiesException, RuleSetNotFoundException, CoreException {
289-
290294
// First ensure that the plugin initial ruleset is equal to the project
291295
// ruleset
292296
final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
@@ -407,11 +411,11 @@ public void testRuleSetStoredInProjectFALSE() throws PropertiesException, RuleSe
407411
final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
408412

409413
final RuleSetFactory factory = new RuleSetFactory();
410-
final RuleSet basicRuleSet = factory.createRuleSet("rulesets/java/basic.xml");
414+
final RuleSet bestPracticesRuleSet = factory.createRuleSet("category/java/bestpractices.xml");
411415
model.setPmdEnabled(true);
412416
model.setRuleSetStoredInProject(false);
413417
model.setProjectWorkingSet(null);
414-
model.setProjectRuleSet(basicRuleSet);
418+
model.setProjectRuleSet(bestPracticesRuleSet);
415419
model.sync();
416420

417421
model.createDefaultRuleSetFile();
@@ -433,7 +437,7 @@ public void testRuleSetStoredInProjectTRUE() throws PropertiesException, RuleSet
433437
final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
434438

435439
final RuleSetFactory factory = new RuleSetFactory();
436-
final RuleSet basicRuleSet = factory.createRuleSet("rulesets/java/basic.xml");
440+
final RuleSet basicRuleSet = factory.createRuleSet("category/java/bestpractices.xml");
437441
model.setPmdEnabled(true);
438442
model.setRuleSetStoredInProject(false);
439443
model.setProjectWorkingSet(null);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

0 commit comments

Comments
 (0)