1 package test.net.sourceforge.pmd.rules;
2
3 import net.sourceforge.pmd.rules.XPathRule;
4 import test.net.sourceforge.pmd.testframework.RuleTst;
5
6 /***
7 * @author daniels
8 *
9 * Cannot Implement:
10 * <LI> Cyclomatic Complexity Rule - don't understand it
11 * <LI> Import From Same Package Rule - cannot check for sub packages
12 * <LI> StringToString - may be possible, but a better grammar would help.
13 * <LI> UnnecessaryConversionTemporaryRule - don't understand it
14 * <LI> UnusedFormalParameter - may be possible, but a better grammar would help.
15 * <LI> UnusedImportsRule - may be possible, but a better grammar would help.
16 * <LI> UnusedLocalVariableFieldRule - may be possible, but a better grammar would help.
17 * <LI> UnusedPrivateFieldRule - may be possible, but a better grammar would help.
18 * <LI> UnusedPrivateMethodRule - may be possible, but a better grammar would help.
19 * <HR>
20 *
21 * Partial Implementation
22 * <LI> DuplicateImportsRuleTest - cannot detect specific vs. general imports
23 *
24 * <HR>
25 *
26 * Differing Implementation
27 * <LI> AvoidDuplicateLiteralsRule - marks all duplicate nodes
28 *
29 */
30 public class XPathRuleTest extends RuleTst {
31
32 XPathRule rule;
33
34 public void setUp() {
35 rule = new XPathRule();
36 rule.setMessage("XPath Rule Failed");
37 }
38
39 // public void testUnusedFormalParameterRule() throws Throwable {
40 // rule.addProperty("xpath", "//MethodDeclaration[@Private='true'][@Native='false']//FormalParameters//VariableDeclaratorId");
41 // runTestFromFile("UnusedFormalParam1.java", 1, rule);
42 // runTestFromFile("UnusedFormalParam2.java", 0, rule);
43 // runTestFromFile("UnusedFormalParam3.java", 0, rule);
44 // runTestFromFile("UnusedFormalParam4.java", 0, rule);
45 // }
46
47 // public void testUnnecessaryConversionTemporaryRule() throws Throwable{
48 // runTestFromFile("UnnecessaryTemporary.java", 6, rule);
49 // }
50
51 // public void testStringToString() throws Throwable {
52 // runTestFromFile("StringToString1.java", 1, rule);
53 // runTestFromFile("StringToString2.java", 1, rule);
54 // runTestFromFile("StringToString3.java", 1, rule);
55 // runTestFromFile("StringToString4.java", 0, rule);
56 // runTestFromFile("StringToString5.java", 0, rule);
57 // runTestFromFile("StringToString6.java", 1, rule);
58 //
59 // }
60
61 public void testDeeplyNestedIfStmtsRule() throws Throwable {
62 rule.addProperty(
63 "xpath",
64 "//IfStatement[count(ancestor::IfStatement[not(Statement[2])]) > {0}]");
65 rule.addProperty("subst", "1");
66 runTestFromString(AvoidDeeplyNestedIfStmtsRuleTest.TEST1, 1, rule);
67 runTestFromString(AvoidDeeplyNestedIfStmtsRuleTest.TEST2, 0, rule);
68 }
69
70 /***
71 * @todo Figure it out.
72 */
73 public void testAvoidReassigningParameters() throws Throwable {
74 // fail("I wouldn't even know where to begin");
75 rule.addProperty(
76 "xpath",
77 "//PrimaryExpression[following-sibling::AssignmentOperator][PrimaryPrefix/Name/@Image = ancestor::MethodDeclaration/MethodDeclarator/FormalParameters/FormalParameter/VariableDeclaratorId/@Image]");
78 runTestFromString(AvoidReassigningParametersRuleTest.TEST1, 1, rule);
79 runTestFromString(AvoidReassigningParametersRuleTest.TEST2, 0, rule);
80 runTestFromString(AvoidReassigningParametersRuleTest.TEST3, 1, rule);
81 runTestFromString(AvoidReassigningParametersRuleTest.TEST4, 0, rule);
82 runTestFromString(AvoidReassigningParametersRuleTest.TEST5, 0, rule);
83 runTestFromString(AvoidReassigningParametersRuleTest.TEST6, 0, rule);
84 }
85 }
This page was automatically generated by Maven