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

This page was automatically generated by Maven